如何实现排序后输出
#include<iostream>#include<string>
# define n 5
using namespace std;
struct student
{
int num;
string name;
int score[3];
};
struct classes
{
student info;
float average;
};
void main()
{
void input(classes s[]);
void paixu(classes s[]);
void output(classes s[]);
classes s[n];
input(s);
paixu(s);
output(s);
}
void input(classes s[])
{
int i,j;
cout<<"please input:"<<endl;
for(i=0;i<n;i++)
{
cin>>s[i].info.num>>s[i].info.name;
for(j=0;j<3;j++)
cin>>s[i].info.score[j];
}
}
void paixu(classes s[])
{
int i,j;
float t;
for(i=0;i<n;i++)
{
for(s[i].average=0,j=0;j<3;j++)
{
s[i].average+=s[i].info.score[j];
}
s[i].average=s[i].average/3;
}
for(j=0;j<n;j++)
for(i=0;i<n-j;i++)
if(s[i].average<s[i+1].average)
{
t=s[i].average;
s[i].average=s[i+1].average;
s[i+1].average=t;
}
}
void output(classes s[])
{
int i;
for(i=0;i<n;i++)
cout<<s[i].info.num<<" "<<s[i].info.name<<" "<<s[i].info.score[0]<<" "<<s[i].info.score[1]<<" "<<
s[i].info.score[2]<<" "<<s[i].average<<" "<<endl;
}