/*Univercity:烟台大学 *@Class</A>计134~4 *@Author:薛富磊 *@Time:2013-12-11 *@Function:结构体成绩学号大编排 *@Args: *@Return: */ #include <iostream> using namespace std; struct Student { char num[13]; char name[10]; int cpp; int math; int english; int grade; double average; }; //计算总分和均分,数据在s数组中,共有n个元素 void calculate(Student s[],int n); //按总分降序排序 void sort1(Student [],int); //按学号升序排序 void sort2(Student [],int); //输出成绩单 void output(Student [],int); //输出优秀者:总分超285,单科不低于90 void outputExcellent(Student [],int); int main() { Student stu[]= {{"201152501104","Tom",65,69 ,68 }, {"201152501114","Jeery",94 ,89 ,63 }, {"201152501138","Speike",67 ,62 ,84 }, {"201152501204","Tyke",100 ,95 ,91 }, {"201152501202","Tuffy",59 ,80 ,55 }, {"201152501115","Butch",100 ,99 ,89 }, {"201152501201","Lightning",95 ,92 ,99 }, {"201152501145","Topsy",88 ,56 ,67 }, {"201152501203","Droopy",62 ,62 ,95 }, {"201152501140","Drupa",80 ,60 ,86 }, {"201152501205","Buzz",73 ,90 ,94} }; int stuNum=sizeof(stu)/sizeof(stu[0]); //用sizeof运算确定数组中元素个数 //计算总分和均分后输出 calculate(stu,stuNum); cout<<"下面是成绩单:"<<endl; output(stu,stuNum); cout<<"优秀者名单:"<<endl; outputExcellent(stu,stuNum); //按总分降序排序后输出 sort1(stu,stuNum); cout<<"按总分降序排序后:"<<endl; output(stu,stuNum); //按学号升序排序后输出 sort2(stu,stuNum); cout<<"按学号升序排序后:"<<endl; output(stu,stuNum); return 0; } void calculate(Student s[],int n) { for(int i=0;i<n;i++) { s[i].grade=s[i].cpp+s[i].math+s[i].english; s[i].average=s[i].grade/3; } } void sort1(Student s[],int n) { Student m; for(int i=0;i<n-2;i++) { for(int j=0;j<n-i-1;j++) if(s[j].grade<s[j+1].grade) { m=s[j]; s[j]=s[j+1]; s[j+1]=m; } } } void sort2(Student s[],int n) { Student m; for(int i=0;i<n-2;i++) { for(int j=0;j<n-i-1;j++) if(s[j].num>s[j+1].num) { m=s[j]; s[j]=s[j+1]; s[j+1]=m; } } } void output(Student s[],int n) { cout<<"----------------------------------------------------------\n"; cout<<"|学号 |姓名 | cpp| math| english|总分 |均分 |\n"; for(int i=0;i<n;i++) { cout<<s[i].num<<"|\t"<<s[i].name<<"|\t"<<s[i].cpp; cout<<"|\t"<<s[i].math<<"|\t"<<s[i].english<<endl; } } void outputExcellent(Student s[],int n) { for(int i=0;i<n;i++) if(s[i].grade>=285&&s[i].cpp>=90&&s[i].math>=90&&s[i].english>=90) { cout<<s[i].num<<"|\t"<<s[i].name<<"|\t"<<s[i].cpp; cout<<"|\t"<<s[i].math<<"|\t"<<s[i].english<<endl; } }
心得体会:
笔记本没下画图
上次下了没安装上
气煞我也
最后用了QQ截图
小样难不倒爷!!!