C语言程序设计基础课程设计报告 .doc

上传人:laozhun 文档编号:2384690 上传时间:2023-02-17 格式:DOC 页数:17 大小:75.50KB
返回 下载 相关 举报
C语言程序设计基础课程设计报告 .doc_第1页
第1页 / 共17页
C语言程序设计基础课程设计报告 .doc_第2页
第2页 / 共17页
C语言程序设计基础课程设计报告 .doc_第3页
第3页 / 共17页
C语言程序设计基础课程设计报告 .doc_第4页
第4页 / 共17页
C语言程序设计基础课程设计报告 .doc_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《C语言程序设计基础课程设计报告 .doc》由会员分享,可在线阅读,更多相关《C语言程序设计基础课程设计报告 .doc(17页珍藏版)》请在三一办公上搜索。

1、C语言程序设计基础课 程 设 计 报 告班 级: 计算 07-2 班 学 号: 0706010202 姓 名: 蔡子俊 成 绩: 电子与信息工程学院计算机科学与技术系C语言程序设计基础课程设计报告题目一:修改时钟程序阅读下面的时钟程序及观察运行结果写出程序中存在问题及改进办法,写出改进后的程序。时钟程序:#include#include#include#define pi 3.1415926#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;#define d(a

2、,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)void init()int i,l,x1,x2,y1,y2; setbkcolor(1); circle(300,240,200); circle(300,240,205); circle(300,240,5); for(i=0;i60;i+) if(i%5=0) l=15; else l=5; x1=200*cos(i*6*pi/180)+300; y1=200*sin(i*6*pi/180)+240; x2=(200-l)*cos(i*6*pi/180)+300; y2=(200-l)*sin(i*6*pi

3、/180)+240; line(x1,y1,x2,y2); main() int x,y; int gd=VGA,gm=2; unsigned char h,m,s; struct time t1; initgraph(&gd,&gm,d:tc); init(); setwritemode(1); gettime(t); h=t0.ti_hour; m=t0.ti_min; s=t0.ti_sec; setcolor(7); d(150,h,30); setcolor(14); d(170,m,6); setcolor(4); d(190,s,6); while(!kbhit() while(

4、t0.ti_sec=s) gettime(t); sound(400); delay(70); sound(200); delay(30); nosound(); setcolor(4); d(190,s,6); s=t0.ti_sec; d(190,s,6); if (t0.ti_min!=m) setcolor(14); d(170,m,6); m=t0.ti_min; d(170,m,6); if (t0.ti_hour!=h) setcolor(7); d(150,h,30); h=t0.ti_hour; d(150,h,30); sound(1000); delay(240); no

5、sound(); delay(140); sound(2000); delay(240); nosound(); getch(); closegraph(); 1程序中存在问题时针每小时跳动一次,精确度不足,造成时间显示上的错误。2改进办法增加显示时间的精确度,由每60秒分针动一次改为3秒动一次,时针由每60分钟跳一次改为每3分钟跳一次。3改进后的程序#include#include#include#define pi 3.1415926#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;#define Y(a,b,c) y=a*sin(b*c*pi/1

6、80-pi/2)+240;#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)void init()int i,l,x1,x2,y1,y2; setbkcolor(1); circle(300,240,200); circle(300,240,205); circle(300,240,5); for(i=0;i60;i+) if(i%5=0) l=15; else l=5; x1=200*cos(i*6*pi/180)+300; y1=200*sin(i*6*pi/180)+240; x2=(200-l)*cos(i*6*pi/180)+30

7、0; y2=(200-l)*sin(i*6*pi/180)+240; line(x1,y1,x2,y2); main() int x,y; int gd=VGA,gm=2; unsigned char s; float m,h; struct time t1; initgraph(&gd,&gm,F:TC2.0); init(); setwritemode(1); gettime(t); h=t0.ti_hour; m=t0.ti_min; s=t0.ti_sec; setcolor(7); d(150,h,30); setcolor(14); d(170,m,6); setcolor(4);

8、 d(190,s, 6); while(!kbhit() while(t0.ti_sec=s) gettime(t); sound(400); delay(70); sound(200); delay(30); nosound(); setcolor(4); d(190,s,6); s=t0.ti_sec; d(190,s,6); setcolor(14); d(170,m,6); m=t0.ti_min+(t0.ti_sec/3)*0.05; d(170,m,6); setcolor(7); d(150,h,30); h=t0.ti_hour+(t0.ti_min/3)*0.05; d(15

9、0,h,30); sound(1000); delay(240); nosound(); delay(140); sound(2000); delay(240); nosound(); getch(); closegraph(); 题目二:学生成绩管理系统1程序流程图调用保存数据到文件函数调用删除记录函数开始输出欢迎信息调用初始化函数调用菜单选择函数输入选项序号nn=1n=7n=9n=8n=6n=5n=4n=3n=2调用输入函数调用显示全部记录函数调用查找记录函数调用排序函数调用插入记录函数函数调用从文件读数据函数结束是是是是是是是是是否否否否否否否否2函数的功能及调用关系 .自定义函数功能:

10、 menu_select():菜单选择; STUDENT *create():学生信息输入,并求均值等; print(STUDENT *head):显示学生信息 search(STUDENT *head):查找学生信息 STUDENT *delete(STUDENT *head):删除指定学生信息; STUDENT *sort(STUDENT *head):改变学生信息排列顺序; STUDENT *insert(STUDENT *head,STUDENT *new):插入学生信息; save(STUDENT *head): 创建文件保存学生信息; STUDENT *load(): 读取已有的学

11、生信息文件; .函数调用关系Main函数STUDENT *init() 1 2调用初始化函数STUDENT *init() 3调用STUDENT *create()menu_select()8STUDENT *create() 7调用STUDENT *load() 9 4调用print(STUDENT *head) 5 6 28 29STUDENT *load() 10 30 11print(STUDENT *head)调用save(STUDENT *head)调用menu_select() 12 25调用search(STUDENT *head) 13 26save(STUDENT *hea

12、d) 27 15 24 14STUDENT *insert(STUDENT *head,STUDENT *new)调用STUDENT *sort(STUDENT *head调用STUDENT *delete(STUDENT *head)search(STUDENT *head) 16 19 18STUDENT *insert(STUDENT *head,STUDENT *new) 22 2317STUDENT *delete(STUDENT *head) 20STUDENT *sort(STUDENT *head 213程序代码#include #include#include #includ

13、e#include #include#include#define LEN sizeof(STUDENT)typedef struct stuchar num6; char name5; int score3; int sum; float average; int order; struct stu *next;STUDENT;STUDENT *init();int menu_select();STUDENT *create();void print(STUDENT *head);void search(STUDENT *head);STUDENT *delete(STUDENT *head

14、);STUDENT *sort(STUDENT *head);STUDENT *insert(STUDENT *head,STUDENT *new);void save(STUDENT *head);STUDENT *load();main()STUDENT *head,new; head=init(); clrscr(); for(;) switch(menu_select() case 1: clrscr();head=create();break; case 2: clrscr();print(head);break; case 3: clrscr();search(head);brea

15、k; case 4: clrscr();head=delete(head);break; case 5: clrscr();head=sort(head);break; case 6: clrscr();head=insert(head,&new);break; case 7: clrscr();save(head);break; case 8: clrscr();head=load(); break; case 9: exit(0); STUDENT *init() return NULL; menu_select()int n; clrscr();printf(*n); printf(tt

16、 Welcome ton); printf(ntt The student score manage systemn); printf(*MENU*n); printf(ttt1. Enter the recordn); printf(ttt2. Print the recordn); printf(ttt3. Search record on namen); printf(ttt4. Delete a recordn); printf(ttt5. Sort to make new a filen); printf(ttt6. Insert record to listn); printf(t

17、tt7. Save the filen); printf(ttt8. Load the filen); printf(ttt9. Quitn); printf(ntt Made by Cai zijun.n); printf(*n); do printf(ntttEnter your choice(19):); scanf(%d,&n); while(n9); return(n);STUDENT *create()int i,s; STUDENT *head=NULL,*p; clrscr(); for(;) p=(STUDENT *)malloc(LEN);if(!p) printf(nOu

18、t of memory.); return (head); printf(Enter the num(0:list end):); scanf(%s,p-num);if(p-num0=0) break; printf(Enter the name:); scanf(%s,p-name);printf(Please enter the %d scoresn,3);s=0; for(i=0;iscorei); if(p-scoreiscorei100) printf(Data error,please enter again.n); while(p-scoreiscorei100); s=s+p-

19、scorei; p-sum=s; p-average=(float)s/3; p-order=0; p-next=head; head=p; return(head);void print(STUDENT *head)int i=0; STUDENT *p; clrscr(); p=head; printf(n*STUDENT*n); printf(-n); printf(| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |n); printf(-n); while(p!=NULL) i+; printf(| %3d | %4s

20、| %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|n, i, p-num,p-name,p-score0,p-score1,p-score2,p-sum,p-average,p-order); p=p-next; printf(-n); printf(*END*n); getch();void search(STUDENT *head)STUDENT *p; char s5; clrscr(); printf(Please enter name for searching.n); scanf(%s,s); p=head; while(strcmp(p-

21、name,s) & p != NULL) p=p-next; if(p!=NULL) printf(n*FOUND*n); printf(-n); printf(| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |n); printf(-n); printf(| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|n, p-num,p-name,p-score0,p-score1,p-score2,p-sum,p-average,p-order); printf(-n); printf(*END*

22、n); else printf(nThere is no num %s student on the list.n,s);STUDENT *delete(STUDENT *head) int n; STUDENT *p1,*p2; char c,s6; clrscr(); printf(Please enter the deleted num: ); scanf(%s,s); p1=p2=head; while(strcmp(p1-num,s) & p1 != NULL) p2=p1;p1=p1-next; if(strcmp(p1-num,s)=0) printf(*FOUND*n); pr

23、intf(-n); printf(| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |n); printf(-n); printf(| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|n, p1-num,p1-name,p1-score0,p1-score1,p1-score2,p1-sum,p1-average,p1-order); printf(-n); printf(*END*n);printf(Are you sure to delete the student Y/N ?); for

24、(;) scanf(%c,&c); if(c=n|c=N) break; if(c=y|c=Y) if(p1=head) head=p1-next; else p2-next=p1-next; n=n-1; printf(nNum %s student have been deleted.n,s); printf(Dont forget to save.n);break; elseprintf(nThere is no num %s student on the list.n,s); return(head);STUDENT *sort(STUDENT *head)int i=0; STUDE

25、NT *p1,*p2,*t,*temp; temp=head-next; head-next=NULL; while(temp!=NULL) t=temp;temp=temp-next; p1=head; p2=head;while(t-averageaverage&p1!=NULL) p2=p1; p1=p1-next; if(p1=p2) t-next=p1; head=t; else t-next=p1; p2-next=t; p1=head; while(p1!=NULL) i+;p1-order=i;p1=p1-next; printf(Sorting is sucessful.n)

26、; return (head);STUDENT *insert(STUDENT *head,STUDENT *new)STUDENT *p0,*p1,*p2; int n,sum1,i; p1=head; p0=new; printf(nPlease enter a new record.n); printf(Enter the num:); scanf(%s,new-num); printf(Enter the name:); scanf(%s,new-name); printf(Please enter the %d scores.n,3); sum1=0; for(i=0;iscorei

27、); if(new-scorei100|new-scoreiscorei100|new-scoreiscorei; new-sum=sum1; new-average=(float)sum1/3; new-order=0; if(head=NULL) head=p0;p0-next=NULL; else while(p0-averageaverage)&(p1-next!=NULL) p2=p1; p1=p1-next; if(p0-average=p1-average) if(head=p1)head=p0; else p2-next=p0; p0-next=p1; else p1-next

28、=p0;p0-next=NULL; n=n+1; head=sort(head); printf(nStudent %s have been inserted.n,new-name); printf(Dont forget to save the new file.n); return(head);void save(STUDENT *head)FILE *fp; STUDENT *p; char outfile10; printf(Enter outfile name,for example c:scoren); scanf(%s,outfile); if(fp=fopen(outfile,

29、wb)=NULL) printf(Cannot open the filen);return; printf(nSaving the file.n); p=head; while(p!=NULL) fwrite(p,LEN,1,fp);p=p-next; fclose(fp); printf(Save completed!n); getch();STUDENT *load()STUDENT *p1,*p2,*head=NULL; FILE *fp; char infile10; printf(Enter infile name,for example c:scoren); scanf(%s,infile); if(fp=fopen(infile,rb)=NULL) printf(Can not open the file.n); return(head); printf(nLoad completed!n); getch(); p1=(STUDENT *)malloc(LEN); if(!p1) printf(Out of memory!n); return(head); head=p1; while(!feof(fp) if(fread(p1,LEN,1,fp)!=1) break; p1-next=(STUDENT *)malloc(LEN); if(!p1-next)

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

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号