學(xué)生成績(jī)管理系統(tǒng)-vs資料講解_第1頁(yè)
學(xué)生成績(jī)管理系統(tǒng)-vs資料講解_第2頁(yè)
學(xué)生成績(jī)管理系統(tǒng)-vs資料講解_第3頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、#include <stdio.h>#include <stdlib.h>#include <conio.h> #include <dos.h> #include <string.h> #define LEN sizeof ( struct student)#define FORMAT"%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lfn"#define DATA stui.num,,stui.elec,stui.expe,stui.requ,stui.sum fl

2、oat Ielec,Iexpe,Irequ;float Felec,Fexpe,Frequ;struct student /* 定義學(xué)生成績(jī)結(jié)構(gòu)體 */int num; /* 學(xué)號(hào) */char name15; /* 姓名 */ double elec; /* 選修課 */ double expe; /* 實(shí)驗(yàn)課 */ double requ; /* 必修課 */ double sum; /* 總分 */;struct student stu50; /* 定義結(jié)構(gòu)體數(shù)組 */ void input(); /* 錄入學(xué)生成績(jī)信息 */ void show(); /* 顯示學(xué)生信息 */ void

3、 sort(); /* 按總分排序 */ void del(); /* 刪除學(xué)生成績(jī)信息 */ void modify(); /* 修改學(xué)生成績(jī)信息 */ void menu(); /* 主菜單 */ void insert(); /* 插入學(xué)生信息 */ void total(); /* 計(jì)算總?cè)藬?shù) */ void search(); /* 查找學(xué)生信息 */ main()int n; menu(); scanf( "%d",&n); while (n) switch (n)case 1: input();break ;case 2: search();break

4、 ;case 3: del();break ;case 4: modify();break ;case 5: insert();break ;case 6: sort();break ;case 7: total();break ;default : break ;menu(); scanf( "%d",&n); void show() FILE *fp;int i,m=0;fp=fopen( "d:data.txt", "ab+" );while (!feof(fp)if (fread(&stum ,LEN,1,fp

5、)=1) m+;fclose(fp);printf( "number name elective experiment required sumtn" for (i=0;i<m;i+)printf(FORMAT,DATA); /* 將信息按指定格式打印 */void menu()system( "cls" );printf( "n" );printf( "n" );printf( "t|Student management system|n");printf("t|n"

6、printf("t|0. exit|n"printf("t|n"printf("t|1. input record|n"printf("t|n"printf("t|2. search record|n"printf("t|n"printf("t|3. delete record|n"printf("t|n"printf("t|4. modify record|n"printf("t|n"print

7、f("t|5. insert record|n"printf("t|n"printf("t|6. order|n"printf("t|n"printf("t|7. number|n"printf("t|n"printf("t|n"printf("n" );printf("n" );printf(I!choose( 0 7 ):"););););););););););););););););););););

8、 void input() int i,m=0;char ch2;FILE *fp;if (fp=fopen( "d:data.txt" , "ab+" )=NULL) /* 打開(kāi)指定文件 */printf( "can not openn" ); return ; /* 返回主函數(shù) */while (!feof(fp) /*feof() 函數(shù)是用來(lái)判斷指針是否已經(jīng)到達(dá)文件尾部的, 若指針指向文件末尾,則返回值為 “真 ”, if (fread(&stum,LEN,1,fp)=1) m+; /* 統(tǒng)計(jì)當(dāng)前記錄條數(shù) */ fclo

9、se(fp); if (m=0) printf( "No record!n" ); else system( "cls" );show(); /*調(diào)用show函數(shù),顯示原有信息*/if (fp=fopen( "d:data.txt" , "wb" )=NULL)printf( "can not openn" );return ; for (i=0;i<m;i+) fwrite(&stum,LEN,1,fp);/* 向指定磁盤(pán)文件寫(xiě)入信息 */printf( "please

10、 input (y/n):/n");scanf( "%s",&ch);if (strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0) printf("please input per centum:");printf("nelective:" );scanf( "%f" ,&Ielec);printf( "/nexperiment:" );scanf( "%f" ,&Iexpe);

11、printf( "/nrequired course:" );scanf( "%f" ,&Irequ);while (strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0)printf( "number:" );scanf( "%d",&stum.num);/* 輸入學(xué)生學(xué)號(hào) */for (i=0;i<m;i+)if (stui.num=stum.num)返回。 */); printf( "the number is ex

12、isting,press any to continue!"getch();fclose(fp);return ;printf( "name:" );scanf( "%s" ,&);/* 輸入學(xué)生姓名 */printf( "elective:" );scanf( "%lf" ,&stum.elec); /* 輸入選修課成績(jī) */ printf( "experiment:" );scanf( "%lf" ,&stum.expe

13、); /* 輸入實(shí)驗(yàn)課成績(jī) */printf( "required course:");scanf( "%lf" ,&stum.requ); /* 輸入必修課成績(jī) */ stum.sum=stum.elec*Ielec+stum.expe*Iexpe+stum.requ*Irequ;績(jī)*/if (fwrite(&stum,LEN,1,fp)!=1) /* 將新錄入的信息寫(xiě)入指定的磁盤(pán)文件/* 計(jì)算出總成*/printf( "can not save!" ); getch();elseprintf( "%s s

14、aved!n" ,);m+;printf( "continue?(y/n):" scanf( "%s" ,ch);fclose(fp);printf( "OK!n" );); /* 詢問(wèn)是否繼續(xù) */void search()FILE *fp;int snum,i,m=0;char ch2;if (fp=fopen( "d:data.txt"printf( "can not openn"/* 自定義查找函數(shù) */, "ab+" )=NULL);re

15、turnwhile (!feof(fp)if (fread(&stum,LEN,1,fp)=1)m+;if (m=0)printf( "no record!n");return ;printf( "please input the number:" );scanf( "%d",&snum); /* 輸入需要查找學(xué)生的學(xué)號(hào) */ for (i=0;i<m;i+)if (snum=stui.num) /* 查找出入的學(xué)號(hào)是否在記錄中 */printf( "find the student,show?(y/n

16、)");scanf( "%s" ,ch);if (strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0)printf( "number name elective experiment requiredsumtn" );printf(FORMAT,DATA); /* 將查找出得結(jié)果按指定格式輸出 */ break ;if (i=m)printf( "can not find the student!n"); /* 沒(méi)有找到要查額信息 */system( "

17、;pause" );void modify() /* 自定義修改函數(shù) */int i,j,snum,m=0;FILE *fp;if (fp=fopen( "d:data.txt" , "ab+" )=NULL)printf( "can not openn" );return ;while (!feof(fp)if (fread(&stum,LEN,1,fp)=1)m+;if (m=0)printf( "no record!n" ); fclose(fp);return ;printf( "

18、;please input the number of the student which do you want to modify!n");scanf( "%d" ,&snum);for (i=0;i<m;i+)if (snum=stui.num) /* 檢索記錄中是否有要修改的信息 */ break ;if (i<m)printf( "find the student! you can modify now!n");printf( "please input per centnm:");printf

19、( "nelective:" );scanf( "%f" ,&Ielec);printf( "nexperiment:" );scanf( "%f" ,&Iexpe);printf( "nrequired course:" ); scanf( "%f" ,&Irequ);printf( "name:n" );scanf("%s" ,&);printf( "nelective:&

20、quot; );scanf("%lf" ,&stui.elec);printf( "nexperiment:" );scanf("%lf" ,&stui.expe);printf( "nrequired course:" ); scanf("%lf" ,&stui.requ);stui.sum=stui.elec*Ielec+stui.expe*Iexpe+stui.requ*Irequ; else);, "wb" )=NULL);printf( &q

21、uot;can not find!" getch();return ;if (fp=fopen( "d:data.txt"printf( "can not openn" return ;for (j=0;j<m;j+)if (fwrite(&stuj,LEN,1,fp)!=1)printf( "can not save!" );getch();fclose(fp);void del() /* 自定義刪除函數(shù) */int snum,i,j,m=0;char ch2;FILE *fp;if (fp=fopen( &

22、quot;d:data.txt" , "ab+" )=NULL) printf( "can not openn" ); return ;while (!feof(fp)if (fread(&stum,LEN,1,fp)=1)m+; fclose(fp);if (m=0) printf( "no record!n" );return ;);printf( "please input the number:"scanf( "%d" ,&snum);for (i=0;i<

23、;m;i+)if (snum=stui.num)break ;);printf( "find the student,delete?(y/n)"scanf( "%s" ,ch);ifif(strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0) for (j=i;j<m;j+) stuj=stuj+1; m-;(fp=fopen( "d:data.txt","wb" )=NULL)文件中 */voidinsert() forprintf( "

24、;can not openn" return ;);(j=0;j<m;j+)if (fwrite(&stuj,LEN,1,fp)!=1)printf( "can not save!n" getch();fclose(fp);printf( "delete successfully!n"/* 自定義插入函數(shù) */int i,j,k,snum,m=0; FILE *fp;(fp=fopen( "d:data.txt"ifprintf( "can not openn" return ;););,

25、"ab+" )=NULL); while (!feof(fp)if (fread(&stum,LEN,1,fp)=1) m+;if (m=0)printf( "no record!n" ); fclose(fp);return ;/* 將更改后的記錄重新寫(xiě)入指定的磁盤(pán)printf( "please input the position where you want to insert!n");scanf( "%d",&snum); /* 輸入要插入的位置 */for (i=0;i<m;i+)i

26、f (snum=stui.num) break ;for (j=m-1;j>i;j-)stuj+1=stuj; /* 從最后一條記錄開(kāi)始均向后移一位 */ printf( "please input the new information:n");printf( "number:" );scanf( "%d" ,&stui+1.num);for (k=0;k<m;k+)if (stuk.num=stui+1.num&&k!=i+1)printf( "the number is existi

27、ng,press any to continue!");getch();fclose(fp);return ;printf( "please input per centum:");printf( "nelective:" );scanf( "%f" ,&Felec);printf( "nexperiment:" );scanf( "%f" ,&Fexpe);printf( "nrequired course:" );scanf( "%f&

28、quot; ,&Frequ);printf( "name:n" );scanf("%s" ,&stui+1.name);printf( "nelective:" );scanf("%lf" ,&stui+1.elec);printf( "nexperiment:" );scanf("%lf" ,&stui+1.expe);printf("nrequired course:");scanf("%lf" ,&stui+1.requ);/*stui+1.sum=stui+1.elec*Felec+stui+1.expe*Fexpe+stui+1.requ*Frequ;計(jì)算總成績(jī) */if (fp=fopen( "d:data.txt", "wb" )=NULL)printf( "can not openn" ); return ;for (k=0;k<=m;k+)if (fwrite(&stuk,LEN,1,fp)!=1) /* 將修改后的

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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)論