定义student类,数据成员包括姓名name和成绩score,成员函数包括构造函数,拷贝构造函数和析构函数。

定义student类,数据成员包括姓名name和成绩score,成员函数包括构造函数,拷贝构造函数和析构函数。
定义函数void highestscore(student s[]),输出分数最高的学生姓名和分数。
在main函数中定义student s[N],调用highestscore函数,输出分数最高的学生姓名和分数

/参考程序:
#include "iostream"
#include "string"
using namespace std;
class Student
{
private:
int no; //学号
string name; //姓名
int score; //成绩
public:
Student()
{ }
Student(int no, string name, int score)
{
this->no = no;
this->name = name;
this->score = score;
}
string getName()
{
return name;
}
int getNo()
{
return no;
}
int getScore()
{
return score;
}
void display()
{
cout<<no<<"\t"<<name<<"\t"<<score<<endl;
}
};
void sort(Student stus[], int len)
{
int i, j, k;
Student temp;
for(i=0; i<len-1; i++)
{
k = i;
for(j=i+1; j<len; j++)
if(stus[j].getScore() > stus[k].getScore())
k = j;
if(k != i)
{
temp = stus[k];
stus[k] = stus[i];
stus[i] = temp;
}
}
}
void main()
{
int i;
int len = 5;
Student stus[20];
int no;
string name;
int score;
cout<<"请输入20个学生的信息(学号、姓名、成绩) : "<<endl;
for(i=0; i<len; i++)
{
cout<<"No. "<<i+1<<" : ";
cin>>no>>name>>score;
stus[i] = Student(no, name, score);
}
sort(stus, len);
cout<<"学生信息一览(按成绩降序) : "<<endl;
for(i=0; i<len; i++)
{
stus[i].display();
}
}追问

你没有看清楚题目额

温馨提示:答案为网友推荐,仅供参考
相似回答