综合应用实例

上传人:cn****1 文档编号:508591207 上传时间:2024-03-03 格式:DOC 页数:7 大小:50KB
返回 下载 相关 举报
综合应用实例_第1页
第1页 / 共7页
综合应用实例_第2页
第2页 / 共7页
综合应用实例_第3页
第3页 / 共7页
综合应用实例_第4页
第4页 / 共7页
综合应用实例_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《综合应用实例》由会员分享,可在线阅读,更多相关《综合应用实例(7页珍藏版)》请在金锄头文库上搜索。

1、综合应用实例实现一个简单的学生成绩录入和查询系统。具体要求如下:(1)能够输入学生的学号、姓名和各科成绩。(2)根据输入的学号,查询并计算出该生的各科成绩及平均分。(3)根据输入的课程代号,查询并计算出该课程中每个学生的成绩及课程平均分。(4)查询所有课程中成绩不及格的学生名单及相应成绩。程序分析:学生成绩用文本文件来存储,能够从文本文件里读出学生的信息,也能够向文本文件中写入学生的信息。程序中对插入和提取运算符进行了重载。程序依次有5项功能:学生信息的添加;输入学号,输出该生各科成绩及平均分;输入课程代号,输出该课程每位学生成绩及课程平均分;输入学生姓名,输出成绩;设计功能选择菜单及利用sw

2、itch case语句实现以上功能。程序如下: #include#include#include#include#includeint count; /学生人数class Student /学生类定义private:char Name20; /姓名char Number20; /学号double Chinese,Math,English,Computer; /语文,数学,英语,计算机成绩public:Student()char *getname()return Name;double getscore(char n)double score;switch(n)case c: score=Chi

3、nese; break;case m: score=Math; break;case e: score=English; break;case p: score=Computer; break;return score;char *getNumber()return Number;friend ofstream& operator (ofstream &dist,Student &st); /重载插入运算符friend ostream &operator (istream &sour,Student &st); /重载提取运算符friend ifstream &operator (ifstre

4、am&sour,Student &st);ofstream &operator (ofstream&dist,Student &st) /重载插入运算符 distst.Nametst.Numbertst.Chinesetst.Mathtst.Englishtst.Computerendl;return dist;ostream &operator (ostream&dist,Student &st) /重载插入运算符 dist姓名:st.Namet学号:st.Numbert语文:st.Chineset数学:st.Matht英语:st.Englisht计算机:st.Computert (istr

5、eam&sour,Student &st) /重载提取运算符coutst.Name;coutst.Number;coutst.Chinese;coutst.Math;coutst.English;coutst.Computer;return sour;ifstream &operator (ifstream&sour,Student &st) /重载提取运算符sourst.Name;sourst.Number;sourst.Chinese;sourst.Math;sourst.English;sourst.Computer;return sour;Student s100; /对象数组void

6、 ReadStuInfoFromFile() /读学生信息文件到数组中count=0;ifstream infile(d:StuInfo.txt,ios:in);Student st;infilest;while(!infile.eof()scount+=st;infilest;infile.close();void AddStuInfo() /添加学生信息char c;ofstream f(d:StuInfo.txt,ios:ate);doStudent st;cinst;fst;cout数据输入成功,想继续数入吗(y/n)c;if(c!=y&c!=n)cout输入错误!请重新输入!c;wh

7、ile(c=y);f.close();void FindByName() /按姓名查找学生ReadStuInfoFromFile();char n20;int j=0;char c;if(count=0)cout学生库中没有输入数据!endl;return;doint flag=0;cout请输入你要查询的学生姓名n;for(int j=0;jcount;j+)if(strcmp(n,sj.getname() )=0)flag=1;cout您要查询的学生是:sj.getname()endl;coutsjendl;if(flag=0)cout对不起!您要查询的学生不存在!endl;cout您想继

8、续查询吗?(y/n)c;if(c!=y&c!=n)cout输入错误!请重新输入!c;while(c=y);void FindByCourseNo() /查看课程考试情况ReadStuInfoFromFile();double CourseAve=0.0;char n;int j=0;char c;if(count=0)cout学生库中没有输入数据!endl;return; docout请输入你要查询的课程号 c:语文 m 数学 e 英语 p 计算机 n;cout您查询的结果如下:endl;for(int j=0;jcount;j+)coutsj.getname() 的成绩是: sj.getsc

9、ore(n)endl;CourseAve+=sj.getscore(n);cout该课程的平均成绩是:setprecision(2)setiosflags(ios:fixed)CourseAve/countendl;cout您想继续查询吗?(y/n)c;if(c!=y&c!=n)cout输入错误!请重新输入!c;while(c=y);void FindFault() /查找不及格学生ReadStuInfoFromFile();if(count=0)cout学生库中没有输入数据!endl;return;cout不及格情况如下:endl;for(int k=0;kcount;k+)if(sk.ge

10、tscore(c)60 | sk.getscore(m)60|sk.getscore(e)60 | sk.getscore(p)60)coutk+1 姓名: sk.getname()endl;if(sk.getscore(c)60)cout 语文: sk.getscore(c);if(sk.getscore(m)60)cout 数学: sk.getscore(m);if(sk.getscore(e)60)cout 英语: sk.getscore(e);if(sk.getscore(p)60) cout 计算机: sk.getscore(p);if(sk.getscore(c)60 | sk.getscore(m)60|sk.getscore(e)60 | sk.getscore(p)60)coutendl;void FindByStuNo() /按学号查找学生ReadStuInfoFromFile();char n20,j=0;char c;if(count=0)cout学生库中没有输入数据!endl;return; doint flag=0;cout请输入你要查询的学生的学号n;for(int j=0;jcount;j+)if(strcmp(sj.getNumber(),n)=0)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号