#include<iostream>
#define COUNT 5
using namespace std;
class Student{
public:
Student(int n,float s):num(n),score(s){};
void output();
public:
int num;
float score;
};
void Student::output()
{
cout<<"num: "<<num<<endl;
cout<<"score: "<<score<<endl;
}
int max(Student *arr)
{
float max=arr->score;
int outnum=arr->num;
for(int i=0;i<COUNT;i++)
{
arr++;
if(max<arr->score)
outnum=arr->num;
}
return outnum;
};
void main()
{
Student *p,stu[COUNT]={Student(01,88),Student(02,78),Student(03,66),Student(04,98),Student(05,77)};
int n,max(Student *arr);
for(int i=0;i<COUNT;i=i+2)
{
p=&stu[i];
p->output();
}
p=&stu[0];
cout<<"the num of best score is :"<<max(p)<<endl;
}
注:程序缺点是没有体现封装性的特点
C++项目 指向学生类的指针
最新推荐文章于 2019-04-21 20:46:35 发布