


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
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 /* 定義學生成績結(jié)構(gòu)體 */int num; /* 學號 */char name15; /* 姓名 */ double elec; /* 選修課 */ double expe; /* 實驗課 */ double requ; /* 必修課 */ double sum; /* 總分 */;struct student stu50; /* 定義結(jié)構(gòu)體數(shù)組 */ void input(); /* 錄入學生成績信息 */ void show(); /* 顯示學生信息 */ void
3、 sort(); /* 按總分排序 */ void del(); /* 刪除學生成績信息 */ void modify(); /* 修改學生成績信息 */ void menu(); /* 主菜單 */ void insert(); /* 插入學生信息 */ void total(); /* 計算總?cè)藬?shù) */ void search(); /* 查找學生信息 */ 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) /* 打開指定文件 */printf( "can not openn" ); return ; /* 返回主函數(shù) */while (!feof(fp) /*feof() 函數(shù)是用來判斷指針是否已經(jīng)到達文件尾部的, 若指針指向文件末尾,則返回值為 “真 ”, if (fread(&stum,LEN,1,fp)=1) m+; /* 統(tǒ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);/* 向指定磁盤文件寫入信息 */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);/* 輸入學生學號 */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" ,&);/* 輸入學生姓名 */printf( "elective:" );scanf( "%lf" ,&stum.elec); /* 輸入選修課成績 */ printf( "experiment:" );scanf( "%lf" ,&stum.expe
13、); /* 輸入實驗課成績 */printf( "required course:");scanf( "%lf" ,&stum.requ); /* 輸入必修課成績 */ stum.sum=stum.elec*Ielec+stum.expe*Iexpe+stum.requ*Irequ;績*/if (fwrite(&stum,LEN,1,fp)!=1) /* 將新錄入的信息寫入指定的磁盤文件/* 計算出總成*/printf( "can not save!" ); getch();elseprintf( "%s s
14、aved!n" ,);m+;printf( "continue?(y/n):" scanf( "%s" ,ch);fclose(fp);printf( "OK!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); /* 輸入需要查找學生的學號 */ for (i=0;i<m;i+)if (snum=stui.num) /* 查找出入的學號是否在記錄中 */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"); /* 沒有找到要查額信息 */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 ;/* 將更改后的記錄重新寫入指定的磁盤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; /* 從最后一條記錄開始均向后移一位 */ 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;計算總成績 */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. 本站所有資源如無特殊說明,都需要本地電腦安裝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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 地鐵工程檔案資料集中管理措施
- 小學普通話節(jié)慶活動推廣計劃
- 網(wǎng)球培訓機構(gòu)教學計劃
- 裝飾工程施工技術(shù)質(zhì)量保證體系及措施
- 小學乒乓球社團多樣化訓練計劃
- 科技企業(yè)人力資源部創(chuàng)新激勵計劃
- 金融行業(yè)風險資源配備計劃
- 腫瘤科輸血流程與規(guī)范管理
- 綜藝節(jié)目腳本策劃書范文
- 拆除施工塵土污染防治文明措施
- 體育經(jīng)紀人資格考試復習資料
- 2025年英語四級考試試卷及答案
- 中國絲綢文化課件
- 人工血管內(nèi)瘺穿刺技巧與護理
- 脊柱術(shù)后腦脊液漏護理
- 預防溺水小學課件
- 血小板減少課件
- 裝修工程滿堂腳手架施工方案
- 12J12無障礙設(shè)施圖集
- VMware數(shù)據(jù)中心的服務(wù)器虛擬化與運維管理解決方案
- 夫妻婚內(nèi)財產(chǎn)約定協(xié)議書范本(2025年)
評論
0/150
提交評論