




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、一. 課程設計目的和要求(一). 課程設計目的本課程設計是重要的實踐性環(huán)節(jié)之一,是在學生學習完程序設計語言(C)課程后進行的一次全面的綜合練習。本課程設計的目的和任務:1. 鞏固和加深學生對C語言課程的基本知識的理解和掌握2. 掌握C語言編程和程序調試的基本技能3. 利用C語言進行基本的軟件設計4. 掌握書寫程序設計說明文檔的能力5. 提高運用C語言解決實際問題的能力(二). 課程設計要求1. 分析課程設計題目的要求2. 寫出詳細設計說明3. 編寫程序代碼,調試程序使其能正確運行4. 設計完成的軟件要便于操作和使用4. 設計完成后提交課程設計報告二. 課程設計任務內容設計一個學生成績管理系統(tǒng)。
2、系統(tǒng)功能:1)具備對學生基礎數(shù)據(jù)的維護功能(添加、刪除、修改)2)具備對課程基礎數(shù)據(jù)的維護功能(添加、刪除、修改)3)具備對學生成績數(shù)據(jù)的維護功能(添加、刪除、修改)4) 具備對成績的查詢功能(按學號、姓名、或課程名查詢成績,排序等 )5) 具備對成績的統(tǒng)計功能(最高分,最低分,平均分,及格率等)6) 采用菜單界面三. 總體設計說明1 工程設計說明 (工程中有哪些文件組成,各有什么作用) 該工程文件中有student.h, studentmain.c, student.c, course.c, scgrade.c query.c #c。student.h是頭文件,主要存放一些其他函
3、數(shù)共用的東西,比如結構體之類的。Studentmain.c存放main函數(shù)主菜單程序。其他幾個是存放的實現(xiàn)各個功能的函數(shù)。另外,還有STUDENT.DAT,COURSE.DAT,GRADE.DAT三個文件,主要存放學生,課程,成績的信息的。還有一個TEMP.DAT文件,用于暫時存放數(shù)據(jù)。2 菜單結構設計 (列出各級菜單)3 數(shù)據(jù)結構設計 (三個數(shù)據(jù)文件用到的的結構定義)學生結構體:struct student long sno; char sname20; char sclass20;課程結構體:struct course int cno; char cname30;成績結構體:struct
4、scgrade long sno; int cno; float grade;四. 詳細設計說明1 學生數(shù)據(jù)維護子系統(tǒng)設計說明 (每個功能模塊的設計思路,哪些功能是自己增強的, 加注釋的源代碼)#include<stdio.h>#include"STUDENT.H"/該部分為學生主菜單程序,分別調用添加,修改,刪除三個函數(shù)。void studentmenu() void addstudent(); void modistudent(); void deletestudent(); char a; while(1) puts("n"); put
5、s(" 系 統(tǒng) 主 菜 單"); puts(" 1: 學 生 數(shù) 據(jù) 添 加"); puts(" 2: 學 生 數(shù) 據(jù) 修 改"); puts(" 3: 學 生 數(shù) 據(jù) 刪 除"); puts(" 0: 退 出 系 統(tǒng)"); printf("請輸入數(shù)字選擇: "); a=getche(); switch(a) case '1': addstudent(); break; case '2': modistudent(); break; case
6、'3': deletestudent(); break; case '0': system("cls"); return; default: return; /添加數(shù)據(jù)void addstudent() FILE *fp;struct student s; struct student sw;char ch;int flag=0;/打開文件。 fp=fopen("d:STUDENTSTUDENT.dat","ab+"); if(!fp) printf("Create file error!n&
7、quot;); return; dodo /*輸入一條學生信息,另外,增加了檢驗數(shù)據(jù)是否重復的功能*/printf("nEnter a student number name class:");fflush(stdin);scanf("%ld%s%s",&s.sno,s.sname,s.sclass);rewind(fp);while(!feof(fp) fread(&sw,sizeof(sw),1,fp);if(sw.sno=s.sno) flag=1;printf("數(shù)據(jù)輸入重復,請重新輸入!");break;wh
8、ile(flag);fwrite(&s,sizeof(s),1,fp);/ 提示是否繼續(xù)輸入。printf("Input another student? y/n");ch=getche();while(ch='y');fclose(fp);/修改數(shù)據(jù)void modistudent() FILE *fp;char ch;struct student s, modis;int found=0;fp=fopen("D:STUDENTSTUDENT.dat","rb+");if(!fp) printf("
9、Create file error!n"); return; /*顯示文件中的所有學生信息*/fread(&s,sizeof(s),1,fp);PRINT1;while(!feof(fp) PRINT2; PRINT1; fread(&s,sizeof(s),1,fp);/*提示輸入要修改的學生號, 存入modis.sno*/printf("please enter the no of the modify");scanf("%ld",&modis.sno);/*找到要修改的學生并顯示 */rewind(fp);whil
10、e( 1 ) fread(&s,sizeof(s),1,fp); if(feof(fp) break; if(s.sno=modis.sno) found=1; break; if(!found) printf("未找到你要找的數(shù)據(jù)!"); return; else PRINT2;printf("n你確實要修改該學生的其他信息嗎?(Y/N)");ch=getche();if(ch='Y'|ch='y') /*提示輸入要修改的學生姓名, 存入modis.sname*/printf("nplease ente
11、r the name of the modifyn");scanf("%s",modis.sname);printf("nplease enter the class of the modifyn");scanf("%s",modis.sclass);fseek(fp,-(int)sizeof(s),SEEK_CUR); /*從當前位置向前移動一個s的長度*/*將modis寫到文件(覆蓋原數(shù)據(jù)) */ fwrite(&modis,sizeof(s),1,fp);fclose(fp); /刪除數(shù)據(jù)。void delet
12、estudent() FILE *fp,*fp1;char ch;int found=0,num;struct student s;fp=fopen("D:studentstudent.dat","rb");if(!fp) printf("Create file error!");return;/*顯示文件中的所有學生信息*/fread(&s,sizeof(s),1,fp);PRINT1;while(!feof(fp) PRINT2;PRINT1;fread(&s,sizeof(s),1,fp);printf(&quo
13、t;please enter the no of the delete");scanf("%d",&num); /找到要修改的學生信息,顯示!rewind(fp);while(1) fread(&s,sizeof(s),1,fp);if(feof(fp) break;if(s.sno=num) found=1;break;if(!found) printf("未找到你要找的數(shù)據(jù)!");return;elsePRINT2;printf("n你確實要刪除該學生的信息嗎?(Y/N)");ch=getche();/將
14、刪除后的信息復制到temp文件中。if(ch='Y'|ch='y') fp1=fopen("D:studenttemp.dat","wb");rewind(fp);while(1) fread(&s,sizeof(s),1,fp);if(feof(fp) break;if(s.sno!=num) fwrite(&s,sizeof(s),1,fp1);fclose(fp1);fclose(fp);將temp文件的信息再重新覆蓋掉原來的student文件。fp=fopen("D:studentstud
15、ent.dat","wb");fp1=fopen("D:studenttemp.dat","rb");while(1) fread(&s,sizeof(s),1,fp1);if(feof(fp1) break;fwrite(&s,sizeof(s),1,fp);fclose(fp1);fclose(fp); 2 課程數(shù)據(jù)維護子系統(tǒng)設計說明#include<stdio.h>#include"STUDENT.H"void coursemenu() void addcourse();
16、 void modicourse(); void deletecourse(); char a; while(1) puts("n"); puts(" 系 統(tǒng) 主 菜 單"); puts(" 1: 課 程 數(shù) 據(jù) 添 加"); puts(" 2: 課 程 數(shù) 據(jù) 修 改"); puts(" 3: 課 程 數(shù) 據(jù) 刪 除"); puts(" 0: 退 出 系 統(tǒng)"); printf("請輸入數(shù)字選擇: "); a=getche(); switch(a) ca
17、se '1': addcourse(); break; case '2': modicourse(); break; case '3': deletecourse(); break; case '0': system("cls"); return; default: return; /添加數(shù)據(jù)。void addcourse() FILE *fp;struct course c,cw; char ch;int flag=0; fp=fopen("d:STUDENTCOURSE.dat",&qu
18、ot;ab+"); if(!fp) printf("Create file error!n"); return; /輸入一條課程信息,提示是否重新輸入,另外增加檢驗數(shù)據(jù)是否重復的功能。dodoprintf("nEnter a course number name:");fflush(stdin);scanf("%d%s",&o,ame);rewind(fp);while(!feof(fp) fread(&cw,sizeof(cw),1,fp);if(o=o) flag=1;printf("數(shù)據(jù)輸入重
19、復,請重新輸入!");break;while(flag);fwrite(&c,sizeof(c),1,fp);printf("Input another course? y/n");ch=getche();while(ch='y');fclose(fp);/修改數(shù)據(jù)void modicourse() FILE *fp;char ch;struct course c, modis;int found=0;fp=fopen("D:STUDENTCOURSE.dat","rb+");if(!fp) prin
20、tf("Create file error!n"); return; /*顯示文件中的所有課程信息*/fread(&c,sizeof(c),1,fp);PRINT1;while(!feof(fp) PRINT3; PRINT1; fread(&c,sizeof(c),1,fp);/*提示輸入要修改的課程號, 存入modis.sno*/printf("please enter the no of the modify");scanf("%d",&o);/*找到要修改的課程并顯示 */rewind(fp);whil
21、e( 1 ) fread(&c,sizeof(c),1,fp); if(feof(fp) break; if(o=o) found=1; break; if(!found) printf("未找到你要找的數(shù)據(jù)!"); return; else PRINT3;printf("n你確實要修改該課程的其他信息嗎?(Y/N)");ch=getche();if(ch='Y'|ch='y') /*提示輸入要修改的課程名, 存入ame*/printf("nplease enter the name of the mod
22、ifyn");scanf("%s",ame);fseek(fp,-sizeof(c),SEEK_CUR); /*從當前位置向前移動一個s的長度*/*將modis寫到文件(覆蓋原數(shù)據(jù)) */fwrite(&modis,sizeof(c),1,fp);fclose(fp); /刪除數(shù)據(jù)。void deletecourse() FILE *fp,*fp1;char ch;int found=0,num;struct course c;fp=fopen("D:studentCOURSE.dat","rb");if(!fp)
23、printf("Create file error!");return;/顯示文件中的信息。fread(&c,sizeof(c),1,fp);PRINT1;while(!feof(fp) PRINT3;PRINT1;fread(&c,sizeof(c),1,fp);/*提示輸入要修改的課程號, 存入num*/printf("please enter the no of the delete");scanf("%d",&num); /*找到要修改的課程并顯示 */rewind(fp);while(1) fread
24、(&c,sizeof(c),1,fp);if(feof(fp) break;if(o=num) found=1;break;if(!found) printf("未找到你要找的數(shù)據(jù)!");return;elsePRINT3;printf("n你確實要刪除該學生的信息嗎?(Y/N)");ch=getche();/將刪除后的文件復制到temp文件中。if(ch='Y'|ch='y') fp1=fopen("D:studenttemp.dat","wb");rewind(fp);w
25、hile(1) fread(&c,sizeof(c),1,fp);if(feof(fp) break;if(o!=num) fwrite(&c,sizeof(c),1,fp1);fclose(fp1);fclose(fp);/將temp文件中的信息覆蓋掉原來course的文件中。fp=fopen("D:studentCOURSE.dat","wb");fp1=fopen("D:studenttemp.dat","rb");while(1) fread(&c,sizeof(c),1,fp1);
26、if(feof(fp1) break;fwrite(&c,sizeof(c),1,fp);fclose(fp1);fclose(fp);3 成績數(shù)據(jù)維護子系統(tǒng)設計說明#include<stdio.h>#include"STUDENT.H"void grademenu() void addgrade(); void modigrade(); void deletegrade(); char a; while(1) puts("n"); puts(" 系 統(tǒng) 主 菜 單"); puts(" 1: 成 績 數(shù)
27、據(jù) 添 加"); puts(" 2: 成 績 數(shù) 據(jù) 修 改"); puts(" 3: 成 績 數(shù) 據(jù) 刪 除"); puts(" 0: 退 出 系 統(tǒng)"); printf("請輸入數(shù)字選擇: "); a=getche(); switch(a) case '1': addgrade(); break; case '2': modigrade(); break; case '3': deletegrade(); break; case '0':
28、 system("cls"); return; default: return; /添加成績!void addgrade() FILE *fp;struct scgrade sc; struct scgrade scw;char ch;int flag=0; fp=fopen("d:STUDENTGRADE.dat","ab+"); if(!fp) printf("Create file error!n"); return; /輸入一條成績信息,提示是否重新輸入,另外增加檢驗數(shù)據(jù)是否重復的功能dodo printf
29、("nEnter a student number ,a course number, grade :");fflush(stdin);scanf("%ld%d%f",&sc.sno,&o,&sc.grade);if(sc.grade<0|sc.grade>100) flag=1;printf("n輸入成績格式不正確,請重新輸入");rewind(fp);while(!feof(fp) fread(&scw,sizeof(scw),1,fp);if(o=o&&scw.sno=
30、sc.sno) flag=1;printf("n數(shù)據(jù)輸入重復,請重新輸入!");break;while(flag);fwrite(&sc,sizeof(sc),1,fp);printf("Input another student's grade? y/n");ch=getche();while(ch='y');fclose(fp);/修改數(shù)據(jù)void modigrade() FILE *fp;char ch;struct scgrade sc, modis;int found=0;fp=fopen("D:STU
31、DENTGRADE.dat","rb+");if(!fp) printf("Create file error!n"); return; /*顯示文件中的所有成績信息*/fread(&sc,sizeof(sc),1,fp);PRINT1;while(!feof(fp) PRINT4; PRINT1; fread(&sc,sizeof(sc),1,fp);/*提示輸入要修改的學生號, 存入modis.sno*/printf("please enter the no of the modify");scanf(&
32、quot;%ld",&modis.sno);/*找到要修改的學生成績并顯示 */rewind(fp);while( 1 ) fread(&sc,sizeof(sc),1,fp); if(feof(fp) break; if(sc.sno=modis.sno) found=1; break; if(!found) printf("未找到你要找的數(shù)據(jù)!"); return; else PRINT4;printf("n你確實要修改該學生的其他信息嗎?(Y/N)");ch=getche();if(ch='Y'|ch=
33、39;y') /*提示輸入要修改的學生課程名和成績, 存入o和modis.grade*/printf("nplease enter the course number of the modifyn");scanf("%d",&o);printf("nplease enter the grade of the modifyn");scanf("%f",&modis.grade);fseek(fp,-(int)sizeof(sc),SEEK_CUR); /*從當前位置向前移動一個sc的長度*/*
34、將modis寫到文件(覆蓋原數(shù)據(jù)) */fwrite(&modis,sizeof(sc),1,fp);fclose(fp); /刪除數(shù)據(jù)void deletegrade() FILE *fp,*fp1;char ch;int found=0,num;struct scgrade sc;fp=fopen("D:studentGRADE.dat","rb");if(!fp) printf("Create file error!");return;/顯示文件中的信息fread(&sc,sizeof(sc),1,fp);PRI
35、NT1;while(!feof(fp) PRINT4;PRINT1;fread(&sc,sizeof(sc),1,fp);/*提示輸入要刪除的學號, 存入num*/printf("please enter the no of the delete");scanf("%d",&num); /*找到要刪除的成績并顯示 */rewind(fp);while(1) fread(&sc,sizeof(sc),1,fp);if(feof(fp) break;if(sc.sno=num) found=1;break;if(!found) pri
36、ntf("未找到你要找的數(shù)據(jù)!");return;elsePRINT4;printf("n你確實要刪除該學生的信息嗎?(Y/N)");ch=getche(); /將刪除后的文件復制到temp文件中。if(ch='Y'|ch='y') fp1=fopen("D:studenttemp.dat","wb");rewind(fp);while(1) fread(&sc,sizeof(sc),1,fp);if(feof(fp) break;if(sc.sno!=num) fwrite
37、(&sc,sizeof(sc),1,fp1);fclose(fp1);fclose(fp);/將temp文件中的信息覆蓋掉原來course的文件中。fp=fopen("D:studentGRADE.dat","wb");fp1=fopen("D:studenttemp.dat","rb");while(1) fread(&sc,sizeof(sc),1,fp1);if(feof(fp1) break;fwrite(&sc,sizeof(sc),1,fp);fclose(fp1);fclose
38、(fp);4 查詢數(shù)據(jù)維護子系統(tǒng)設計說明#include<stdio.h>#include<string.h>#include"STUDENT.H"void query() void snoquery();void snamequery();void cnamequery();void cnamequeryson();void classandcnamequery();char a;while(1) puts("n");puts(" 系 統(tǒng) 主 菜 單");puts(" 1: 按 學 號 查 詢 成
39、績");puts(" 2: 按 姓 名 查 詢 成 績");puts(" 3: 按 課 名 查 詢 成 績");puts(" 4: 按 課 名 查 詢 成 績(子函數(shù))");puts(" 5: 按 班 名 課 名 查 詢 成 績");puts(" 0: 退 出 系 統(tǒng)");printf("請輸入數(shù)字選擇: ");a=getche();switch(a) case '1': snoquery(); break; case '2': sn
40、amequery(); break; case '3': cnamequery(); break; case '4': cnamequeryson(); break; case '5': classandcnamequery(); break; case '0': system("cls"); return; default: return;/按學號查詢void snoquery() FILE *fp;struct scgrade sc; char ch;long no;int found=0;fp=fopen
41、("d:STUDENTGRADE.dat","rb");if(!fp) printf("Create file error!n"); return; /提示要查詢成績的學號。printf("nEnter a student number of the query:");scanf("%ld",&no);/顯示并輸出。while(1) fread(&sc,sizeof(sc),1,fp); if(feof(fp) break; if(sc.sno=no) found=1; PRIN
42、T1;PRINT4;PRINT1;if(!found) printf("未找到你要找的數(shù)據(jù)!");return; fclose(fp);/按姓名查詢void snamequery() FILE *fp;struct student s;struct scgrade sc; char ch,name20;long no;int found=0;fp=fopen("d:STUDENTSTUDENT.dat","rb");if(!fp) printf("Create file error!n"); return; /提示
43、輸入要查詢成績的姓名。printf("nEnter a student name of the query:");scanf("%s",name);/找到該生的的學號。while(1) fread(&s,sizeof(s),1,fp); if(feof(fp) break; if(strcmp(s.sname,name)=0) found=1;no=s.sno;/PRINT1;/PRINT2;/PRINT1;if(!found) printf("未找到你要找的數(shù)據(jù)!");return; fclose(fp);fp=fopen(
44、"d:STUDENTGRADE.dat","rb");found=0;if(!fp) printf("Create file error!n"); return; /找到該生成績,并顯示。while(1) fread(&sc,sizeof(sc),1,fp); if(feof(fp) break; if(sc.sno=no) found=1; PRINT1;PRINT4;PRINT1;if(!found) printf("未找到你要找的數(shù)據(jù)!");return; fclose(fp);/按課名查詢void
45、cnamequery() FILE *fp;struct course c;struct scgrade sc,temp; struct scgrade grades80;char name20;int no,i,j,n=0;int found=0;fp=fopen("d:STUDENTCOURSE.dat","rb");if(!fp) printf("Create file error!n"); return; /提示輸入要查詢的課程名printf("nEnter a course name of the query:&q
46、uot;);scanf("%s",name);/找到該課程的課稱號。while(1) fread(&c,sizeof(c),1,fp); if(feof(fp) break; if(strcmp(ame,name)=0) found=1;no=o;/PRINT1;/PRINT3;/PRINT1;if(!found) printf("未找到你要找的數(shù)據(jù)!");return; fclose(fp);fp=fopen("d:STUDENTGRADE.dat","rb");found=0;if(!fp) print
47、f("Create file error!n"); return; /在成績信息中找到該課程號的成績while(1) fread(&sc,sizeof(sc),1,fp); if(feof(fp) break; if(o=no) found=1;gradesn=sc;n=n+1;/PRINT1;/PRINT4;/排序for(i=0;i<n;i+) for(j=i+1;j<=n;j+) if(gradesi.grade<gradesj.grade) temp=gradesi;gradesi=gradesj;gradesj=temp;/顯示for(i=
48、0;i<n;i+) PRINT1;printf("%-5ld%5d%15f",gradesi.sno,o,gradesi.grade);PRINT1;if(!found) printf("未找到你要找的數(shù)據(jù)!");return; fclose(fp);/按課程名,用子函數(shù)查詢。void cnamequeryson() int getcno(char name);/獲取課程號。int getgrade(int cno,struct scgrade grades);/獲取成績void sort(struct scgrade grad
49、es,int n);/排序void display(struct scgrade grades,int n);/顯示struct scgrade grades80;char name20;int cno, n;printf("nEnter a course name of the query:");scanf("%s",name);cno=getcno(name);if(cno=-1) puts("No such course!"); return;n=getgrade(cno,grades);sort(grades,n);displ
50、ay(grades, n);int getcno(char name) FILE *fp;struct course c;int found=0,no;fp=fopen("d:STUDENTCOURSE.dat","rb");if(!fp) printf("Create file error!n"); return -1; /獲取課程號。while(1) fread(&c,sizeof(c),1,fp); if(feof(fp) break; if(strcmp(ame,name)=0) found=1;no=o;/PRINT
51、1;/PRINT3;/PRINT1;return no;if(!found) printf("未找到你要找的數(shù)據(jù)!");return -1; fclose(fp);int getgrade(int cno,struct scgrade grades) FILE *fp;struct scgrade sc;int n=0,found=0;fp=fopen("d:STUDENTGRADE.dat","rb");if(!fp) printf("Create file error!n"); return; /通過課程號,找到成績。while(1) fread(&sc,sizeof(sc),1,fp); if(feof(fp) break; if(o=cno) found=1;gradesn=sc;n=n+1;/PRINT1; /PRINT4; return n;if(!found) printf(&q
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 豆類作物種植的農業(yè)科技成果轉化考核試卷
- 2025年除草劑混劑合作協(xié)議書
- 管道工程行業(yè)政策環(huán)境與競爭力分析考核試卷
- 茶葉種類與品質鑒定考核試卷
- 康復輔具的標準化與模塊化設計考核試卷
- 船舶涂料性能測試與選用考核試卷
- 商場導視系統(tǒng)設計
- 2025年耐火土石類項目發(fā)展計劃
- 河南送變電運維安全考試
- 圓柱側面積計算
- 2025年特種設備安全操作實務考試真題卷
- 人教版小學數(shù)學六年級下冊說課稿
- 2025年高考歷史考綱(完整版)
- 地鐵事件面試題及答案
- 2025屆青海省西寧市高考第一次模擬預測地理試題(原卷版+解析版)
- 兒童肺血栓栓塞癥診斷與治療專家共識(2025)解讀課件
- 急救中心患者轉運流程標準化指南
- 《2025急性冠脈綜合征患者管理指南》解讀
- 電廠粉煤灰購銷合同
- 注射用A型肉毒毒素-額紋面部皺紋(FWS)量表評分考試
- 《碼垛機器人機械手的結構設計》9400字【論文】
評論
0/150
提交評論