C++编程问题!!(关于一个学生类,及一个学生类的友元类--学生线性表类)

2025-01-07 20:26:46
推荐回答(1个)
回答1:

我刚好做完这个作业
#include
#include
using namespace std;
class student
{
public:
int score;
string name;
int no;
};

student *max(student *p,int num)
{
int a=0;
int max=p[a].score;
for(int i=0;i if(p[i].score>max){
max=p[i].score;
a=i;
}
}
return p+a;
}

student *min(student *p,int num)
{
int b=0;
int min=p[b].score;
for(int i=0;i if(p[i].score min=p[i].score;
b=i;
}
}
return p+b;
}
void main()
{ int num;
cout<<"输入人数"<cin>>num;
student *p=new student[num];
for(int i=0;i {cout< cin>>p[i].name>>p[i].no>>p[i].score;
}

cout<<"最高成绩人姓名"<<(max(p,num))->name<<"学号:"<<(max(p,num))->no<<"成绩"<<(max(p,num))->score< cout<<"最低成绩人姓名"<<(min(p,num))->name<<"学号:"<<(min(p,num))->no<<"成绩"<<(min(p,num))->score< delete []p;
}