第二周 项目三 用结构体数据做运算
来源:互联网 发布:嵌入式软件开发实例 编辑:程序博客网 时间:2024/05/18 03:56
上机目的:数据结构体
上机内容:获得奖学金的人以及排名
/* .* 程序的版权和版本声明部分 .* Copyright (c)2013, 烟台大学计算机学院学生 .* All rightsreserved. .* 文件名称:text.cpp .* 作者:刘玉金 .* 完成日期: 2013年3月18日 .* 版本号: v1.0 .* 输入描述:从文件中获得学生名单.* 问题描述: 求学生的排名以及获得奖学金的人.* 输出: 学生的排名以及获得奖学金的的人 */ #include <iostream> #include <iostream> #include <fstream> #include <cstdlib> using namespace std; struct Student { char num[13]; char name[10]; int cpp; int math; int english; int grade; }; const int N=200; int main( ) { int i, j, k, stuNum=0; Student stu[N], t_stu; ifstream infile("score.txt",ios::in); if(!infile) { cerr<<"open error!"<<endl; exit(1); } i=0; while(!infile.eof()) { 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(); for(i=0; i<stuNum-1; i++) { k=i; for(j=i+1; j<stuNum; j++) if(stu[j].grade>stu[k].grade) k=j; t_stu=stu[k]; stu[k]=stu[i]; stu[i]=t_stu; } for(i=0; i<stuNum; ++i) { cout<<stu[i].num<<"\t"<<stu[i].name<<"\t"<<stu[i].cpp<<"\t"<<stu[i].math<<"\t"<<stu[i].english<<"\t"<<stu[i].grade<<endl; } cout<<"恭喜以下同学获得奖学金"<<endl; i=0,j=1; while (j<=30) { if (stu[i].cpp>=60&&stu[i].math>=60&&stu[i].english>=60) { cout<<j<<'\t'<<stu[i].name<<'\t'<<stu[i].grade<<endl; j++; } i++; } return 0; }
运行结果:
心得体会:这个根据项目一与项目二的结合,进行运算的。
- 第二周 项目三 用结构体数据做运算
- 2013第二周上机任务项目三(用结构体数组做计算)
- 第二周项目三—用结构体数组做计算
- 第二周 项目三:用结构体数组作计算
- 第二周上机任务项目3-用结构体数组做计算
- 第二周项目三-文件+结构体实用系统
- 第二周项目二:读取数据到结构体数组
- 第二周 项目二:读取数据到结构体数组
- 第二周项目2 读取数据到结构体数组
- 第二周项目二 读取数据到结构体数组
- 第2周项目三-用结构体数组做计算
- 第二周项目五--数组做数据成员
- 第二周项目五--数组做数据成员2
- 第二周项目三————结构体数组计算
- 第二周:项目一结构体
- 第二周项目三
- 第二周项目三
- 第二周项目三
- R语言中的attach()和detach()函数
- 2013第三周上机任务【项目三 长方体类】
- nGrinder-世界上最简单但潜力无限的压力工具
- List<Map<String,Object>几种遍历的方法
- JS最佳实践
- 第二周 项目三 用结构体数据做运算
- LinkedHashMap和HashMap的比较使用 由于现在项目中用到了LinkedHashMap,并不是太熟悉就到网上搜了一下。 ? import java.util.HashMap; impo
- TD SCDMA里的CELL_FACH、CELL_DCH、CELL_PCH
- hdu 1080 Human Gene Functions( 带权值的最长公共子序列)
- CString之GetBuffer()
- HelloWorldScene解析
- Visual C++ 6.0的常用快捷键(来自EmanLee, Eman Lee's Space )
- I-P-B frame简介http://www.eefocus.com/czzheng/blog/07-11/75757_e4cdb.html
- Oracle的dual