中国铁道建设出版
# include <iostream.h>
# include <iomanip.h>
struct score
{
char name[8] ;
int no ;
float c, english, maths, average ;
} ;
score input(score st) ;
float average( float a, float b, float c ) ;
void sort(score st[], int n) ;
void print (score st[], int n) ;
void main()
{
score student[30] ;
for (int i=0 ; i<5 ; i++)
student[i]=input(student[i]) ;
sort(student, 5) ;
print(student, 5) ;
}
score input(score st)
{
cout<<"请输入学生姓名:" ; cin>>http://www.77cn.com.cn ;
cout<<"请输入学生学号:" ; cin>>st.no ;
cout<<"请输入C++成绩:" ; cin>>st.c ;
cout<<"请输入英语成绩:" ; cin>>st.english ;
cout<<"请输入数学成绩:" ; cin>>st.maths ;
cout<<endl ;
st.average=average(st.c, st.english, st.maths) ;
return st ;
}
float average( float a, float b, float c )
{ return (a+b+c)/3 ; }
void sort(score st[], int n)
{ score temp ;
for ( int i=0 ; i<n-1 ; i++)
for ( int j=i ; j<n ; j++ )
if (st[i].average < st[j].average )
{ temp=st[i] ; st[i]=st[j] ; st[j]=temp ; }
}