第二周项目三-文件+结构体实用系统
来源:互联网 发布:linux的chown命令 编辑:程序博客网 时间:2024/05/29 15:52
#include <iostream>#include <fstream>#include <cstdlib>using namespace std;struct Student{ char num[13];//注意后面char类型的学号比较 char name[10]; int cpp; int math; int english; int grade; double average;};void sort1(Student [],int); //按总分降序排序void output(Student [],int); //输出成绩单void award(Student [],int); //输出获得奖学金者int main(){ Student stu[400]; int i=0,stuNum=0; ifstream infile("score.txt",ios::in); //以输入的方式打开文件 if(!infile) //测试是否成功打开 { cerr<<"open error!"<<endl; exit(1); } while(infile>>stu[i].num>>stu[i].name>>stu[i].cpp>>stu[i].math>>stu[i].english) { stu[i].grade=stu[i].cpp+stu[i].math+stu[i].english;//计算总分 ++stuNum;//计算出有多少学生 ++i; } infile.close(); //计算总分和均分后输出 cout<<"下面是成绩单:"<<endl; output(stu,stuNum); //按总分降序排序后输出 sort1(stu,stuNum); cout<<"按总分降序排序后:"<<endl; output(stu,stuNum); //按学号升序排序后输出 cout<<"获得奖学金者名单:"<<endl; award(stu,stuNum); return 0;}void output(Student s[],int n) //输出成绩单{ cout<<'\t'<<"学号"<<'\t'<<"姓名"<<'\t'<<"C++"<<'\t'<<"高数"<<'\t'<<"英语"<<'\t'<<"总分"<<endl; for(int i=0; i<n; i++) { cout<<s[i].num<<'\t'<<s[i].name<<'\t'<<s[i].cpp<<'\t'<<s[i].math<<'\t'<<s[i].english<<'\t'<<s[i].grade<<endl; }}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 award(Student s[],int n){ for(int i=0; i<30; i++) { if(s[i].math>=60&&s[i].cpp>=60&&s[i].english>=60) cout<<s[i].name<<'\t'; if(i%5==0) { cout<<endl;//5个一组输出 } }}
运行结果:
0 0
- 第二周项目三-文件+结构体实用系统
- 第二周(项目三)——文件+结构体实现实用系统。<总是不对,求大神指点迷津!!>
- 【结构体】项目三。文件+结构体实现实用系统
- 第二周上机实践项目——文件+结构体实现实用系统
- 第二周项目3-文件+结构体实现实用函数
- 第三周项目3-文件+结构体实现实用系统
- 第二学期第二周项目3--文件+结构体实用实现
- C++ 项目3 文件加结构体实现实用系统
- 02周:项目三:文件加结构体实现系统
- C++第2周(春)项目3 文件+结构体实现实用系统
- 第二周 项目三:用结构体数组作计算
- 第二周 项目三 用结构体数据做运算
- 文件+结构体实现实用系统+拓展()
- 第二周——文件+结构体实现使用系统
- 第二周项目三多文件程序
- 2-3文件+结构体实现实用系统
- 2-文件+结构体实现实用系统(拓展)
- 2013第二周上机任务项目三(用结构体数组做计算)
- Eclipse 3.2 + MyEclipse 5.0GA + WebLogic 9.2
- linux入门
- LeetCode Reverse Words in a String Total
- shell中的more命令
- 借用“青春赋”来表达我想说的
- 第二周项目三-文件+结构体实用系统
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- 嵌入式开发工程师面试题 – C语言部分
- 买不到的数目
- spring在javaWeb环境中加载 bean 配置文件方式的选择
- Android - Android应用程序(Application)的主要组件
- poj1195之二维树状数组
- 《Head First 设计模式》 总结
- 用堆实现的优先队列