class student
{
int eng,com,total;
public:
void getxcore();//获取一个学生成绩
void display();//显示一个学生成绩
};
void sort(student*);//将若干个学生按总分从高到低排序.
只在我的程序的基础上修改就成.
#include <iostream.h>
class student
{
int n,eng,com,total;
public:
void getscore();
void display();
int retotal() { return total;}
};
void student :: getscore()
{
static int num=0;
num=num+1;
n=num;
cout << " 输入英语成绩:";
cin >> eng;
cout << " 输入计算机成绩:";
cin >> com;
total=eng+com;
}
void student :: display()
{
cout << "学号:" << n << "英语=" << eng << "计算机=" << com << "总分=" << total << endl;
}
int main(void)
{
void sort(student* *,student* *);
student*a[4];
for(int j=0;j<4;j++)
{
a[j]=new student;
cout << "学生" << j+1 << endl;
a[j]->getscore();
}
int i;
for(j=0;j<3;j++)
for(i=0;i<3;i++)
{
sort(a+j,a+j+1);
}
cout << endl << "排序结果如下:"<< endl;
for(i=0;i<4;i++)
{
a[i]->display();
}
void sort(student* *p1,student* *p2)//此行提示有错误
{
if((*p1)->retotal()<(*p2)->retotal())
{
student* temp=*p1;
*p1=*p2;
*p2=temp;
}
}
return 0;
}
[此贴子已经被作者于2006-1-8 11:52:39编辑过]