用C語言開發(fā)小型數(shù)據(jù)庫管理系統(tǒng)代碼文庫 (1)_第1頁
用C語言開發(fā)小型數(shù)據(jù)庫管理系統(tǒng)代碼文庫 (1)_第2頁
用C語言開發(fā)小型數(shù)據(jù)庫管理系統(tǒng)代碼文庫 (1)_第3頁
用C語言開發(fā)小型數(shù)據(jù)庫管理系統(tǒng)代碼文庫 (1)_第4頁
用C語言開發(fā)小型數(shù)據(jù)庫管理系統(tǒng)代碼文庫 (1)_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、用C語言開發(fā)小型數(shù)據(jù)庫管理系統(tǒng)代碼的文庫.txt如果有來生,要做一棵樹,站成永恒,沒有悲傷的姿勢。一半在土里安詳,一半在風里飛揚,一半灑落陰涼,一半沐浴陽光,非常沉默非常驕傲,從不依靠從不尋找。#include <stdio.h>#include <string.h>typedef struct count /*保存記錄條數(shù)結構體*/ char name10; int num;count;typedef struct st char name10; long Number; int Math; int C; int Amount;st;st record8;count

2、num1; char filename10="0"char filename210="0"int Inputnum8;void MainMenu() /*主菜單*/ printf("ntttt* * * * * * * * * *n"); printf("tttt* 主菜單 *n"); printf("tttt* 1. 創(chuàng)建新文件 *n"); printf("tttt* 2. 添加記錄 *n"); printf("tttt* 3. 刪除記錄 *n"); p

3、rintf("tttt* 4. 排序 *n"); printf("tttt* 5. 查詢記錄 *n"); printf("tttt* 6. 退出 *n"); printf("tttt* * * * * * * * * *n");void DelMenu() /*刪除菜單*/ printf("ntttt* * * * * * * * * * * *n"); printf("tttt* 刪除菜單 *n"); printf("tttt* 1. 學號查詢刪除 *n"

4、;); printf("tttt* 2. 返回到上級菜單 *n"); printf("tttt* * * * * * * * * * * *n");void RankingMenu() /*排序菜單*/ printf("ntttt* * * * * * * * * * * *n"); printf("tttt* 排序菜單 *n"); printf("tttt* 1. 數(shù)學成績排序 *n"); printf("tttt* 2. C語言成績排序 *n"); printf(&quo

5、t;tttt* 3. 總分排序 *n"); printf("tttt* 4. 返回到上級菜單 *n"); printf("tttt* * * * * * * * * * * *n");void InquireMenu() /*查訊菜單*/ printf("ntttt* * * * * * * * * * * *n"); printf("tttt* 查訊菜單 *n"); printf("tttt* 1. 學號查訊 *n"); printf("tttt* 2. 姓名查訊 *n&q

6、uot;); printf("tttt* 3. 數(shù)學成績查訊 *n"); printf("tttt* 4. C語言成績查訊 *n"); printf("tttt* 5. 總分查訊 *n"); printf("tttt* 6. 返回到上級菜單 *n"); printf("tttt* * * * * * * * * * * *n");char Inputfilename() /*輸入文件名同時產生付本文件名*/ char str2="B" printf("* 請輸入文件

7、名 * : "); scanf("%s",filename); getchar(); strcpy(filename2,filename); strcat(filename2,str2);FILE *readfile() /*讀取文檔*/ FILE *fp1; if(fp1=fopen(filename,"rb")=NULL) printf("n文件讀取錯誤!n"); fclose(fp1); return(fp1);FILE *foundfile() /*新建文檔*/ FILE *fp1; if(fp1=fopen(fil

8、ename,"wb")=NULL) printf("n文件創(chuàng)建錯誤!n"); fclose(fp1); return(fp1);FILE *savefile() /*追加文檔*/ FILE *fp1; if(fp1=fopen(filename,"ab")=NULL) printf("n文件追加錯誤!n"); fclose(fp1); return(fp1);int InputSave() /*添加數(shù)據(jù) */ int i=0,j; char ch='y' while(ch!='w')

9、 i=i+1; printf("n* 請輸入姓名(字符型) * :"); scanf("%s",);Loop1: printf("n* 請輸入學號(長整型) * :"); scanf("%ld",&recordi.Number); if(i!=1) for(j=1;j<i;j+) if(recordi.Number=recordj.Number) printf("nt警告! 輸入了二個同樣的學號! 第%d條和第%d學號相同!n",i,j); printf(&

10、quot;nt請重新輸入!n"); goto Loop1; Loop2: printf("n* 請輸入數(shù)學成績(整型) * :"); scanf("%d",&recordi.Math); if(recordi.Math>100|recordi.Math<0) printf("nt輸入的分數(shù)不服合實際要求! 請重新錄入!n"); goto Loop2; Loop3: printf("n* 請輸入C語言成績(整型) * :"); scanf("%d",&reco

11、rdi.C); if(recordi.C>100|recordi.C<0) printf("nt輸入的分數(shù)不服合實際要求! 請重新錄入!n"); goto Loop3; recordi.Amount=recordi.Math+recordi.C; printf(" n'w'=結束錄入 's'=重新錄入此條記錄 'n'=下一條 : "); getchar(); /*吃掉上一個回車符*/ if(ch=getchar()='s') i=i-1; return(i);/*void Rea

12、dComputer(int i,FILE *fp1) (文本方式)數(shù)據(jù)寫入機器 int j; for(j=1;j<i+1;j+) fscanf(fp1,"%s,%ld,%d,%d,%d",,&recordj.Number,&recordj.Math,&recordj.C,&recordj.Amount);void SaveFile(int i,FILE *fp1) (文本方式)數(shù)據(jù)寫到文件中 int j; for(j=1;j<i+1;j+) fprintf(fp1,"%s,%ld,%d,%d,%d

13、",,recordj.Number,recordj.Math,recordj.C,recordj.Amount);*/ void ReadComputer2(int i,FILE *fp1) /*(2方式)數(shù)據(jù)寫入機器*/ int j; for(j=1;j<i+1;j+) if(fread(&recordj,sizeof(struct st),1,fp1)!=1) printf("n主文件數(shù)據(jù)讀取錯誤! n"); fclose(fp1); void SaveFile2(int i,FILE *fp1) /*(2方式)數(shù)據(jù)寫到文

14、件中*/ int j; for(j=1;j<i+1;j+) if(fwrite(&recordj,sizeof(struct st),1,fp1)!=1) printf("n主文件數(shù)據(jù)寫入錯誤! n"); fclose(fp1); /* * * */FILE *readfile2() /*讀文件付本*/ FILE *fp1; if(fp1=fopen(filename2,"rb")=NULL) printf("n付本文件讀取錯誤!n"); fclose(fp1); return(fp1);FILE *foundfile2

15、() /*新建文件付本*/ FILE *fp1; if(fp1=fopen(filename2,"wb")=NULL) printf("n付本文件創(chuàng)建錯誤!n"); fclose(fp1); return(fp1);FILE *savefile2() /*追加文件付本*/ FILE *fp1; if(fp1=fopen(filename2,"ab")=NULL) printf("n付本文件追加錯誤!n"); fclose(fp1); return(fp1);/*void Additive2(int i,FILE *

16、fp1) 數(shù)據(jù)與入付本文件(文本方式) int j; char str2="0" if(strcmp(filenameF,str2)!=0) strcpy(,filenameF); else strcpy(,filenameA); num0.num=i; fprintf(fp1,"%s,%d",,num0.num); int ReadComputer2(FILE *fp1) 讀出付本中的數(shù)據(jù)(文本方式) int j,k; fscanf(fp1,"%s,%d",,&

17、amp;num0.num); k=num0.num; return(k);*/void Additive2Two(int i,FILE *fp1) /*數(shù)據(jù)寫入付本文件(二進制方式)*/ char str2="0" if(strcmp(filename2,str2)!=0) strcpy(,filename2); else strcpy(,filename2); num0.num=i; if(fwrite(&num0,sizeof(struct count),1,fp1)!=1) printf("n付本文件數(shù)據(jù)寫入錯誤!

18、 n"); fclose(fp1); int ReadComputer2Two(FILE *fp1) /*讀出付本中的數(shù)據(jù)(二進制方式)*/ int j; if(fread(&num0,sizeof(struct count),1,fp1)!=1) printf("n付本文件數(shù)據(jù)讀取錯誤! n"); fclose(fp1); j=num0.num; return(j);/* * * */void Num_inquire() /*學號查詢*/ int num,j,time; FILE *fp1,*fp2; fp1=readfile(); /*讀取文檔*/ f

19、p2=readfile2(); /*(開打方式'讀'*'引用讀文件名')讀文件付本*/ time=ReadComputer2Two(fp2); /*讀出付本中的數(shù)據(jù)(二進制方式)*/ ReadComputer2(time,fp1); /*(2方式)數(shù)據(jù)寫入機器*/ fclose(fp1);fclose(fp2); printf("輸入學號:"); scanf("%ld",&num); /*getchar();*/ for(j=1;j<time+1;j+) if(recordj.Number=num) prin

20、tf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount); void Name_inquire() /*姓名查詢*/ int j,time; char Name10; FILE *fp1,*fp2; fp1=readfile(); fp2=readfile2(); /*(開打方式'讀'*'引用讀文件名')讀文件付本*/ time=ReadComputer2Two(

21、fp2); /*讀出付本中的數(shù)據(jù)(二進制方式)*/ ReadComputer2(time,fp1); /*(2方式)數(shù)據(jù)寫入機器*/ fclose(fp1);fclose(fp2); printf("輸入姓名:"); scanf("%s",Name); /*getchar();*/ for(j=1;j<time+1;j+) if(strcmp(Name,)=0) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,re

22、cordj.Number,recordj.Math,recordj.C,recordj.Amount); void Math_inquire() /*數(shù)學查詢*/ int Math,j,time; FILE *fp1,*fp2; fp1=readfile(); fp2=readfile2(); /*(開打方式'讀'*'引用讀文件名')讀文件付本*/ time=ReadComputer2Two(fp2); /*讀出付本中的數(shù)據(jù)(二進制方式)*/ ReadComputer2(time,fp1); /*(2方式)數(shù)據(jù)寫入機器*/ fclose(fp1);fclose(

23、fp2); printf("輸入數(shù)學成績:"); scanf("%d",&Math); /*getchar();*/ for(j=1;j<time+1;j+) if(recordj.Math>=Math) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount); void C_inquire() /*C查詢*/ int C,j

24、,time; FILE *fp1,*fp2; fp1=readfile(); fp2=readfile2(); /*(開打方式'讀'*'引用讀文件名')讀文件付本*/ time=ReadComputer2Two(fp2); /*讀出付本中的數(shù)據(jù)(二進制方式)*/ ReadComputer2(time,fp1); /*(2方式)數(shù)據(jù)寫入機器*/ fclose(fp1);fclose(fp2); printf("輸入C語言成績:"); scanf("%d",&C); /*getchar();*/ for(j=1;j&l

25、t;time+1;j+) if(recordj.C>=C) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount); void Amount_inquire() /*總分查詢*/ int Amount,j,time; FILE *fp1,*fp2; fp1=readfile(); fp2=readfile2(); /*(開打方式'讀'*'引用讀文件名

26、9;)讀文件付本*/ time=ReadComputer2Two(fp2); /*讀出付本中的數(shù)據(jù)(二進制方式)*/ ReadComputer2(time,fp1); /*(2方式)數(shù)據(jù)寫入機器*/ fclose(fp1);fclose(fp2); printf("輸入總分:"); scanf("%d",&Amount); /*getchar();*/ for(j=1;j<time+1;j+) if(recordj.Amount>=Amount) printf("nName:%-10s Num:%3ld Math:%3d C

27、:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount); /* * * */void Num_inquire_Del() /*學號查詢刪除*/ char ch; int num,j,k,time; FILE *fp1,*fp2; fp1=readfile(); /*讀取文檔*/ fp2=readfile2(); /*讀文件付本*/ time=ReadComputer2Two(fp2); /*讀出付本中的數(shù)據(jù)(二進制方式)*/ ReadComputer2(time,fp1)

28、; /*(2方式)數(shù)據(jù)寫入機器*/ fclose(fp1);fclose(fp2); printf("輸入學號:"); scanf("%ld",&num); getchar(); for(j=1;j<=time;j+) if(recordj.Number=num) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount); k=j;

29、printf("nt* 刪除='y' 不刪除='n' * : "); if(ch=getchar()='y') if(k=time) time=time-1; else for(j=k;j<time;j+) recordj=recordj+1; time=time-1; fp1=foundfile(); /*新建文檔*/ SaveFile2(time,fp1); /*(2方式)數(shù)據(jù)寫到文件中*/ fp2=foundfile2(); /*新建文件付本*/ Additive2Two(time,fp2); /*數(shù)據(jù)與入付本文件

30、(二進制方式)*/ printf("n刪除成功!目前共有%d條記錄!n",time); fclose(fp1);fclose(fp2); else printf("n沒有執(zhí)行刪除操作!n"); /* * * */void Math_ranking(int i) /*數(shù)學排序函數(shù)*/ int j,k; st time; for(j=1;j<i;j+) for(k=1;k<=i-j;k+) if(recordk.Math>recordk+1.Math) time=recordk;recordk=recordk+1;recordk+1=tim

31、e; printf("n"); for(j=1;j<i+1;j+) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount);void C_ranking(int i) /*C排序函數(shù)*/ int j,k; st time; for(j=1;j<i;j+) for(k=1;k<=i-j;k+) if(recordk.C>recordk+1.C)

32、 time=recordk;recordk=recordk+1;recordk+1=time; printf("n"); for(j=1;j<i+1;j+) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount);void Amount_ranking(int i) /*總分排序函數(shù)*/ int j,k; st time; for(j=1;j<i;j+)

33、 for(k=1;k<=i-j;k+) if(recordk.Amount>recordk+1.Amount) time=recordk;recordk=recordk+1;recordk+1=time; printf("n"); for(j=1;j<i+1;j+) printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount);/* * * */main

34、() FILE *fp,*ffp; int temp1=0,temp2=0,temp3; char ch,location; MainMenu(); location='1' printf("n請輸入選項 1 - 6 (當前在主菜單):"); while(ch=getchar()!='0') if(ch='6')&&(location='1') getchar(); printf("nnttt* 'Y'=續(xù)繼 'n'=退出 *n"); prin

35、tf("nnttINPUT:"); if(ch=getchar()='n') printf("nnttt 謝謝您的使用!"); exit(); break; else MainMenu();location='1' printf("n請輸入選項 1 - 6 (當前在主菜單):"); if(ch='1')&&(location='1') temp1=InputSave(); /*添加數(shù)據(jù) */ getchar(); printf("tt* '

36、;y'=保存 'n'=不保存 * : "); if(ch=getchar()='y') Inputfilename(); /*輸入文件名同時產生付本文件名*/ fp=foundfile(); /*新建文檔*/ SaveFile2(temp1,fp); /*(2方式)數(shù)據(jù)寫到文件中*/ fclose(fp); ffp=foundfile2(); /*(開打方式'新建')新建文件付本*/ Additive2Two(temp1,ffp); /*新建付本文件數(shù)據(jù)(文本方式)*/ fclose(ffp); printf("保存了

37、%d條記錄!n",temp1); else printf("t 沒有保存!n"); temp1=0;temp2=0; MainMenu();location='1' printf("n請輸入選項 1 - 6 (當前在主菜單):"); continue; if(ch='2')&&(location='1') getchar(); printf("nt * 'y'=使用當前文件名 'n'=輸入新文件名 * : "); if(ch=ge

38、tchar()='y') fp=savefile(); /*追加文檔*/ else Inputfilename(); /*輸入文件名同時產生付本文件名*/ fp=savefile(); temp1=InputSave(); /*添加數(shù)據(jù) */ temp3=temp1; SaveFile2(temp1,fp); /*(2方式)數(shù)據(jù)寫到文件中*/ fclose(fp); ffp=readfile2(); /*讀文件付本*/ temp2=ReadComputer2Two(ffp); /*讀出付本中的數(shù)據(jù)(文本方式)*/ fclose(ffp); temp1=temp1+temp2;

39、ffp=foundfile2(); /*新建文件付本*/ Additive2Two(temp1,ffp); /*新建付本文件數(shù)據(jù)(文本方式)*/ fclose(ffp); printf("n添加拉%d條數(shù)據(jù)!共保存%d條數(shù)據(jù)!n",temp3,temp1); temp1=0;temp2=0; MainMenu();location='1' printf("n請輸入選項 1 - 6 (當前在主菜單):"); continue; if(ch='3')&&(location='1') DelMenu();location='2' printf("n請輸入選項 1 - 3 (當前在刪除菜單):"); while(ch=getchar()!='0') if(ch='1')&&(location='2') getchar(); printf("ntt *現(xiàn)在位置在刪除菜單 - 學號刪除*n"); printf("nt * 

溫馨提示

  • 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論