#include <iostream>
using namespace std;
class Student
{
public:
Student(int = 0,int = 0);
void display();
private:
int no;
int score;
};
Student::Student(int no,int score):no(no),score(score){}
void Student::display()
{
cout << no << ":" << score << endl;
}
int main()
{
//定义对象数组
Student stu[5] =
{
Student(100,100),
Student(200,200),
Student(300,300),
Student(400,400),
Student(500,500)
};
Student *p;//指定对象指针
p = stu; //将对象数组的首地址赋值给指针对象
for(int i = 0 ; i < 5; i++)
{
switch(i + 1)
{
case 1:
case 3:
case 5:
(*p).display();
break;
default:
break;
}
p++;
}
system("pause");
return 0;
}
|