class mStudents{
double score1;
double score2;
double score3;
public:
int num;
double total;
double avgscore;
mStudents(int stunum,double s1, double s2, double s3) :num(stunum),score1(s1), score2(s2), score3(s3)
{
total = s1 + s2 + s3;
avgscore = total / 3;
}
void Display()
{
cout << "stuNum :" << num << " ";
cout << "score1 :" << score1 << " ";
cout << "score2 :" << score2 << " ";
cout << "score3 :" << score3 << endl;
}
};
void OrderByScore(int const count,mStudents*stuarr[])
{
mStudents* tmp ;
for (int i = 0; i < count;i++)
{
for (int j = i; j < count; j++)
{
if (stuarr[i]->total < stuarr[j]->total)
{
tmp = stuarr[j];
stuarr[j] = stuarr[i];
stuarr[i] = tmp;
}
}
}
}
void main()
{
int num;
double score1, score2, score3;
mStudents* stuarr[100];
int count = 0;
while (1)
{
cout << "请依次输入学号,第一科目,第二科目,第三科目成绩,以-1结尾"<
if (-1 == num)
{
break;
}
cin >> score1 >> score2 >> score3;
stuarr[count++] = new mStudents( num,score1,score2,score3);
}
for (int i = 0; i < count; i++)
{
stuarr[i]->Display();
}
OrderByScore(count,stuarr);//sort
cout<<"first:";
stuarr[0]->Display();//first
cout << "last:";
stuarr[count-1]->Display();//last
for (int i = 0; i < count;i++)
{
stuarr[i]->Display();
delete stuarr[i];
}
}