C語言程序設(shè)計基礎(chǔ)課程設(shè)計報告.doc_第1頁
C語言程序設(shè)計基礎(chǔ)課程設(shè)計報告.doc_第2頁
C語言程序設(shè)計基礎(chǔ)課程設(shè)計報告.doc_第3頁
C語言程序設(shè)計基礎(chǔ)課程設(shè)計報告.doc_第4頁
C語言程序設(shè)計基礎(chǔ)課程設(shè)計報告.doc_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

c語言程序設(shè)計基礎(chǔ)課 程 設(shè) 計 報 告班 級: 計算 07-2 班 學 號: 0706010202 姓 名: 蔡子俊 成 績: 電子與信息工程學院計算機科學與技術(shù)系c語言程序設(shè)計基礎(chǔ)課程設(shè)計報告c語言程序設(shè)計基礎(chǔ)課程設(shè)計報告題目一:修改時鐘程序閱讀下面的時鐘程序及觀察運行結(jié)果寫出程序中存在問題及改進辦法,寫出改進后的程序。時鐘程序:#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(); 題目二:學生成績管理系統(tǒng)1程序流程圖調(diào)用保存數(shù)據(jù)到文件函數(shù)調(diào)用刪除記錄函數(shù)開始輸出歡迎信息調(diào)用初始化函數(shù)調(diào)用菜單選擇函數(shù)輸入選項序號nn=1n=7n=9n=8n=6n=5n=4n=3n=2調(diào)用輸入函數(shù)調(diào)用顯示全部記錄函數(shù)調(diào)用查找記錄函數(shù)調(diào)用排序函數(shù)調(diào)用插入記錄函數(shù)函數(shù)調(diào)用從文件讀數(shù)據(jù)函數(shù)結(jié)束是是是是是是是是是否否否否否否否否2函數(shù)的功能及調(diào)用關(guān)系 .自定義函數(shù)功能: 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): 創(chuàng)建文件保存學生信息; student *load(): 讀取已有的學生信息文件; .函數(shù)調(diào)用關(guān)系main函數(shù)student *init() 1 2調(diào)用初始化函數(shù)student *init() 3調(diào)用student *create()menu_select()8student *create() 7調(diào)用student *load() 9 4調(diào)用print(student *head) 5 6 28 29student *load() 10 30 11print(student *head)調(diào)用save(student *head)調(diào)用menu_select() 12 25調(diào)用search(student *head) 13 26save(student *head) 27 15 24 14student *insert(student *head,student *new)調(diào)用student *sort(student *head調(diào)用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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論