//参考程序:
#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< } }; void sort(Student stus[], int len) { int i, j, k; Student temp; for(i=0; i { k = i; for(j=i+1; 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个学生的信息(学号、姓名、成绩) : "< for(i=0; i { cout<<"No. "<
cin>>no>>name>>score; stus[i] = Student(no, name, score); } sort(stus, len); cout<<"学生信息一览(按成绩降序) : "< for(i=0; i { stus[i].display(); } } 运行结果: