对参赛结果分数进行分析C++

上传人:仙*** 文档编号:34684243 上传时间:2021-10-22 格式:DOC 页数:31 大小:318KB
收藏 版权申诉 举报 下载
对参赛结果分数进行分析C++_第1页
第1页 / 共31页
对参赛结果分数进行分析C++_第2页
第2页 / 共31页
对参赛结果分数进行分析C++_第3页
第3页 / 共31页
资源描述:

《对参赛结果分数进行分析C++》由会员分享,可在线阅读,更多相关《对参赛结果分数进行分析C++(31页珍藏版)》请在装配图网上搜索。

1、课程设计报告课程设计题目:对参赛结果分数进行分析学生姓名: 专 业: 班 级:指导教师: 2011年11月25日东华理工大学课程设计评分表学生姓名:朱秀刚 班级:10211303 学号:1021130326课程设计题目:对参赛结果分数进行分析项目内容满分实 评选题能结合所学课程知识、有一定的能力训练。符合选题要求(5人一题)10工作量适中,难易度合理10能力水平能熟练应用所学知识,有一定查阅文献及运用文献资料能力10理论依据充分,数据准确,公式推导正确10能应用计算机软件进行编程、资料搜集录入、加工、排版、制图等10能体现创造性思维,或有独特见解10成果质量总体设计正确、合理,各项技术指标符合

2、要求。10说明书综述简练完整,概念清楚、立论正确、技术用语准确、结论严谨合理;分析处理科学、条理分明、语言流畅、结构严谨、版面清晰10设计说明书栏目齐全、合理,符号统一、编号齐全。格式、绘图、表格、插图等规范准确,符合国家标准10有一定篇幅,字符数不少于500010总 分100指导教师评语: 指导教师签名: 年 月 日目录一、问题分析二、结构分析三、实现流程分析四、个性功能介绍五、课程设计小结一、问题描述及分析1、问题描述参赛选手n人(n1),评委m人(m2),评委给每一选手打一个分数score(分数scor为小于等于10的一个正实数)。选手的最后得分lastScore计算方法为(1)m9时,

3、去掉一个最高分和一个最低分后另m-2个得分的平均值。(2)m9时,去掉两个最高分和两个最低分后另m-4个得分的平均值。假设事先已经建立了text型的数据文件f1.txt,其中依次记录着n个选手的编号(一个正整数)、姓名(一个字符串)以及m个评委给出的得分。请编制程序,依次从数据文件f1.txt中读入n个选手的有关信息,而后按上述规定方法计算出每一个选手的最后得分,而且往屏幕上以及另一个text型文件f2.txt中同时输出如下形式的结果信息。假设参赛选手人数n=5,评委人数m=7,磁盘文件f1.txt中的初始数据为:1 zhangjin 8.8 9.3 7.9 8.7 8.9 9.7 9.22

4、lintao 8.9 8.2 8.6 8.8 8.5 9.1 9.33 guojian 8.9 8.4 8.7 8.6 8.6 8.4 8.64 maling 7.9 8.3 8.5 8.6 8.5 8.9 8.35 liuyifan 9.5 9.1 9.8 9.2 9.0 9.5 8.9那么,程序执行后,屏幕显示结果以及磁盘文件f2.txt中的结果均应该为:-参赛号 姓 名 最高分 最低分 累积分最后得分- 1 zhangjin9.77.944.9 8.982 lintao 9.38.2 43.9 8.783 guojian 8.98.4 42.9 8.584 maling 8.97.9 4

5、2.28.445 liuyifan 9.8 8.9 46.3 9.26-思考:可进一步考虑找出比赛的第1至第k名,也在屏幕以及f2.txt中同时输出相关的结果信息(k小于等于n,并规定若多个选手最后得分相同时,则有效分(即已删除原来的最高分后)中最高分高者名次优先)。2、问题分析(1)、要对参赛结果的数据进行分析,首先要有数据的来源,在面向对象的设计中,数据来源于对象,在这里我们可以构建一个类Competition(参赛选手),作为数据的来源,建一个Competition的友元类Judge(评委)通过其成员函数给Competition的数据成员初始化,这就有了数据的来源。 (2)、对数据的处理

6、可以通过对Competition类设计功能函数来实现,其数据处理功能有:对每个选手的得分按从高分到低分排序、求最高分、最低分、累计得分、最后得分和对所有选手进行名次排序等。(3)、因为题目要求把原始数据和处理后的结果分别存放到f1.txt,f2,txt文件,因此可建立一个Competition的基类Compbase(选手基类)其数据成员只有number(编号),name(姓名),max_score(最高分),min_score(最低分),sum_score(累计得分),last_score(最后得分),用来存储处理后的结果,这样就可以方便地把处理后的结果存入到f2.txt文件。二、结构分析1.

7、通过以上的分析可以得出系统类Compbase,Competition,Judge之间的关系如下UML图:Competition是Compbsae的派生类Compbase-number:int-name:string-max_score:double-min_score:double-last_score:double-sun_score:double+Compbase()+Compbase()+Compbase_input(*p:Compebase,n:int):void +operator=(&p:Compbase):voidCompetition-number:int-name:strin

8、g-*score:double-max_score:double-min_score:double-lase_score:double-sum-score:double-n:int+Competition(); +Competition(number1:int,name1:string, *score1:double,n1:int)+Competition() +Comp_input(*p:Competition,n:int):void +Comp_set(number1:int,name1:string,*score1:double,n1:int):viod+Score_order():vo

9、id +Max_score():double +Min_score():double +Sum_score():double +Last_score():double +Comp_order(*p,const:Competition,n1:int):void+Comp_show():void +classJudge:frind +Score_set():void+operator=(&p:Competition):voidJudge是Competition的友元Judge-number:int -name:string+Judge()+Judge(number1:int,name1:strin

10、g)+Give_score(*x:Competition,*y:Judge,z:int,h:int):void+Judge()+class Competition:friend三、函数实现流程分析1、Compbase类函数的流程图(1).信息输入函数i=0in false truecout请输入第i+1pi.number; coutendl请输入第i+1pi.name; coutendl;i+(2). 符号重载实现对象的拷贝number=p.number;name=p.name;max_score=p.max_score;min_score=p.min_score;last_score=p.l

11、ast_score;sum_score=p.sum_score; 2、Competition类函数的流程图(1).无参数的构造函数number=0; name=无; score=new double0; max_score=0; min_score=0; sum_score=0; last_score=0;(2).含参数的构造函数n=n1; number=number1; name=name1; score=new doublen; score=score1;i=0(3).从键盘录入信息函数in false truecout请输入第i+1pi.number; coutendl请输入第i+1pi

12、.name; coutendl;i+(4) 每个选手的得分数从最高分到最低分排序函数Competition temp;int i=0;in-1; false trueint j=0;jn-i-1; fasle truescorejscorej+1 fasle truetemp=scorej;scorej=scorej+1;scorej+1=temp;j+; i+;(5).求最高分函数调用分数排序函数return max_score=score0;(6).求最低分函数Score_order();return min_score=scoren-1; (7)求总累计得分函数定义double sum=

13、0;存储累计得分 调用分数排序函数评委个n数大于9 falsetrue去掉两个最高分和两个最低分,求累计得分Sum_score评委个数n大于2且小于9 false ture去掉一个最高分和一个最低分,求累计得分Sum_score(8).求最后得分函数调用求累计得分函数评委个数n大于9个 false ture 最后得分等于累计得分除以4评委个数n大于2且小于9 false 最后得分等于累计得分除以2(9). 按得分把所有选手的名次排序函数定义一个Competition类的对象tempint i=0;i小于选手个数减1 ture false tureint j=0;j小于选手个数减(i+1) fa

14、lse true第j个选手的最后得分小于第j+1个选手的最后得分 falsetrue 交换第j个选手与第j+1个选手的顺序 第j个选手的最后得分等于第j+1个选手的最后得分且,第j个选手的最高得分小于第j+1个选手的最高得分 false true交换第j个选手与第j+1个选手的顺序 j+; i+;(10).向屏幕输出信息函数coutsetiosflags(ios_base:left); coutsetw(15)numbersetw(15)namesetw(15)max_scoresetw(15)min_scoresetw(15)sum_scoresetw(15)last_scoreendl;

15、resetiosflags(ios_base:left);(11). 符号重载实现深拷贝函数n=p.n; number=p.number; name=p.name; score=new doublen; *score=*p.score; max_score=p.max_score;min_score=p.min_score;last_score=p.last_score;sum_score=p.sum_score;3、 Judge类成员函数的(1). 构造函数number=number1;name=name1;(2). 评委给分函数int i=0;i小于选手个数 false true把评委个数

16、n1赋值给对象的数据成员nint j=0;j小于评委个数 false truecout第j+1号评委给i+1号选手评分(分值大于0,小于10):; double score1;从键盘输入score1的值score110 false truecout输入错误,请重新输入:;i+;4、main函数定义一个Competition类指针对其动态分配内存,并且对Cper其初始化定义一个输出流把Cper指向的内容写入文件f1.txt定义一个输入流,从文件f1.txt中读出数据存在Competition 指针Cper2,调用Competition的函数成员对Cper2的每个元素求分数排序,最高分,最低分,累

17、计得分,最后得分和名次排序。定义一个Compbase类的指针Cper3,把Cper2处理后的结果赋值给Cper3。定义一个输出流,把Cper3的信息输出到磁盘文件f2.txt.和屏幕定义一个Comptition类的指针和Judge类的指针,调用从键盘输入信息函数和评分函数5、程序的具体实现(1).建立一个工程Competition.(2).在工程中分别建立一个Comp.h、Competition.cpp文件和一个test.cpp文件。(3).Comp.h中的代码如下:/*/*程序名称:评分系统 */*作 者:朱秀刚 */*学 号:1021130326 */*编制时间:2011年11月 */*程

18、序功能:对参赛结果分数进行处理 */*#includeusing namespace std;class Judge;class Compbase /选手基类public:Compbase()Compbase()void Compbase_input(Compbase *p,int n); /信息输入函数void operator=(Compbase &p) ; /符号重载private:int number; /参赛号string name; /姓名double max_score; /最高分double min_score; /最低分double sum_score; /总得分double

19、 last_score; /最后得分 ;/*class Competition:public Compbase /参赛选手的派生类public:Competition(); /构造函数 Competition(int number1,string name1,double *score1,int n1); /参赛选手构造函数Competition() /析构函数delete score;void Comp_input(Competition *p,int n); /信息从键盘录入函数 void Comp_set(int number1,string name1,double *score1,i

20、nt n1); /信息录入函数void Score_order(); /分数排序函数double Max_score(); /求最高分函数double Min_score(); /求最低分函数double Sum_score(); /求总得分函数double Last_score(); /求最后得分函数void Comp_order(Competition *p,const int n1); /参赛人员名次排序void Comp_show(); /显示信息函数friend class Judge; /声明评委类为选手类的友元类void Score_set();void operator=(Co

21、mpetition &p);private:int number; /参赛号string name; /姓名double *score; /定义一个指针,指向裁判给的分数 double max_score; /最高分double min_score; /最低分double sum_score; /总得分double last_score; /最后得分 int n; /n表示评委的个数;/*class Judge /定义评委类public:Judge();Judge(int number1,string name1); /Judge的构造函数void Give_score(Competition

22、 *x,Judge *y,int z,int h); /评委给分函数Judge() /析构函数friend class Competition; /Competition为Judge的友元类private:int number; /评委号string name; /评委姓名;(4).Competition.cpp文件中的代码如下:#includeComp.h#include#include#include /基类Compbase成员函数的实现void Compbase:Compbase_input(Compbase *p,int n) /信息输入函数 for(int i=0;in;i+) co

23、ut请输入第i+1pi.number; coutendl请输入第i+1pi.name; coutendl;void Compbase:operator=(Compbase &p) /符号重载实现对象的拷贝 number=p.number; name=p.name;max_score=p.max_score;min_score=p.min_score;last_score=p.last_score;sum_score=p.sum_score;/*/派生类Competition成员函数的实现Competition:Compet /构造函数 number=0; name=无; score=new d

24、ouble0; max_score=0; min_score=0; sum_score=0; last_score=0; Competition:Competition(int number1,string name1,double *score1,int n1) /参赛选手构造函数 n=n1; number=number1; name=name1; score=new doublen; score=score1;void Competition:Comp_input(Competition *p,int n1) /信息从键盘录入函数 n=n1;for(int i=0;in1;i+) cout

25、请输入第i+1pi.number; coutendl请输入第i+1pi.name; coutendl;void Competition:Comp_set(int number1,string name1,double *score1,int n1) /信息录入函数n=n1; number=number1; name=name1; score=new doublen; score=score1;void Competition:Score_order() /每个选手的得分 /从最高分到最低分排序函数double temp=0;for(int i=0;in-1;i+)for(int j=0;jn-

26、i-1;j+)if(scorej9) /评委个数大于9时去掉两 for(int i=2;in-2;i+) /个最高分和两个最低分 sum+=scorei; else if(n2) /评委个数小于等于9个且大于2个 for(int j=1;j9) last_score=sum_score1/(n-4); if(n2) last_score=sum_score1/(n-2); return last_score; void Competition:Comp_order(Competition *p,const int n1) /按得分把所有 /选手的名次排序Competition temp;for

27、(int i=0;in1-1;i+)for(int j=0;jn1-i-1;j+)if(pj.last_scorepj+1.last_score) /按最后得分排序temp=pj;pj=pj+1;pj+1=temp;else if(pj.last_score=pj+1.last_score) /最后得分相等时比较最高分if(pj.max_scorepj+1.max_score) temp=pj; pj=pj+1; pj+1=temp;void Competition:Comp_show() /显示信息函数 coutsetiosflags(ios_base:left); coutsetw(15)

28、numbersetw(15)namesetw(15)max_scoresetw(15)min_scoresetw(15)sum_scoresetw(15)last_scoreendl; resetiosflags(ios_base:left); void Competition:operator=(Competition &p) /符号重载实现深拷贝 n=p.n; number=p.number; name=p.name; score=new doublen; *score=*p.score; /传指针指向内存里的值max_score=p.max_score;min_score=p.min_s

29、core;last_score=p.last_score;sum_score=p.sum_score;/* /Judge类成员函数的实现Judge:Judge(int number1,string name1) /Judge类的构造函数 number=number1;name=name1;void Judge:Give_score(Competition *x,Judge *y,int z,int h)/评委给分函数 for(int i=0;iz;i+) xi.n=h; for(int j=0;jh;j+) cout第j+1号评委给i+1 score1; if(score110) cout输入

30、错误,请重新输入:; while(score110); xi.scorej=score1; coutendl; (5).test.cpp文件中是代码如下:#include#includeComp.h#include#include#includeint main() const int n=5,m=7; /n为参赛者人数,m为评委人数 Competition *Cper; /定义一个Competition类存储参赛者信息 Cper=new Competitionn; int numbern=1,2,3,4,5; /参赛者号 string namen=zhangjin,lintao,gaojia

31、n,maling,liuyifan; /参赛者姓名 double score57=8.8,9.3,7.9,8.7,8.9,9.7,9.2,8.9,8.2,8.6,8.8,8.5,9.1,9.3 /评委给的分数 ,8.9,8.4,8.7,8.6,8.6,8.4,8.6,7.9,8.3,8.5,8.6,8.5,8.9,8.3 ,9.5,9.1,9.8,9.2,9.0,9.5,8.9; for(int i=0;in;i+) Cperi.Comp_set(numberi,namei,scorei,m); /录入参赛者的信息 ofstream file; /定义一个输出流,把参赛者的信息写入的磁盘 fi

32、le.open(f1.txt,ios_base:out); file.write(reinterpret_cast(Cper),n*sizeof(Competition); file.close(); Competition *Cper2=new Competitionn; /*Cper2用来存储从文件中读出的数据 ifstream is; is.open(f1.txt,ios_base:in); /定义一个输入流,f1.txt中的信息读入内存 if(is) is.read(reinterpret_cast(Cper2),n*sizeof(Competition); is.close(); c

33、out-endl;coutsetiosflags(ios_base:left) /控制输出格式为左对齐 setw(15)参赛号setw(15)姓名setw(15)最高得分setw(15)最低得分setw(15)累计得分setw(15)最后得分endl; cout-endl; resetiosflags(ios_base:left); /关闭左对齐格式 for(int j=0;jn;j+) /把从磁盘文件读出的数据进行处理 Cper2j.Max_score(); /求最高分 Cper2j.Min_score(); /求最低分 Cper2j.Sum_score(); /求累计得分 Cper2j.L

34、ast_score(); /求最后得分 Cper2j.Comp_show(); /把选手的主要信息输出的屏幕 Compbase *Cper3=new Compbasen; /定义一个选手基类,用来存储处理后的数据结果 Cper3=Cper2; /把处理后的结果赋值给Cper3 ofstream file2;file2.open(f2.txt,ios_base:out); /定义一个输出流,把参赛者的信息写入的磁盘文件 file2.write(reinterpret_cast(Cper3),n*sizeof(Compbase); file2.close(); Cper20.Comp_order(

35、Cper2,n); cout按最后得分排名后的结果为endl; for(int k=0;kn;k+) Cper2k.Comp_show(); /把处理过的信息输出的屏幕 /增加功能从键盘输入选手的信息,对其结果进行处理 int s,d; /s为参赛者数,d为评委数 Competition *Cper4; /定义一个参赛选手的指针 Judge *Jud; /定义一个评委的指针 couts; coutendld; Cper4=new Competition s; Jud=new Judge d; for(i=0;is;i+)Cper40.Comp_input(Cper4,s);Jud0.Give_

36、score( Cper4,Jud,s,d); /调用评分函数ofstream file3; /定义一个输出流,把参赛者的信息写入的磁盘文件file3.open(f1.txt,ios_base:out|ios_base:ate); file3.write(reinterpret_cast(Cper4),s*sizeof(Competition); file3.close(); Competition *Cper5=new Competitions; /*Cper2用来存储从文件中读出的数据 ifstream is2; is2.open(f1.txt,ios_base:in); /定义一个输入流,f1.txt中的信息读入内存 if(is2) is2.read(reinterpret_cast(Cper5),s*sizeof(Comp

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!