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

上传人:仙*** 文档编号:33671567 上传时间:2021-10-18 格式:DOC 页数:17 大小:105KB
返回 下载 相关 举报
C语言程序设计基础课程设计报告_第1页
第1页 / 共17页
C语言程序设计基础课程设计报告_第2页
第2页 / 共17页
C语言程序设计基础课程设计报告_第3页
第3页 / 共17页
点击查看更多>>
资源描述
C语言程序设计基础课 程 设 计 报 告班 级: 计算 07-2 班 学 号: 0706010202 姓 名: 蔡子俊 成 绩: 电子与信息工程学院计算机科学与技术系C语言程序设计基础课程设计报告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,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/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(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); nosound(); 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/180-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)+300; 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); 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(150,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函数的功能及调用关系 .自定义函数功能: 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(): 读取已有的学生信息文件; .函数调用关系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 *head) 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 #include#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);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);break; 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 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(ttt7. 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(nOut 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-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 | %-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-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*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); 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, 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(;) 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; STUDENT *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); 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); 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=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,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) printf(Out of memory!n); return (head); p2=p1; p1=p1-next; p2-next=NULL; fclose(fp); printf(You have success to read data from the file!n); return (head); 16
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档


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

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


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