用C语言开发小型数据库管理系统代码文库_第1页
用C语言开发小型数据库管理系统代码文库_第2页
用C语言开发小型数据库管理系统代码文库_第3页
用C语言开发小型数据库管理系统代码文库_第4页
用C语言开发小型数据库管理系统代码文库_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、用C语言开发小型数据库管理系统代码文库.txt如果有来生,要做一棵树,站成永恒,没有悲伤的姿势。一半在土里安详,一半在风里飞扬,一半洒落阴凉,一半沐浴阳光,非常沉默非常骄傲,从不依靠从不寻找。#include #include typedef struct count /*保存记录条数结构体*/char name10;int num;count;typedef struct stchar name10;long Number;int Math;int C;int Amount;st;st record8;count num1; char filename10="0"char

2、 filename210="0"int Inputnum8;void MainMenu( /*主菜单*/printf("ntttt* * * * * * * * * *n"printf("tttt* 主菜单 *n"printf("tttt* 1. 创建新文件 *n"printf("tttt* 2. 添加记录 *n"printf("tttt* 3. 删除记录 *n"printf("tttt* 4. 排序 *n"printf("tttt* 5. 查询

3、记录 *n"printf("tttt* 6. 退出 *n"printf("tttt* * * * * * * * * *n"void DelMenu( /*删除菜单*/printf("ntttt* * * * * * * * * * * *n"printf("tttt* 删除菜单 *n"printf("tttt* 1. 学号查询删除 *n"printf("tttt* 2. 返回到上级菜单 *n"printf("tttt* * * * * * * * * *

4、 * *n"void RankingMenu( /*排序菜单*/printf("ntttt* * * * * * * * * * * *n"printf("tttt* 排序菜单 *n"printf("tttt* 1. 数学成绩排序 *n"printf("tttt* 2. C语言成绩排序 *n"printf("tttt* 3. 总分排序 *n"printf("tttt* 4. 返回到上级菜单 *n"printf("tttt* * * * * * * * *

5、* * *n"void InquireMenu( /*查讯菜单*/printf("ntttt* * * * * * * * * * * *n"printf("tttt* 查讯菜单 *n"printf("tttt* 1. 学号查讯 *n"printf("tttt* 2. 姓名查讯 *n"printf("tttt* 3. 数学成绩查讯 *n"printf("tttt* 4. C语言成绩查讯 *n"printf("tttt* 5. 总分查讯 *n"pr

6、intf("tttt* 6. 返回到上级菜单 *n"printf("tttt* * * * * * * * * * * *n"char Inputfilename( /*输入文件名同时产生付本文件名*/char str2="B"printf("* 请输入文件名 * : "scanf("%s",filename;getchar(;strcpy(filename2,filename;strcat(filename2,str2;FILE *readfile( /*读取文档*/FILE *fp1;if(

7、fp1=fopen(filename,"rb"=NULLprintf("n文件读取错误!n"fclose(fp1;return(fp1;FILE *foundfile( /*新建文档*/FILE *fp1;if(fp1=fopen(filename,"wb"=NULLprintf("n文件创建错误!n"fclose(fp1;return(fp1;FILE *savefile( /*追加文档*/FILE *fp1;if(fp1=fopen(filename,"ab"=NULLprintf(&quo

8、t;n文件追加错误!n"fclose(fp1;return(fp1;int InputSave( /*添加数据 */int i=0,j;char ch='y'while(ch!='w'i=i+1;printf("n* 请输入姓名(字符型 * :"scanf("%s",;Loop1: printf("n* 请输入学号(长整型 * :"scanf("%ld",&recordi.Number;if(i!=1for(j=1;j if(recordi.

9、Number=recordj.Numberprintf("nt警告! 输入了二个同样的学号! 第%d条和第%d学号相同!n",i,j;printf("nt请重新输入!n"goto Loop1; Loop2: printf("n* 请输入数学成绩(整型 * :"scanf("%d",&recordi.Math;if(recordi.Math>100|recordi.Math<0printf("nt输入的分数不服合实际要求! 请重新录入!n"goto Loop2;Loop3: p

10、rintf("n* 请输入C语言成绩(整型 * :"scanf("%d",&recordi.C;if(recordi.C>100|recordi.C<0printf("nt输入的分数不服合实际要求! 请重新录入!n"goto Loop3;recordi.Amount=recordi.Math+recordi.C;printf(" n'w'=结束录入 's'=重新录入此条记录 'n'=下一条 : "getchar(; /*吃掉上一个回车符*/if(c

11、h=getchar(='s'i=i-1;return(i;/*void ReadComputer(int i,FILE *fp1 (文本方式数据写入机器int j;for(j=1;j fscanf(fp1,"%s,%ld,%d,%d,%d",,&recordj.Number,&recordj.Math,&recordj.C,&recordj.Amount;void SaveFile(int i,FILE *fp1 (文本方式数据写到文件中int j;for(j=1;j fprintf(fp1,"

12、;%s,%ld,%d,%d,%d",,recordj.Number,recordj.Math,recordj.C,recordj.Amount;*/ void ReadComputer2(int i,FILE *fp1 /*(2方式数据写入机器*/int j;for(j=1;j if(fread(&recordj,sizeof(struct st,1,fp1!=1printf("n主文件数据读取错误! n"fclose(fp1;void SaveFile2(int i,FILE *fp1 /*(2方式数据写到文件中*/int j;f

13、or(j=1;j if(fwrite(&recordj,sizeof(struct st,1,fp1!=1printf("n主文件数据写入错误! n"fclose(fp1;/* * * */FILE *readfile2( /*读文件付本*/FILE *fp1;if(fp1=fopen(filename2,"rb"=NULLprintf("n付本文件读取错误!n"fclose(fp1;return(fp1;FILE *foundfile2( /*新建文件付本*/FILE *fp1;if(fp1=fopen(filename2,

14、"wb"=NULLprintf("n付本文件创建错误!n"fclose(fp1;return(fp1;FILE *savefile2( /*追加文件付本*/FILE *fp1;if(fp1=fopen(filename2,"ab"=NULLprintf("n付本文件追加错误!n"fclose(fp1;return(fp1;/*void Additive2(int i,FILE *fp1 数据与入付本文件(文本方式)int j;char str2="0"if(strcmp(filenameF,st

15、r2!=0strcpy(,filenameF;elsestrcpy(,filenameA;num0.num=i;fprintf(fp1,"%s,%d",,num0.num;int ReadComputer2(FILE *fp1 读出付本中的数据(文本方式)int j,k;fscanf(fp1,"%s,%d",,&num0.num;k=num0.num;return(k;*/void Additive2Two(int i,FILE *fp1 /*数据写入付本文件(二进制方式)*

16、/char str2="0"if(strcmp(filename2,str2!=0strcpy(,filename2;elsestrcpy(,filename2;num0.num=i;if(fwrite(&num0,sizeof(struct count,1,fp1!=1printf("n付本文件数据写入错误! n"fclose(fp1;int ReadComputer2Two(FILE *fp1 /*读出付本中的数据(二进制方式)*/int j;if(fread(&num0,sizeof(struct

17、 count,1,fp1!=1printf("n付本文件数据读取错误! n"fclose(fp1;j=num0.num;return(j;/* * * */void Num_inquire( /*学号查询*/int num,j,time;FILE *fp1,*fp2;fp1=readfile(; /*读取文档*/fp2=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/time=ReadComputer2Two(fp2; /*读出付本中的数据(二进制方式)*/ReadComputer2(time,fp1; /*(2方

18、式数据写入机器*/fclose(fp1;fclose(fp2;printf("输入学号:"scanf("%ld",#/*getchar(;*/for(j=1;j if(recordj.Number=numprintf("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 Na

19、me10;FILE *fp1,*fp2;fp1=readfile(;fp2=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/time=ReadComputer2Two(fp2; /*读出付本中的数据(二进制方式)*/ReadComputer2(time,fp1; /*(2方式数据写入机器*/fclose(fp1;fclose(fp2;printf("输入姓名:"scanf("%s",Name;/*getchar(;*/for(j=1;j if(strcmp(Name,=0

20、printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount;void Math_inquire( /*数学查询*/int Math,j,time;FILE *fp1,*fp2;fp1=readfile(;fp2=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/time=ReadComputer2Two(fp2; /*读出付本中的数据

21、(二进制方式)*/ReadComputer2(time,fp1; /*(2方式数据写入机器*/fclose(fp1;fclose(fp2;printf("输入数学成绩:"scanf("%d",&Math;/*getchar(;*/for(j=1;j if(recordj.Math>=Mathprintf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.A

22、mount;void C_inquire( /*C查询*/int C,j,time;FILE *fp1,*fp2;fp1=readfile(;fp2=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/time=ReadComputer2Two(fp2; /*读出付本中的数据(二进制方式)*/ReadComputer2(time,fp1; /*(2方式数据写入机器*/fclose(fp1;fclose(fp2;printf("输入C语言成绩:"scanf("%d",&C;/*getchar(

23、;*/for(j=1;j if(recordj.C>=Cprintf("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(; /*(开打方式'读'*'引用读文件名'读文件付本*/ti

24、me=ReadComputer2Two(fp2; /*读出付本中的数据(二进制方式)*/ReadComputer2(time,fp1; /*(2方式数据写入机器*/fclose(fp1;fclose(fp2;printf("输入总分:"scanf("%d",&Amount;/*getchar(;*/for(j=1;j if(recordj.Amount>=Amountprintf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.

25、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; /*读出付本中的数据(二进制方式)*/ReadComputer2(time,fp1; /*(2方式数据写入机器*/fclose(fp1;fclose(fp2;printf("输入学号:&q

26、uot;scanf("%ld",#getchar(;for(j=1;j<=time;j+if(recordj.Number=numprintf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,recordj.C,recordj.Amount;k=j;printf("nt* 删除='y' 不删除='n' * : "if(ch=getchar(='y'i

27、f(k=timetime=time-1;else for(j=k;j recordj=recordj+1;time=time-1;fp1=foundfile(; /*新建文档*/SaveFile2(time,fp1; /*(2方式数据写到文件中*/fp2=foundfile2(; /*新建文件付本*/Additive2Two(time,fp2; /*数据与入付本文件(二进制方式)*/printf("n删除成功!目前共有%d条记录!n",time;fclose(fp1;fclose(fp2;else printf("n没有执行删除操作!n"/* * * *

28、/void Math_ranking(int i /*数学排序函数*/int j,k;st time;for(j=1;j for(k=1;k<=i-j;k+if(recordk.Math>recordk+1.Mathtime=recordk;recordk=recordk+1;recordk+1=time;printf("n"for(j=1;j printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",,recordj.Number,recordj.Math,re

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

30、ordj.Math,recordj.C,recordj.Amount;void Amount_ranking(int i /*总分排序函数*/int j,k;st time;for(j=1;j for(k=1;k<=i-j;k+if(recordk.Amount>recordk+1.Amounttime=recordk;recordk=recordk+1;recordk+1=time;printf("n"for(j=1;j printf("nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3dn",rec

31、,recordj.Number,recordj.Math,recordj.C,recordj.Amount;/* * * */main(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(&q

32、uot;nnttt* 'Y'=续继 'n'=退出 *n"printf("nnttINPUT:"if(ch=getchar(='n'printf("nnttt 谢谢您的使用!"exit(;break;else MainMenu(;location='1'printf("n请输入选项 1 - 6 (当前在主菜单:"if(ch='1'&&(location='1'temp1=InputSave(; /*添加数据 */ge

33、tchar(;printf("tt* 'y'=保存 'n'=不保存 * : "if(ch=getchar(='y'Inputfilename(; /*输入文件名同时产生付本文件名*/fp=foundfile(; /*新建文档*/SaveFile2(temp1,fp; /*(2方式数据写到文件中*/fclose(fp;ffp=foundfile2(; /*(开打方式'新建'新建文件付本*/Additive2Two(temp1,ffp; /*新建付本文件数据(文本方式)*/fclose(ffp;printf(&qu

34、ot;保存了%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=getchar(='y&

35、#39;fp=savefile(; /*追加文档*/else Inputfilename(; /*输入文件名同时产生付本文件名*/fp=savefile(;temp1=InputSave(; /*添加数据 */temp3=temp1;SaveFile2(temp1,fp; /*(2方式数据写到文件中*/fclose(fp;ffp=readfile2(; /*读文件付本*/temp2=ReadComputer2Two(ffp; /*读出付本中的数据(文本方式)*/fclose(ffp;temp1=temp1+temp2;ffp=foundfile2(; /*新建文件付本*/Additive2Tw

36、o(temp1,ffp; /*新建付本文件数据(文本方式)*/fclose(ffp;printf("n添加拉%d条数据!共保存%d条数据!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 (当前在删除菜单

37、:"while(ch=getchar(!='0'if(ch='1'&&(location='2'getchar(;printf("ntt *现在位置在删除菜单 - 学号删除*n"printf("nt * 'y'=使用当前文件名 'n'=输入新文件名 * : "if(ch=getchar(='y' /*追加文档*/else Inputfilename(; /*输入文件名同时产生付本文件名*/Num_inquire_Del(; /*学号查

38、询删除*/DelMenu(;location='2'printf("n请输入选项 1 - 3 (当前在删除菜单:"continue;if(ch='2'&&(location='2'MainMenu(;location='1'printf("n请输入选项 1 - 6 (当前在主菜单:"break;if(ch='4'&&(location='1'RankingMenu(;location='3'printf(&quo

39、t;n请输入选项 1 - 4 (当前在排序菜单:"while(ch=getchar(!='0'if(ch='1'&&(location='3'getchar(;printf("ntt *现在位置在排序菜单 - 数学排序*n"printf("nt * 'y'=使用当前文件名 'n'=输入新文件名 * : "if(ch=getchar(='y' /*追加文档*/else Inputfilename(;fp=readfile(; /*读取文

40、档*/ffp=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/temp1=ReadComputer2Two(ffp; /*读出付本中的数据(二进制方式)*/ fclose(ffp;ReadComputer2(temp1,fp; /*(2方式数据写入机器*/fclose(fp;Math_ranking(temp1; /*数学排序函数*/temp1=0;temp2=0;RankingMenu(;location='3'printf("n请输入选项 1 - 4 (当前在排序菜单:"continue;if(

41、ch='2'&&(location='3'getchar(;printf("ntt *现在位置在排序菜单 - C语言排序*n"printf("nt * 'y'=使用当前文件名 'n'=输入新文件名 * : "if(ch=getchar(='y' /*追加文档*/else Inputfilename(;fp=readfile(; /*读取文档*/ffp=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/t

42、emp1=ReadComputer2Two(ffp; /*读出付本中的数据(二进制方式)*/fclose(ffp;ReadComputer2(temp1,fp; /*(2方式数据写入机器*/fclose(fp;C_ranking(temp1; /*数学排序函数*/temp1=0;temp2=0;RankingMenu(;location='3'printf("n请输入选项 1 - 4 (当前在排序菜单:"continue;if(ch='3'&&(location='3'getchar(;printf("

43、;ntt *现在位置在排序菜单 - 总分排序*n"printf("nt * 'y'=使用当前文件名 'n'=输入新文件名 * : "if(ch=getchar(='y' /*追加文档*/else Inputfilename(;fp=readfile(; /*读取文档*/ffp=readfile2(; /*(开打方式'读'*'引用读文件名'读文件付本*/temp1=ReadComputer2Two(ffp; /*读出付本中的数据(二进制方式)*/fclose(ffp;ReadComput

44、er2(temp1,fp; /*(2方式数据写入机器*/fclose(fp;Amount_ranking(temp1; /*数学排序函数*/temp1=0;temp2=0;RankingMenu(;location='3'printf("n请输入选项 1 - 4 (当前在排序菜单:"continue;if(ch='4'&&(location='3'MainMenu(;location='1'printf("n请输入选项 1 - 6 (当前在主菜单:"break;if(ch=&

45、#39;5'&&(location='1'InquireMenu(;location='4'printf("n请输入选项 1 - 6 (当前在查询菜单:"while(ch=getchar(!='0'if(ch='1'&&(location='4'getchar(;printf("ntt *现在位置在查询菜单 - 学号查询*n"printf("nt * 'y'=使用当前文件名 'n'=输入新文件名 * : "if(ch=getchar(='y' /*追加文档*/else Inputfilename(;Num_inquire(; /*学号查询*/Inquire

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论