C語言課程設(shè)計(jì)—學(xué)生成績管理系統(tǒng)源代碼吉林大學(xué)1_第1頁
C語言課程設(shè)計(jì)—學(xué)生成績管理系統(tǒng)源代碼吉林大學(xué)1_第2頁
C語言課程設(shè)計(jì)—學(xué)生成績管理系統(tǒng)源代碼吉林大學(xué)1_第3頁
C語言課程設(shè)計(jì)—學(xué)生成績管理系統(tǒng)源代碼吉林大學(xué)1_第4頁
C語言課程設(shè)計(jì)—學(xué)生成績管理系統(tǒng)源代碼吉林大學(xué)1_第5頁
已閱讀5頁,還剩8頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、#in clude<stdio.h>#in clude<stri ng.h>#in clude<stdlib.h>#in clude<time.h>typedef struct student /* 定義結(jié)構(gòu)體 */char IDNumber16;/* 學(xué)號(hào) */char FamilyName16; /* 姓*/ char Give nN ame16; /* 名 */int sex; /*性別(0代表 女”,1代表 男”)*/int BirthYear; /* 出生年 */int BirthM on th; /* 出生月 */int BirthD

2、ay; /* 出生日 */ float score4; /* 成績 */ float sum; /* 總分 */ float average; /* 平均分 */stu;typ edef struct Lnodestude nt data;Lnode *n ext;st, *li nklist;/*/struct tm* ptm;float Sumstu(li nklist L);float Averstu(li nklist L);/*計(jì)算總分*/float Sumstu(li nklist L)li nklist s;s=L; int i; s->data.sum=0;for(i=0

3、;i<=4;i+) s->data.sum+=s->data.scorei;return (s->data.sum);float Averstu(li nklist L)lin klist q;q=L;Sumstu(q);q->data.average=q->data.sum/4; retur n (q->data.average);void TimeNow()/*獲取系統(tǒng)時(shí)間*/Istruct long inttm* ptm;ts;y,m,d,h, n,s;ts =time(NULL);ptm =localtime(&ts);y =p tm-

4、> tm_year+1900;年m =p tm-> tm_ mon +1;/月d =ptm-> tm_mday;/ 日h =p tm-> tm_hour;/時(shí)n =ptm-> tm_mi n;/分s =p tm-> tm_sec;/秒菜單函數(shù)*/int Men u() /*int n;printf("tttnnnn歡迎使用學(xué)生成績管理系統(tǒng)nnttt按任意鍵進(jìn)入系統(tǒng)!");system( "p ause");prin tf("*n");printf("nttt學(xué)生成績管理系統(tǒng)ntttt制作人

5、陳光林(52101407)n");printf(”菜單(Menu)n");prin tf("nt 1. En ter list printf(” printf(” printf(” printf(” printf(” printf(”t 2. Delete a record from listt 3. Print listt 4. Search record on n amet 5. Save the filet 6. Load the file輸入記錄n"); 刪除記錄n");顯示所有記錄n");按照姓名查找記錄保存記錄到文件中從文

6、件中讀入記錄n “); n “); rr);t 7. Compute the scoreprintf(” t 8. Query by classprin tf("t 9. In sert record to listprintf(” t 0. Quitprintf(”計(jì)算所有學(xué)生的總分和均分n");按班級(jí)查詢顯示學(xué)生總分n");插入記錄到表中n");退出系統(tǒng)n"); n");system("cls");prin tf("*n");doprin tf("nttt請(qǐng)選擇你需要的操作(09)

7、:");scan f("%d", &n);while(n<1|n>5); /*如果選擇項(xiàng)不在1 9之間則重輸*/return(n);/*返回選擇項(xiàng)*/*/linklist initlist(void)/* 建立一個(gè)空鏈表 */lin klist L=(li nklist)malloc(sizeof(st);L-> next=NULL;return NULL;/*建立學(xué)生信息鏈表*/st *creastlist(li nklist L)int i;float s;lin klist p;for(;)/*開辟新的節(jié)點(diǎn)*/p=(l in kli

8、st)malloc(sizeof(st);if仲)prin tf("n Out of memory."); return (L);printf("請(qǐng)輸入學(xué)生學(xué)號(hào)");scan f("%s", p->data.lDNumber);if(p->data.lDNumberO='O') break;printf("請(qǐng)輸入姓:");sca nf("%s", p->data.FamilyName);printf("請(qǐng)輸入名:");scan f("

9、;%s", p->data.Give nName);printf("請(qǐng)輸入性別(0女/1男):");scan f("%d", &p->data.sex);printf("請(qǐng)輸入生日:");scan f("%d %d %d",&p->data.BirthYear, &p->data.BirthMo nth,&p->data.BirthDay);printf("請(qǐng)輸入成績n",4);s=0;for(i=0;i<4;i+)d

10、oprin tf("score%d:",i+1);scan f("%f", &p->data.scorei);if(p->data.scorei<0 | p->data.scorei>100) printf(” Data error, pl ease en ter aga in.n");while( p->data.scorei<0 | p->data.scorei>100); s=s+p->data.scorei;p->data.sum=s;p->data.ave

11、rage=s/4;p->n ext=L;L=p; return(L);/*/* void creastlist(l in klist L)st *p;lin klist head=NULL;p=(l in klist)malloc(sizeof(st);P=L;for(;)printf(”請(qǐng)輸入學(xué)生學(xué)號(hào):n");scan f("%s", p->data.lDNumber);printf(”請(qǐng)依次輸入學(xué)生姓名:n");sca nf("%s%s", p->data.FamilyName ,p->data.Give

12、nName);printf(”請(qǐng)輸入出生年月曰:n");scan f("%d%d%d", p->data.BirthYear, p->data.BirthMo nth, p->data.BirthDay);TimeNow();if(p->data.BirthYear>=ptm-> tm_year+1900) printf(”錯(cuò)誤!學(xué)生年齡不能為負(fù)值! 請(qǐng)重新輸入! ");co nti nue;else if(p->data.BirthMo nth>=ptm-> tm_mo n+1) printf(”錯(cuò)

13、誤!學(xué)生年齡不能為負(fù)值!請(qǐng)重新輸入!");co nti nu e;else if(p->data.BirthDay>=ptm-> tm_mday) printf(”錯(cuò)誤!學(xué)生年齡不能為負(fù)值!請(qǐng)重新輸入!");co nti nu e;elseprintf("請(qǐng)輸入性別(0代表女,1代表男:n");scan f("%d", p->data.sex);if(p->data.sex!=0|p->data.sex!=1) printf(" 錯(cuò)誤!學(xué)生年齡不能為負(fù) 值!請(qǐng)重新輸入!");co

14、 nti nue;elseprintf(”請(qǐng)分別輸入外語、高數(shù)、C語言、馬哲四門成績:n");sca nf("%f%f%f%f", &p->data.score0,&p->data.score1, &p->data.score2,&p->data.score3); p->n ext=head;head=p;*/*/*輸出所有學(xué)生的信息void prin t(l in klist head) lin klist p;p=head;prin tf("*Hprintf("|學(xué)號(hào)I姓名 性別

15、出生年 月 日外語C語言 高數(shù) 馬哲總分I 平均分|");printf("-一Sumstu( P);Averstu( p);while( p!=NULL)prin tf("%s%s%s%d%d%d%f%f%f%f%f%f", p->data.lDNumber, p->data.FamilyName, p->data.Give nN ame,p->data.sex ,p->data.BirthYear, p->data.BirthM on th, p->data.BirthDay,p->data.score0

16、, p->data.score1, p->data.score2, p->data.score3, p->data.su m,p->data.average)prin tf("n"); p=p->n ext;prin tf("n");/*/插入新的結(jié)點(diǎn)*/void in sert(li nklist L)lin klist s,p=L;stu e;/頭插法s=(li nklist)malloc(sizeof(st);s->data=e;s->n ext=p->n ext;p->n ext=s;/

17、*/void search(l in klist L)int flag=1;char famil yn ame16;li nklist p;printf("請(qǐng)輸入要查詢的學(xué)生姓名:n");sca nf("%s",famil yn ame);p=L->n ext;while( p!=NULL)if(strc mp (famil yn ame, p->data.FamilyName)=0)system("cls");Sumstu( p);Averstu( p);prin tf("*Hprintf("|學(xué)號(hào)I

18、姓名I性別出生年 月 日外語C語言高數(shù) 馬哲總分平均分|");prin tf("prin tf("%s%s%s%d%d%d%f%f%f%f%f%f", p->data.lDNumber, p->data.FamilyName, p->data.Gi venN ame,p->data.sex ,p->data.BirthYear, p->data.BirthM on th, p->data.BirthDay,p->data.score0, p->data.score1, p->data.score

19、2, p->data.score3, p->data.sum, p->data.average);prin tf("n");flag=0; break; elsep=p->n ext;if(flag)printf(”沒有該學(xué)生信息或輸入錯(cuò)誤”);Men u();/* */void Delete(li nklist L)lin klist p,q;char num16;in t label=1;printf("請(qǐng)輸入要?jiǎng)h除的學(xué)生學(xué)號(hào):n"); sca nf("%s", num);p=L->n ext;q=L

20、;doif(strcm p(num,p->data .1 DNumber)=0)system("cls");printf("t發(fā)現(xiàn)要?jiǎng)h除的學(xué)生信息,確認(rèn)刪除嗎?n");printf("tt 確認(rèn)(丫) 取消(N) ”); getchar();if('y'll'Y')q->n ext =p->n ext;delete p;printf(”刪除成功!");label=0;elseexit(0);elseq=q->n ext;p=q->n ext; while(q-> ne

21、xt!=NULL);if(label)printf("輸入錯(cuò)誤或者信息不存在!");/* */void P aixu(li nklist L)lin klist p;float s1=90,s2=80,s3=70,s4=60;P=L;int i;for(i=0;i<=4;i+)prin tf("*");printf(”第%d科90分以上的學(xué)生:",i);if(p->data.scorei>=s1) prin tf("%s%s%s%f", p->data.lDNumber, p->data.Fam

22、ilyName, p->data.Give nN ame, p->data.scorei);elsep=p->n ext;if(s2<=p->data.scorei<s1)prin tf("%s%s%s%f", p->data.lDNumber, p->data.FamilyName ,p->data.Give nName, p->data.scorei);elsep=p->n ext;if(s3<=p->data.scorei<s2)prin tf("%s%s%s%f"

23、, p->data.lDNumber, p->data.FamilyName ,p->data.Give nName, p->data.scorei);elsep=p->n ext;if(s4 <=p->data.scorei<s3)prin tf("%s%s%s%f", p->data.lDNumber, p->data.FamilyName ,p->data.Give nName, p->data.scorei);elsep=p->n ext;if(p->data.scorei<s

24、4)prin tf("%s%s%s%f", p->data.lDNumber, p->data.FamilyName ,p->data.Give nName, p->data.scorei);elsep=p->n ext;/*/此處假設(shè)學(xué)號(hào)形式為 20101407/*void Query(li nklist L)lin klist p;p=L;char classs2;float sumclass;printf("請(qǐng)輸入您想查詢的班級(jí):n");sca nf("%s",classs);dosumclass=

25、p->data.score0+p->data.score1+p->data.score2+p->data.score3; prin tf("%s%f", p->data.lDNumber, p->data.sum);while(strc mp (classs1, p->data.lDNumber5)=0)&&(strc mp (classs2, p->data.lDNu mber6)=0);/* */void Com pu te Project(li nklist L)li nklist p;float sum

26、all4,averall4;float Su=0,Av=0;/sumall4=0,0,0,0;averall4=0,0,0,0;int i,m=0;p=L;for(i=0;i<=4;i+)for(p=L;p->n ext!=NULL ;p=p->n ext)m+;sumalli+=p->data.scorei;averalli=sumalli/4;printf(” 第 %d 科的平均成績是:n”,averalli);Su+=averalli;Av=Su/4;printf(”總的平均成績是:%fn",Av);/*/void compu te(l in klist

27、 L) lin klist p;P=L;Sumstu( p);Averstu( p);doprintf(” 學(xué)號(hào):%sn",p->data.lDNumber);printf(” 總分:%fn 平均分:fn",p->data.sum,p->data.average); p=p->n ext;while( p-> next!=NULL);/*/插入新的結(jié)點(diǎn)*/ void in sert(l in klist L, stu e)lin klist s,p=L;printf(”請(qǐng)輸入要插入的學(xué)生信息:n");sca nf("%s%s

28、%s%d%d%d%f%f%f%f%f%f", p->data.lDNumber, p->data.FamilyName, p->data.Gi venN ame,p->data.sex ,p->data.BirthYear, p->data.BirthM on th, p->data.BirthDay,p->data.score0, p->data.score1, p->data.score2, p->data.score3, p->data.sum, p->data.average);s=(li nkli

29、st)malloc(sizeof(st);/頭插法s->data=e;s->n ext=p->n ext;p->n ext=s;/*/void save(l in klist L)FILE *fp;linklist p;/*定義移動(dòng)指針*/char outfile20;scan f("%s",outfile);if(fp=fopen(outfile,"w")=NULL) /*為輸出打開一個(gè)二進(jìn)制文件,為只寫方式*/prin tf("Ca nnot open the filen"); return; /*若打不開

30、則返回菜單*/p=L; /*移動(dòng)指針從頭指針開始*/while(p!=NULL) /* 女0 p 不為空 */fwrite(p,sizeof(st),1,fp); /* 寫入一條記錄 */ p=p->next; /* 指針后移 */fclose(fp); /* 關(guān)閉文件 */ prin tf("Save the file successfully!n");/*從文件讀數(shù)據(jù)函數(shù)*/st *Load(li nklist L)lin klist p1, p2,head=NULL; /* 定義記錄指針變量 */FILE *fp; /* 定義指向文件的指針*/char in file20;sca

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論