[计算机]C语言课程设计.doc

上传人:sccc 文档编号:4561004 上传时间:2023-04-27 格式:DOC 页数:25 大小:150KB
返回 下载 相关 举报
[计算机]C语言课程设计.doc_第1页
第1页 / 共25页
[计算机]C语言课程设计.doc_第2页
第2页 / 共25页
[计算机]C语言课程设计.doc_第3页
第3页 / 共25页
[计算机]C语言课程设计.doc_第4页
第4页 / 共25页
[计算机]C语言课程设计.doc_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《[计算机]C语言课程设计.doc》由会员分享,可在线阅读,更多相关《[计算机]C语言课程设计.doc(25页珍藏版)》请在三一办公上搜索。

1、1.电子档案.包括源代码.参考文献资料. 程序设计报告(Word文档。要求5页)2.纸质档案.把电子的打印出来.+封面. 封面(题目.班级.姓名.学号.指导老师.完成时间.) C语言课程设计题目一:选票系统某班从全班20人(学号120)中投票选举6位班委委员,每张选票内容包括:所选班委的学号,投票人学号。要求用菜单选择并完成下述系统功能:1:输入全班的名单(姓名与学号),并可显示。 2:选票输入:输入每张选票的投票人学号及所选班委的学号(可选6个,没有则键入空白)。 3:输出得票前6位的当选班委名单(如第6位有多位得票数相等,则从中任选一位输出)及其得票率(得票数总选票数) 4:可以输出6位班

2、委名单全部选择与投票结果完全相符的投票人姓名。 5:退出程序。 示例程序源代码:示例一:#include #include struct student int xh; /学号 char xm10; /姓名 int flag; /已投票数 int flag_p; /被票数 int xp_xh6; /被选人学号 stu20; /函数功能:录入学生信息 void lr() int i; for(i=0;i=20;i+) printf(学号:%dn,i); printf(请输入姓名:); stui.xh=(i+1); scanf(%c,&stui.xm); stui.flag=0; stui.fla

3、g_p=0; stui.xp_xh6=0; printf(n); printf(继续输入? ); system(pause); system(cls); printf(学号t); printf(姓名t); printf(票数n); for(i=0;i=20;i+) printf(%dt,stui.xh); printf(%ct,&stui.xm); printf(%d,stui.flag_p); /函数功能:投票,对数据进行操作 ,输出结果 void tp(int tpr,int tp)int q=0;if (stutpr-1.flag20 | tpr0) printf(输入有误!n); sy

4、stem(pause); else q = stutpr-1.flag; stutpr-1.xp_xhq=(tp-1); stutpr-1.flag+; stutp-1.flag_p+; else printf(您已经投了6票!); system(cls); printf(投票结果:t); printf(学号t姓名t票数t投票数n); for (int k=0;k=20;k+) printf(%dt%ct%dt%d,stuk.xh,&stuk.xm,stuk.flag_p,stuk.flag); system(/npause); exit(1); int mian() int xh_tpr;

5、/投票人学号 int xh_tp; /被投票人学号 lr(); start: printf(请输入你的学号:); scanf(%d,&xh_tpr); printf(n请输入你要投票人的学号:); scanf(%d,&xh_tp); tp(xh_tpr,xh_tp); goto start; 示例二:#include #include typedef struct node / 候选人结构char name8;int num;int score;int tax;Node;void shellSort( Node *, int );int main(void)int n = 0;Node * p

6、Array9=;/指针数组,长度9int count = 0;/int status = 1;int vote = -1;printf(Input the number of the candidates(1-9):n);scanf(%d, &n);while(getchar()!=n);while (n9 | n9)printf(No, there cannot be so many candidates. Retry.n);elseprintf(No candidates? It cannot be! Retry!n);scanf(%d, &n);while(getchar()!=n) ;

7、for (count=0; countnum = count+1;pArraycount-tax = 0;pArraycount-score = 0;printf(Input No.%d candidates name:n, count+1);gets(pArraycount-name);while (vote)printf(Now, let us vote:n*n);for (count=0; countname);printf(0.quitn*n);scanf(%d, &vote);while(getchar()!=n) ;while (voten)printf(No joke, than

8、k you. Revote.n);scanf(%d, &vote);while(getchar()!=n) ;if (vote0&votescore+;printf(Finish voting. Lets find the winner.nn);shellSort( pArray, n );for (count=0; counttax=count+1;printf(%d. %s %d votes.n, count+1, pArraycount-name, pArraycount-score);for(count=0; count0)for (i=gap; i=0) & (pj-score sc

9、ore) )*(p+j+gap) = *(p+j);j = j - gap;*(p+j+gap) = temp;gap /= 2;运行与输入方式:1.程序提示,输入候选人人数, 输入数字(1-9),大于9或小于1或者输入不合法字符会提示错误。2.程序提示依次输入候选人名字,不能超过7个字符(少了点,你题目给的,数组拉长点会更安全些)3.按照程序提示的数字开始投票,或者退出。4.投票过程结束后,程序调用shellSort(希尔排序)函数对所有参选人按照得票数目进行降序排序,并将排序结果输出。题目二:简单学生成绩管理系统从键盘输入一个班学生(小于30人)的数学、英语、计算机三门课程的成绩,并保存到

10、文件中,要求:计算出每位学生的平均成绩和总成绩(每位学生的学号不能重复)。:按总成绩从高到低排序。:输人的学号、姓名、总成绩和排名次序。(思考:如何增加一位学生资料?如何删除一位学生资料?)知识点包括:分支语句、循环语句、结构体、文件打开关闭、输入输出函数、排序算法等。 示例程序一:#include stdio.h#include stddef.h#include stdlib.h#include conio.h /*屏幕操作函数*/#include string.h#define MAX 10typedef struct student char nameMAX; char numMAX;

11、char sexMAX; int age; int chinese; int mathematic; int english; float aver; struct student *next; stu;stu *head;void print() /*输出菜单*/ textcolor(RED); /*设置文本显示颜色为红色*/ textbackground(GREEN); /*设置背景颜色为绿色*/ window(1,1,80,10); /* 制作显示菜单的窗口*/ clrscr();printf( n);printf( * welcome to use student manage *n)

12、;printf( * MENU *n);printf( * Enter Record ); /*录入信息*/printf( Statistics *n); /*显示成绩*/printf( * Quest ); /*查询*/printf( Updata *n); /*修改*/printf( * Save ); /*保存到磁盘*/printf(Display *n); /*统计成绩*/printf( * Fresh ); /*刷新*/printf(Quit *n); /*退出系统*/printf( $ Maker: zhangwantong Class:045 Date:2007.01.12 $n

13、);printf( n);void cin(stu *p1) /*录入学生信息 */ printf(Enter name:n); scanf(%s,p1-name); printf(Enter num:n); scanf(%s,p1-num); printf(Enter sex:n); scanf(%s,&p1-sex); printf(Enter age:n); scanf(%d,&p1-age); printf(Enter score:n); printf(Enter chinese:n); scanf(%d,&p1-chinese); printf(Enter math:n); scan

14、f(%d,&p1-mathematic); printf(Enter English:n); scanf(%d,&p1-english);p1-aver=(p1-chinese+p1-mathematic+p1-english)/3.0; /*平均分*/ void cindata() /*是否继续录入*/ stu *p1,*p2; int i=1; char ch; head=(stu *)malloc(sizeof(stu); p1=head; /*头指针*/ while(i) cin(p1); printf(Do you Want to Continue?yes or no:); ch=g

15、etchar(); ch=getchar(); if(ch=n|ch=N) i=0; p1-next=NULL; else p2=p1; p1=(stu *)malloc(sizeof(stu); p2-next=p1; void lookdata(stu *p1) /*输出所有信息*/ printf(-n); while(p1!=NULL) printf(Num:%s ,p1-num); printf(Name:%s ,p1-name); printf(Sex:%s ,p1-sex); printf(Age:%d ,p1-age); /* printf(n); */ printf(Chine

16、se:%d ,p1-chinese); printf(Math:%d ,p1-mathematic); printf(English:%d ,p1-english); printf(Average:%fn,p1-aver); printf(-n); p1=p1-next; printf(-n); /*已经完成的任务:1.录入保存磁盘2.按姓名学号查询3.输出成绩表4.修改处理5.统计学生成绩*/void find1(stu *p2) /* 按姓名查找信息 */ char name20; int b=0; printf(Enter the name of the student you want

17、 to find:); scanf(%s,name); while(p2!=NULL) if(strcmp(name,p2-name)=0) printf(The data you want has be foundn); printf(-n); printf(Num:%st,p2-num); printf( Name:%st,p2-name); printf(sex:%st,p2-sex); printf(age:%dt,p2-age); printf(n); printf(Chinese:%dt,p2-chinese); printf(Math:%dt,p2-mathematic); pr

18、intf(English:%dt,p2-english); printf(Average:%fn,p2-aver); printf(*n); b=1; p2=p2-next; if(b=1) printf(Find onen); else printf(Not findn);void find2(stu *p2) /* 按学号查找信息 */ char numMAX; int b=0; printf(Enter the num of the student you want to find:); scanf(%s,&num); while(p2!=NULL) if(strcmp(num,p2-n

19、um)=0) printf(The data you want has be foundn); printf(-n); printf(Num:%st,p2-num); printf( Name:%st,p2-name); printf(Sex:%st,p2-sex); printf(Age:%dt,p2-age); printf(n); printf(Chinese:%dt,p2-chinese); printf(Math:%dt,p2-mathematic); printf(English:%dt,p2-english); printf(Average:%fn,p2-aver); print

20、f(*n); b=1; p2=p2-next; if(b=1) printf(Find onen); else printf(Not findn);void find() /*查询记录*/ int i; printf(Find with name Find with num Returnn); printf(Please Enter your choice:); scanf(%d,&i); switch(i) case 1: find1(head); break; case 2: find2(head); break; case 3: return; void update1(stu *p2)

21、 /*按姓名修改*/ char name10; int b=0; printf(Enter The Name:); scanf(%s,name); while(p2!=NULL) if(strcmp(name,p2-name)=0) printf(Find you data!n); printf(Enter the new name:); scanf(%s,p2-name); printf(Enter the num:); scanf(%s,p2-num); printf(Enter the sex:); scanf(%s,p2-sex); printf(Enter the age:); sc

22、anf(%d,&p2-age); printf(Enter the chinese score:); scanf(%d,&p2-chinese); printf(Enter the math score:); scanf(%d,&p2-mathematic); printf(Enter the english score:); scanf(%d,&p2-english); p2-aver=p2-chinese+p2-mathematic+p2-english; printf(Success!n); b=1; p2=p2-next; if(b=0) printf(Sorry not Find d

23、ata!n); else printf(Finish!n); void update2(stu *p2) /*按学号修改*/ char numMAX; int b=0; printf(Enter The Num:); scanf(%s,&num);while(p2!=NULL) if(strcmp(num,p2-num)=0) printf(Find you data!n); printf(Enter the new name:); scanf(%s,p2-name); printf(Enter the num:); scanf(%s,p2-num); printf(Enter the sex

24、:); scanf(%s,p2-sex); printf(Enter the age:); scanf(%d,&p2-age); printf(Enter the chinese score:); scanf(%d,&p2-chinese); printf(Enter the math score:); scanf(%d,&p2-mathematic); printf(Enter the english score:); scanf(%d,&p2-english); p2-aver=(p2-chinese+p2-mathematic+p2-english)/3.0; printf(Succes

25、s!n); b=1; p2=p2-next; if(b=0) printf(Sorry not Find data!n); else printf(Finish!n); void update() /*修改记录*/ int i; printf(Updata with name Updata with num Returnn); printf(Please Enter your choice:); scanf(%d,&i); switch(i) case 1: update1(head); break; case 2: update2(head); break; case 3: return;

26、void saved(stu *p2) /*保存到磁盘student.dat文件中*/ FILE *fp; char file16=c:student.dat; char file1=num-name-sex-age-chinese-math-english-avern; if(fp=fopen(file,wt)=NULL) printf(nCannot open the file !n); return; fprintf(fp,%s,file1);while(p2!=NULL) fprintf(fp,%s-,p2-num); fprintf(fp,%s-,p2-name); fprintf(

27、fp,%s-,p2-sex); fprintf(fp,%d-,p2-age); fprintf(fp,%d-,p2-chinese); fprintf(fp,%d-,p2-mathematic); fprintf(fp,%d-,p2-english); fprintf(fp,%fn,p2-aver); p2=p2-next; fclose(fp);printf(Saved successed!);void statistics(stu *p2) /*统计学生成绩*/ FILE *fp,*fp1; char file16=c:stufile.dat,file116=c:stugood.dat;i

28、f(fp=fopen(file,wt)=NULL) printf(nCannot open the file !n); return; if(fp1=fopen(file1,wt)=NULL) printf(nCannot open the file !n); return; while(p2!=NULL) if(p2-chineseenglishmathematicnum); fprintf(fp,%s-,p2-name); fprintf(fp,%s-,p2-sex); fprintf(fp,%d-,p2-age); fprintf(fp,%d-,p2-chinese); fprintf(

29、fp,%d-,p2-mathematic); fprintf(fp,%d-,p2-english); fprintf(fp,%fn,p2-aver); p2=p2-next; else if(p2-chinese=90)&(p2-english=90)&(p2-mathematic=90) fprintf(fp1,%s-,p2-num); fprintf(fp1,%s-,p2-name); fprintf(fp1,%s-,p2-sex); fprintf(fp1,%d-,p2-age); fprintf(fp1,%d-,p2-chinese); fprintf(fp1,%d-,p2-mathematic); fprintf(fp1,%d-,p2-english); fprintf(fp1,%fn,p2-aver); p2=p2-next; elsep2=p2-next;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 教育教学 > 成人教育


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号