1、tt*MENU*); puts(nntt 1.The information to writeinntt 2.The race result records to writeinntt 3.Search the informationntt 4.Exitnntt*nnChoice you number: scanf(%d,&n); if(n4)o=1;getchar(); /*对选择的数字进行判断*/ else o=0; while(o=1); /*选择功能*/ switch(n) case 1:writein();break; /*信息输入模块*/ case 2:resultin(); /*
2、比赛结果输入模块*/ case 3:search(); /*查询模块*/ case 4:exit(0); /*退出*/ 各个模块的设计1、信息输入 数据结构数据结构采用结构体的形式,包括学校、项目、运动员三个结构体。比如学校结构体成员包括学校校名、竞赛项目、得分;项目结构体成员包括项目名、权值。struct student char shool10; char name10; char item10; char sex; int position; int mark;stuC; /*stuN中每个数组元素对应一个学生*/struct item char name10;itC; /*itC中每个
3、数组元素对应一个项目*/struct shoolshoC /* shoC每个数组元素对应一个学校;*/ 信息输入模块 根据题意把与运动员的学校、名字、项目、性别、名次、分数作为结构体成员,如果要存放若干个运动员的信息就用结构体数组。 struct student char item10; char sex; int position; int mark; /*stuC中每个数组元素对应一个运动员*/ stuC中的C为运动员的个数,程序中采用宏定义的方式定义C=100,C的值可随时在源程序中改变。图2 输入模块流程图/*输入模块*/writein() /*输入模块*/ int t,r,i=0;e
4、xtern j;char F,M;y=1; printf(nPlease writein the students name:tscanf(%sstui.name); /*输入名字*/s shool:stui.shool); /*输入学校*/s item:stui.item); /*输入项目*/loop_1:s sex(W or M):stui.sex); /*输入性别*/ if(stui.sex!=W&stui.sex!M)goto loop_1; /*选择函数*/nPleasewritein the students position:stui.position); mark(j,i);l
5、oop_2:printf(nnDo again?t1).Yest2).Nott); if(t!=2&t!=1)goto loop_2; /*调用goto结构*/ if(t=2)menu(); i+; if(t=1);f=1;SuccessnPress any key+enter to menu.r); /*返回主函数*/ menu();结果录入模块 该模块的功能是输入男女运动员的成绩,并由用户选择或定义各名次的分数。 流程图 /*结果录入模块*/resultin() /*结果录入模块*/ int h,r; extern N,M,W,y; if(y=0) printf(Please establ
6、ish system first!nPress any key +enter to menu. /*提醒用户输入运动员的基本信息*/nThe number of shool attended is:N);nThe number of men item is:M);nThe number of women item is:W); /*输入学校的代号、男女运动项目的代号*/nThere are three form of marked you can choice:nnt1).1th-7,2th-5,3th-3,4th-2,5th-1.nnt2).1th-5,2th-3,3th-1.nnt3).D
7、efine by youself. /*用户自定义*/loop:nnChoice the number(1-3):h); if(h0&h4|e1)goto loop;Press any key+enter to menu.c);search_school() /*学校查询程序*/ int x,sum=0,w=0; struct student s;nPlease enter the name of the school that you want to search:s.shool); printf_face(); for(x=0;xC;x+) if(strcmp(s.shool,stux.s
8、hool)=0) /*调用stu结构体*/ sum+=stux.mark; printf_one(x);w=1; /*读出结构体的数据*/ printf_sum(sum); if(w=0) printf(nn*The name is wrong,press again!search_item() /*项目查询程序*/nPlease enter the name of the item that you want to search:s.item); /*数据输入*/ if(strcmp(s.item,stux.item)=0) / *调用stu数组*/ /*数据输出*/程序中调用的函数 记分的
9、函数即用来确定不同的名次所得的不同分数。 mark(int j,int i) int g; extern p15,q15; if(j=1) if(stui.position=1)stui.mark=7; else if(stui.position=2)stui.mark=5; else if(stui.position=3)stui.mark=3; else if(stui.position=4)stui.mark=2; else if(stui.position=5)stui.mark=1; if(j=2) if(stui.position=1)stui.mark=5; else if(st
10、ui.position=2)stui.mark=3; else if(stui.position=3)stui.mark=1; if(j=3) for(g=0;g15;g+)if(stui.position=pg)stui.mark=qg;define_mark() /*自定义名次分数的子函数*/ static int p15,q15,a,b,j; for(a=0;aa+)nThe position(1-15):pa);nThe mark you want to define(Integral):qa);/*自定义*/nDo you want define more:t1).Yest2).No
11、b); if(b=2)break; if(b!=1)goto loop; j=3;printf_one(int x) /*运动员个人信息的输出函数*/ printf(n%-20s%-20s%-20s%-5c%-9d%-5d,stux.shool,stux.name,stux.item,stux.sex,stux.position,stux.mark);printf_sum(int sum) /*团体成绩的输出函数*/nnThe sum of mark is:t %d,sum);nThe shool number is: t%d,N);nThe item number is: t%dn,W+M);printf_face() /*学校成绩输出函数*/nnSchool name student name item sex position mark原程序 #include#define C 100int y=0,f=0,j,W,M,N,p15,q15;shoC;menu()writein()resultin()search() switch(e)search_school() if(strcmp(s.shool,stux.shool)=0)search_item() if(strcmp(s.item,stux.item)=0)w=
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1