南邮程序设计保龄球分数计算系统_第1页
南邮程序设计保龄球分数计算系统_第2页
南邮程序设计保龄球分数计算系统_第3页
南邮程序设计保龄球分数计算系统_第4页
南邮程序设计保龄球分数计算系统_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、保龄球分数计算一课题内容和要求【问题描述】用户依序输入每局所打的球数,程序会根据保龄球的计分规则本程序完成多名学生的保龄球计分。计算所得到的分数,并根据用户要求完成所得分数的排序和查找。【功能要求】(1)学生信息包括:学号,姓名,出生(年,月,日),得分。(2)需要实现的功能1)建立学生信息结构数组2)从键盘输入并显示每局的球数3)求得并显示每名学生的分数4)按分数递减选择排序5)显示按分数排序后学生信息6)按学号查学生信息和分数(顺序查找法)7)将排序后的内容存为文件,以后显示时直接从文件中调出而不用再执行排序算法。二,需求分析功能架构图1,记录学生信息1)建立学生信息结构数组(年,月,日)

2、,得分。2)学生信息包括:学号,姓名,出生2,记录对应学生每局的分数并排序从键盘输入并显示每局的球数求得并显示每名学生的分数按分数递减选择排序显示按分数排序后学生信息3,生成文件保存每局分数并调用按学号查学生信息和分数(顺序查找法)将排序后的内容存为文件,以后显示时直接从文件中调出而不用再执行排序算法。三、概要设计structstudent/*学生信息结构*/charno9;/*学号*/charname9;/*姓名*/structdatebirthday;/*出生日期*/intscore;/*保龄球得分*/;四、源程序代码#includestdafx.h#includestdio.h#incl

3、ude#includestructdateintyear,month,day;structstudent/*学生信息结构*/charno9;/*学号*/charname9;/*姓名*/*/structdatebirthday;/*出生日期intscore;/*保龄球得分*/;#defineN20structstudentstuN;intcount二0;/学生数FILE*sfp;/格式化显示分数信息voidshowscore(int*score)printf(这一局的分数信息n);inti;for(i=1;i11;i+)printf(%dt,i);for(i=1;i10;i+)printf(%-

4、4d%-4d,1,2);printf(123n);for(i=0;i10;i+)if(i=9)printf(%-3d,scorei*2);if(scorei*2=10)printf(%-2c,-);printf(%-3d,scorei*2+2);elseif(scorei*2+scorei*2+1=10)printf(%-2c,-);printf(%-3d,scorei*2+2);elseprintf(%-2d,scorei*2+1);printf(%-3c,-);break;printf(%-4d,scorei*2);if(scorei*2=10)printf(%-4c,-);elsepri

5、ntf(%-4d,scorei*2+1);/voidinputscore(int*score)ints1,s2,s3,test;for(inti=0;i10;i+)printf(Pleaseinputthescoreoftheround%2d:n,i+1);scanf(%d,&s1);if(s1!=10)printf(Pleaseinputthescoreofthesecondgoalinround%2d:n,i+1);scanf(%d,&s2);if(s1!=10)elses2=0;scorei*2=s1;scorei*2+1=s2;if(i=9&(s1+s2)=10)printf(Plea

6、seinputthescoreofthethirdgoalinround%2d:n,i+1);scanf(%d,&s3);elses3=0;score20=s3;voidinputscorefile(int*score)ints1,s2,s3;for(inti=0;i10;i+)printf(Pleaseinputthescoreoftheround%2d:n,i+1);fscanf(sfp,%d,&s1);printf(Pleaseinputthescoreofthesecondgoalinround%2d:n,i+1);fscanf(sfp,%d,&s2);elses2=0;scorei*

7、2=s1;scorei*2+1=s2;if(i=9&(s1+s2)=10)printf(Pleaseinputthescoreofthethirdgoalinround%2d:n,i+1);fscanf(sfp,%d,&s3);elses3=0;score20=s3;showscore(score);intfingerout(int*score)elses2=0;intsum=0,s1,s2,s3;for(inti=0;i10;i+)if(scorei*2=10|score19+score18=10)sum+=scorei*2+scorei*2+2;sum+=scorei*2+1;return

8、sum;intgettotalscore(introundscore21)inputscore(roundscore);returnfingerout(roundscore);/intinputstudent()intcount二0;/学生总人数while(1)printf(Pleaseinputtheinformationofthestudent.endforEnd.学号姓名yearmonthday(用enter键隔开各值):);scanf(%s,stucount.no);if(strcmp(stucount.no,end)=0)break;scanf(%s%d%d%d,stucount.n

9、ame,&stucount.birthday.year,&stucount.birthday.month,&stucount.birthday.day);count+;returncount;intinputstudentfile()FILE*filein;filein=fopen(student.txt,r);intcount二0;/学生总人数while(1)printf(Pleaseinputtheinformationofthestudent.endforEnd学号姓名yearmonthday(用enter键隔开各值):);fscanf(filein,%s,stucount.no);if

10、(strcmp(stucount.no,end)=0)break;fscanf(filein,%s%d%d%d,,&stucount.birthday.year,&stucount.birthday.month,&stucount.birthday.day);count+;count-;fclose(filein);returncount;/显示学生分数voidshowstudent(FILE*fp)fprintf(fp,T6s%T6s%T6sn,学生学号,学生姓名,学生分数);elses2=0;for(inti=0;icount;i+)fprintf(fp,%-16

11、s%-16s%dn,stui.no,,stui.score);/求得并显示每个学生的分数的信息voidscoreofstus()intscore21;for(inti=0;icount;i+)printf(请输入学号为s的学生的瓶数:n,stui.no);#ifdefFinputscorefile(score);#elseinputscore(score);#endifstui.score=fingerout(score);/显示所有学生的信息printf(显示所有学生的信息n);showstudent(stdout);voidsort()/structstudentt=st

12、u0;intmin=0,j;for(inti=0;icount;i+)for(j=0;jstuj.score)min=j;j-;t=stuj;stuj=stumin;stumin=t;intsearch(char*no)inti=0;while(icount&strcmp(stui.no,no)!=0)i+;if(i=count)printf(notfind);return-1;returni;/intmain()sfp=fopen(score.txt,w+);#ifdefFcount=inputstudentfile();#elsecount=inputstudent();#endifsco

13、reofstus();sort();showstudent(stdout);FILE*fp;fp=fopen(data.dat,w);showstudent(fp);fclose(fp);fclose(sfp);while(1)charno9;intselect=0;TOC o 1-5 h zprintf(请选择:n);printf(0.显示学生信息:n);printf(1.查找:n);printf(2.退出n);scanf(%d,&select);switch(select)break;case0:showstudent(stdout);case1:printf(请输入学号:);scanf(

14、%s,no);intii=search(no);printf(T6s%T6s%T6sn,学生学号,学生姓名,学生分数);printf(%-16s%-16s%dn,stuii.no,,stuii.score);break;case2:exit(0);default:printf(输入有误,请重新输入:n);break;return0;五、测试数据及其结果分析1,测试学生数据的建立数据如下:学号姓名生日分数101学生119910101151102学生219910102200103学生319910103198104105学生4学生51991010418519910105197测试

15、项目:1、输入学生信息,2、输入球数计算结果进入程序需要先建立学生数据出现如下提示:Pleaseinputtheinformationofthestudent.endforEnd.学号姓名yearmonthday(用enter键隔开各值):按要求键如完整的数据后自动跳入下一学生输入。输入end则结束输入学生信息开始比赛。从建立的第一个学生开始输入每局的球数,分别出现以下提示请输入学号为s的学生的瓶数:(%sD00DPleaseinputthescoreoftheround%2d:Pleaseinputthescoreofthesecondgoalinround%2dPleaseinputthe

16、scoreofthethirdgoalinround%2d:(只在第十局判定后出现。)显示学生信息学号姓名生日分数101学生119910101151102学生219910102200103学生319910103198104学生419910104185105学生519910105197学号姓名生日分数102学生219910102200103学生319910103198105学生519910105197104学生419910104185101学生119910101151请选择:0.查询学生信息:1.查找:2.退出3、输入“0回车”查询学生信息学号姓名生日分数102学生219910102200103

17、学生319910103198105学生519910105197104学生419910104185101学生1199101011514、输入“1回车”查找输入学号“103回车”学号姓名生日分数103学生3199101031985、退出输入“2回车”退出存为文档六、调试过程中的问题1、在输入学生信息时要按照“学号空格姓名空格年空格月空格日回车”的格式输入,否则在显示学生信息是将出现问题。并以“end”结尾。8个球,2、要严格根据保龄球规则,如第一局第一次击打输入8,第二次应输入小于2的数,否则程序依然可以运行,但不符合正常记分规则。3、如果学生分数相同,排序有可能不按递减排,我们无法调试;但分数不同,能够正常按递减排序。七、课程设计总结刚拿到题目的时候有点

温馨提示

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

评论

0/150

提交评论