C语言程序设计基础课程设计报告.doc_第1页
C语言程序设计基础课程设计报告.doc_第2页
C语言程序设计基础课程设计报告.doc_第3页
C语言程序设计基础课程设计报告.doc_第4页
C语言程序设计基础课程设计报告.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

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

文档简介

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); r

温馨提示

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

评论

0/150

提交评论