#include<iostream>
using namespace std;
//建立对象数组,内放5个学生数据
class Student
{
public:
Student(int n,double s):num(n),score(s){}
void display();
private:
int num;
double score;
};
void Student::display()
{
cout << "学号:" << num << endl;
cout << "成绩:" << score << endl;
cout << endl;
}
int main()
{
int i=0;
Student stud[5] = {
Student(101,89),
Student(102,87.5),
Student(103,99),
Student(104,97.5),
Student(105,86)
};
for (Student* pt = stud;i<5;i+=2, pt += 2)
pt->display();
return 0;
}
谭浩强c++第三版9-4
最新推荐文章于 2021-09-04 16:52:31 发布