【4.17】建立一个对象数组,内放六个学生的数据(学号、成绩),用指针指向数组首元素,输出低2、4、6各学生的数据。
学生类class student | private | string name |
int number | ||
int score | ||
public | student(string name1,int b,int c) | |
student() | ||
void show() |
#include <iostream>
#include<string>
using namespace std;
class student{
public:
student(string name1,int b,int c)
{
name=name1;
number=b;
score=c;
}
student()
{}
void show()
{
cout<<"学生姓名"<<name<<"学号"<<number<<"C++成绩"<<score<<endl;
}
private:
string name;
int number;
int score;
};
int main()
{
student A[6]={
student(),
student("lin",10,90),
student(),
student("chen",15,91),
student(),
student("wu",20,95)};
for(int i=1;i<6;i=i+2)
A[i].show();
system("pause");
return 0;
}