C程序设计:
最后的学生数据要求为学号、姓名、性别、年龄、语数外三门各科成绩,最后加一个按照从高到低输出学生三门各科成绩、总成绩列表的功能
#include<bits/stdc++.h>
using namespace std;
struct students{
string id;
string name;
bool sex;
int age;
double Chinese,Math,English;
double AllScore;
}stu[1000];
bool cmp1(students a,students b){return a.Chinese>b.Chinese;}
bool cmp2(students a,students b){return a.Math>b.Math;}
bool cmp3(students a,students b){return a.English>b.English;}
bool cmp4(students a,students b){return a.AllScore>b.AllScore;}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>stu[i].id>>stu[i].name>>stu[i].sex>>stu[i].age>>stu[i].Chinese>>stu[i].Math>>stu[i].English,
stu[i].AllScore=stu[i].Chinese+stu[i].Math+stu[i].English;
cout<<"按语文成绩排序:"<<endl;
sort(stu,stu+n,cmp1);
for(int i=0;i<n;i++)
cout<<stu[i].id<<" "<<stu[i].name<<" "<<stu[i].sex<<" "<<stu[i].age<<" "<<stu[i].Chinese<<" "<<stu[i].Math<<" "<<stu[i].English<<endl;
cout<<endl;
cout<<"按数学成绩排序:"<<endl;
sort(stu,stu+n,cmp2);
for(int i=0;i<n;i++)
cout<<stu[i].id<<" "<<stu[i].name<<" "<<stu[i].sex<<" "<<stu[i].age<<" "<<stu[i].Chinese<<" "<<stu[i].Math<<" "<<stu[i].English<<endl;
cout<<endl;
cout<<"按英语成绩排序:"<<endl;
sort(stu,stu+n,cmp3);
for(int i=0;i<n;i++)
cout<<stu[i].id<<" "<<stu[i].name<<" "<<stu[i].sex<<" "<<stu[i].age<<" "<<stu[i].Chinese<<" "<<stu[i].Math<<" "<<stu[i].English<<endl;
cout<<endl;
cout<<"按总成绩排序:"<<endl;
sort(stu,stu+n,cmp4);
for(int i=0;i<n;i++)
cout<<stu[i].id<<" "<<stu[i].name<<" "<<stu[i].sex<<" "<<stu[i].age<<" "<<stu[i].Chinese<<" "<<stu[i].Math<<" "<<stu[i].English<<endl;
return 0;
}