第二周项目2-有序的结构体数组
来源:互联网 发布:h5小游戏源码免费下载 编辑:程序博客网 时间:2024/04/29 20:13
/**程序的版权和版本声明部分:*Copyright(c)2014,烟台大学计算机学院学生*All rights reserved.*文件名称:*作者:田成琳*完成日期:2014 年 3月 3 日*版本号:v1.0*对任务及求解方法的描述部分:*输入描述: 无*问题描述:对学生数据进行运算*程序输出:学生成绩*问题分析:*算法设计:*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct Student{ char num[13]; char name[10]; int cpp; int math; int english; int grade; double average;};void calculate(Student s[],int n); //计算总分和均分,数据在s数组中,共有n个元素void sort1(Student [],int); //按总分降序排序void sort2(Student [],int); //按学号升序排序void output(Student [],int); //输出成绩单void outputExcellent(Student [],int); //输出优秀者:总分超285,单科不低于90int 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){ int i; for(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){ int i,j; Student t; for(i=0; i<n-1; i++) { for(j=0; j<n-1-i; j++) { if(s[j].grade<s[j+1].grade) { t=s[j]; s[j]=s[j+1]; s[j+1]=t; } } }}void sort2(Student s[],int n){ int i,j; Student t; for(i=0; i<n-1; i++) { for(j=i+1; j<n; j++) { if(strcmp(s[i].num,s[j].num)>0) { t=s[i]; s[i]=s[j]; s[j]=t; } } }}void output(Student s[],int n){ int i; cout<<"学号 姓名 C++ 高数 英语 总分 平均分"<<endl; for(i=0; i<n; i++) { cout<<s[i].num<<" "<<s[i].name<<" "<<s[i].cpp<<" "<<s[i].math; cout<<" "<<s[i].english<<" "<<s[i].grade<<" "<<s[i].average<<endl; }}void outputExcellent(Student s[],int n){ int i; for(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].name<<" "; } } cout<<endl;}
运行结果:
心得体会:折腾吧~
0 0
- 第二周项目2-有序的结构体数组
- 第二周 项目2 有序的结构体数组
- 第二周项目2-有序的结构体数组
- 第二周项目2-有序的结构体数组
- 第二周项目2-有序的结构体数组
- 补 第二周 项目2- 有序的结构体数组.
- 第二周项目一:有序的结构体数组
- 第二周 项目一:有序的结构体数组
- 第二周项目1 有序的结构体数组
- 第二周项目二-有序的结构体数组
- 第二周 项目二 有序的结构体数组
- 第二学期第二周项目2--有序的结构体数组
- 第二周 项目二 有序的结构数组
- 第二周 项目一 有序结构体数组
- 项目2-有序的结构体数组
- 2013第二周上机任务项目一(有序的结构体数组)
- 第二周上机任务项目1--有序的结构体数组
- 第二周上机任务项目1-有序的结构体数组
- 由12306.cn谈谈网站性能技术
- 性能调优攻略
- 内部排序:冒泡排序算法
- 浅谈Android应用性能之启动时间
- cocos2d-x 2.2 android环境搭建
- 第二周项目2-有序的结构体数组
- NYOJ 298 点的变换
- 设置recv的超时
- CheckBox ExpandableListView
- 立体匹配十大概念综述
- android线程
- PAgP Silent/Non-silent Mode
- 由12306.cn谈谈网站性能技术
- 声音对象