这是一个把学生按总分成绩排序的程序,但他vs2012这里说rank不明确是什么意思
#include<iostream>#include<string>
using namespace std;
template<class T>
void rank(T *a)
{
T temp;
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<(6-i-1);j++)
{
if((a+j)->sum>(a+j+1)->sum)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
};
class student
{
public:
char name[20];
long int ID;
int mathscore;
int chinesescore;
int englishscore;
int sum;
public:
student(char *n=0,long int id=0,int ms=0,int cs=0,int es=0)
{
*name=*n;
ID=id;
mathscore=ms;
chinesescore=cs;
englishscore=es;
}
void add()
{
sum=mathscore+chinesescore+englishscore;
}
};
void main()
{
int i,a[6];
student stu[6]={student("zhang",001,80,86,90),student("han",002,98,85,85),student("he",003,86,94,82),
student("liu",004,98,95,96),student("fang",005,98,78,86),student("gao",006,95,85,74)};
for(i=0;i<6;i++)
{
stu[i].add();
cout<<stu[i].name<<"\t"<<stu[i].ID<<"\t"<<stu[i].mathscore<<"\t"<<
stu[i].chinesescore<<"\t"<<stu[i].englishscore<<"\t"<<endl;
}
for(i=0;i<6;i++)
{
a[i]=stu[i].sum;
}
rank(stu);
for(i=0;i<6;i++)
{
cout<<stu[i].name<<"\t"<<stu[i].ID<<"\t"<<stu[i].mathscore<<"\t"<<
stu[i].chinesescore<<"\t"<<stu[i].englishscore<<"\t"<<endl;
}
}