c文件管理系统源码(C语言文件管理系统)
本文目录一览:
- 1、c语言仓库管理系统源代码
- 2、急求c语言程序设计 图书管理系统 源代码
- 3、急求C语言编写的图书管理系统源代码,具体要求如下
- 4、急求用C语言编写的图书管理系统源代码
- 5、跪求c语言教务管理系统源代码
- 6、c语言 图书管理系统 源代码
c语言仓库管理系统源代码
学籍管理的程序,你自己改改吧
#includestdio.h
#includewindows.h
#includeconio.h
int add();
int amend();
int remove();
int show_student();
int show_class();
struct info //定义结构体info,用于存储学生信息
{
char name[20]; //姓名
char sex[20]; //性别
char idcard[20]; //身份证号码
char stuid[10]; //学号
char academe[20]; //学院
char specialty[20]; //专业
char classid[20]; //班级
char home[20]; //生源地
}stu[100];
int j=0;
int main(void) //主函数
{
/*登陆界面设计*/
char gongnengxuanzhe;
int flag=1;
system("cls");
printf("\n");
printf("\t\t\t\t 欢迎\n");
printf("\n\n\t尊敬的用户, 非常感谢您使用本系统 , 您的完美体验将是我们前进的方向 !\n\n\n");
printf("\t系统功能简介:\n\n\n");
printf("\t\t①:通过键盘输入某位学生的学生证信息。\n\n");
printf("\t\t②:给定学号,显示某位学生的学生证信息。\n\n");
printf("\t\t③:给定某个班级的班号,显示该班所有学生的学生证信息。\n\n");
printf("\t\t④:给定某位学生的学号,修改该学生的学生证信息。\n\n");
printf("\t\t⑤:给定某位学生的学号,删除该学生的学生证信息。\n\n");
printf("\t\t⑥:按出生日期对全班学生的信息进行排序。\n\n\n");
printf("\t按任意键进入系统......");
getch();
do
{
system("cls");
printf("\n\n\n");
printf(" 尊敬的用户 ,欢迎您使用本系统 !\n");
printf("\n\n\n");
printf(" 1.增加学生信息\n\n");
printf(" 2.修改学生信息\n\n");
printf(" 3.删除学生信息\n\n");
printf(" 4.显示单个学生信息\n\n");
printf(" 5.显示整个班级学生信息\n\n");
printf(" 0.退出系统\n\n\n\n");
printf(" 请选择您需要使用的功能:");
gongnengxuanzhe=getch();
switch(gongnengxuanzhe)
{
case '1':add();break;
case '2':amend();break;
case '3':remove();break;
case '4':show_student();break;
case '5':show_class();break;
case '0':flag=0;break;
default:
{
printf("\n\n 您的输入有误,请仔细阅读使用说明!");
printf("\n 任意键继续...");
getch();
}
}
}while(flag==1);
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t尊敬的用户,非常感谢您的使用,您对于完美的追求是我们唯一的动力!");
printf("\n\n\t\t\t 按任意键退出系统......");
getch();
return 0;
}
int add() //增加学生信息函数
{
char flag='1';
do
{
system("cls");
printf("\n\t姓名:");
scanf("%s",stu[j].name);
printf("\n\n\t性别:");
scanf("%s",stu[j].sex);
printf("\n\n\t身份证号:");
scanf("%s",stu[j].idcard);
printf("\n\n\t学院:");
scanf("%s",stu[j].academe);
printf("\n\n\t专业:");
scanf("%s",stu[j].specialty);
printf("\n\n\t班级:");
scanf("%s",stu[j].classid);
printf("\n\n\t学号:");
scanf("%s",stu[j].stuid);
printf("\n\n\t生源地:");
scanf("%s",stu[j].home);
j++;
printf("\n\t继续增加请键入1,返回请键入其他任意键:");
getchar();
flag=getchar();
}while(flag=='1');
return 0;
}
int amend() //修改学生信息函数
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系统无任何可以修改的记录,请先行输入数据!");
printf("\n\n\t\t\t 按任意键返回......");
getch();
return 0;
}
char a[20];
int z;
int flag=0;
do
{
system("cls");
printf("\n\t需要修改的学生学号:");
scanf("%s",a);
for(z=0;zj;z++)
{
if(strcmp(stu[z].stuid,a)==0)
{
flag=1;
break; //break退出后,z++不会执行
}
}
if(flag==0)
{
printf("\t对不起,你请求学生信息不存在,请核实后重试!\n");
printf("\t按任意键继续......");
getch();
}
}while(flag==0);
system("cls");
printf("\n\t姓名:");
scanf("%s",stu[z].name);
printf("\n\n\t性别:");
scanf("%s",stu[z].sex);
printf("\n\n\t身份证号:");
scanf("%s",stu[z].idcard);
printf("\n\n\t学院:");
scanf("%s",stu[z].academe);
printf("\n\n\t专业:");
scanf("%s",stu[z].specialty);
printf("\n\n\t班级:");
scanf("%s",stu[z].classid);
printf("\n\n\t学号:");
scanf("%s",stu[z].stuid);
printf("\n\n\t生源地:");
scanf("%s",stu[z].home);
return 0;
}
int remove() //删除学生信息函数
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系统无任何可以删除的记录,请先行输入数据!");
printf("\n\n\t\t\t 按任意键返回......");
getch();
return 0;
}
char a[20];
int z;
int x;
int flag=0;
do
{
system("cls");
printf("\n\t需要删除的学生学号:");
scanf("%s",a);
for(z=0;zj;z++)
{
if(strcmp(stu[z].stuid,a)==0)
{
flag=1;
for(x=z;xj;x++)
{
strcpy(stu[x].name,stu[x+1].name);
strcpy(stu[x].sex,stu[x+1].sex);
strcpy(stu[x].idcard,stu[x+1].idcard);
strcpy(stu[x].academe,stu[x+1].academe);
strcpy(stu[x].specialty,stu[x+1].specialty);
strcpy(stu[x].classid,stu[x+1].classid);
strcpy(stu[x].stuid,stu[x+1].stuid);
strcpy(stu[x].stuid,stu[x+1].stuid);
}
j--;
printf("\n\t删除成功!");
printf("\n\t按任意键返回上级菜单......");
getch();
}
}
if(flag==0)
{
printf("\t对不起,你请求学生信息不存在,请核实后重试!\n");
printf("\t按任意键继续......");
getch();
}
}while(flag==0);
return 0;
}
int show_student() //单个显示学生信息函数
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系统无任何可以显示的记录,请先行输入数据!");
printf("\n\n\t\t\t 按任意键返回......");
getch();
return 0;
}
char a[20];
int z;
int flag=0;
do
{
system("cls");
printf("\n\t需要显示的学生学号:");
scanf("%s",a);
for(z=0;zj;z++)
{
if(strcmp(stu[z].stuid,a)==0)
{
flag=1;
system("cls");
printf("\n\t姓名:%s",stu[z].name);
printf("\n\n\t性别:%s",stu[z].sex);
printf("\n\n\t身份证号:%s",stu[z].idcard);
printf("\n\n\t学院:%s",stu[z].academe);
printf("\n\n\t专业:%s",stu[z].specialty);
printf("\n\n\t班级:%s",stu[z].classid);
printf("\n\n\t学号:%s",stu[z].stuid);
printf("\n\n\t生源地:%s",stu[z].home);
printf("\n\n\t按任意键返回上级菜单......");
getch();
}
}
if(flag==0)
{
printf("\t对不起,你请求显示的学生信息不存在,请核实后重试!\n");
printf("\t按任意键继续......");
getch();
}
}while(flag==0);
return 0;
}
int show_class() //显示整个班级学生信息函数
{
if(j==0)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t 系统无任何可以显示的记录,请先行输入数据!");
printf("\n\n\t\t\t 按任意键返回......");
getch();
return 0;
}
char a[20];
int z;
int x;
int flag=0;
do
{
system("cls");
printf("\n\t需要显示的班级号码:");
scanf("%s",a);
for(z=0;zj;z++)
{
if(strcmp(stu[z].classid,a)==0)
{
flag=1;
system("cls");
printf("\t%s %s 基本信息\n",stu[z].specialty,stu[z].classid);
for(x=0;xj;x++)
{
if(strcmp(stu[x].classid,a)==0)
{
printf("\n\n\t姓名:%s",stu[z].name);
printf("\n\t性别:%s",stu[z].sex);
printf("\n\t身份证号:%s",stu[z].idcard);
printf("\n\t学院:%s",stu[z].academe);
printf("\n\t专业:%s",stu[z].specialty);
printf("\n\t班级:%s",stu[z].classid);
printf("\n\t学号:%s",stu[z].stuid);
printf("\n\t生源地:%s",stu[z].home);
}
}
printf("\n\n\t按任意键返回上级菜单......");
getch();
}
}
if(flag==0)
{
printf("\t对不起,你请求显示的班级信息不存在,请核实后重试!\n");
printf("\t按任意键继续......");
getch();
}
}while(flag==0);
return 0;
}
有疑问联系我,975853545@qq.com
请采纳。
急求c语言程序设计 图书管理系统 源代码
#includestdio.h
#includemath.h
#includestdlib.h
#includestring.h
#define N 100 //书籍的最多本数
struct book
{ char title[30];
int number;
char author[30];
float price;
int store;
char borrower_name[20];
char borrower_gender[5];
int borrower_number;
}s[N];
int m=0;
void input(structbook *p); //输入图书信息
void save(structbook *p); //保存图书信息
void read(structbook *p); //读取图书信息
void search(structbook *p); //查找图书信息
void del(structbook *p); //删除图书信息
void borrow(structbook *p); //借阅图书
void retur(structbook *p); //归还图书
void main()
{
int x;
do
{
printf("**************************************菜单**************************************\n"
" *********** 1.输入图书信息 ********** \n"
" *********** 2.查找图书信息 ********** \n"
" *********** 3.删除图书信息 ********** \n"
" *********** 4.借阅图书 ********** \n"
" *********** 5.归还图书 ********** \n"
" *********** 0.退出 ********** \n");
printf("********************************************************************************\n");
printf("请在0-5中选择,以回车键结束\n");
scanf("%d",x);
switch(x)
{ case 1: input(s[0]);break;
case 2: search(s[0]);break;
case 3: del(s[0]);break;
case 4: borrow(s[0]);break;
case 5: retur(s[0]);break;
case 0: break;
}
}while(x!=0);
}
void input(structbook *p)
{ int y;
for(;p(s[0]+N);p++)
{ printf("请输入书名:");scanf("%s",p-title);
printf("请输入编号:"); scanf("%d",p-number);
printf("请输入作者:"); scanf("%s",p-author);
printf("请输入图书价格:"); scanf("%f",p-price);
printf("请输入图书数量:"); scanf("%d",p-store);
m++;
printf("第%d个信息已经输入完毕,是否继续?\n按任意键继续,按0键结束.",m);
scanf("%d",y);//读取是否继续
if(y==0)
{ save(s[0]);
read(s[0]);//调用读取文件函数
break;
}
}
}
void search(structbook *p)//查询模块
{ int n;
char name1[20];
char name2[20];
char c[3];
do
{ p=s[0];
printf("\t请选择查找方式:\n");//打印查询方式菜单
printf(" 1.按书名查找\n 2.按作者查找\n 0.返回\n");
printf("请在0-2中选择:\n\n");
scanf("%d",n);//读取查找方式
if(n==0) break;
switch(n)
{ case 1: printf("请输入书名:\n");scanf("%s",name1);break;
case 2: printf("请输入作者:\n");scanf("%s",name2);break;
}
for(;ps[m];p++)
{ read(s[0]);//调用读取函数
if(strcmp(p-title,name1)==0||strcmp(p-author,name2)==0)
{ printf("\n查找图书信息成功!\n");
printf("书名 编号 作者 价格 数量\n");
printf("%-10s%-10d%-10s%-10.2f%-10d\n",p-title,p-number,p-author,p-price,p-store);//打印信息
break;
}
}
printf("是否继续查找?\n“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",c);
}while(strcmp(c,"yes")==0);//判断是否结束
}
void del(structbook *p)//删除模块
{ int i;
struct book *p1,*p2;
char name1[20];
char name2[20];
char c[3];
int n;
do
{ p=s[0];
printf("请选择删除以方式回车键结束:\n");//打印删除方式菜单
printf( " 1.按书名删除\n 2.按作者删除\n 0.返回\n");
printf("请在0-2中选择:\n\n");
scanf("%d",n);//读取查找方//
if(n==0) break;
switch(n)
{case 1:printf("请输入书名:\n");
scanf("%s",name1);break;
case 2: printf("请输入作者:\n");
scanf("%s",name2);break;
}
read(s[0]); //调用读取函数
for(i=0;im;i++,p++)
{
if(strcmp(p-title,name1)==0||strcmp(p-author,name2)==0)
{ p1=p;
for(p2=p1+1;p2=s[m];p1++,p2++)
{
strcpy(p1-title,p2-title);
strcpy(p1-author,p2-author);
p1-number=p2-number;
p1-store=p2-store;
p1-price=p2-price;
m--;
printf("删除成功!!\n");
}
}
else {printf("没有该书记录!!");
break;}
}
printf("是否继续删除?“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",c); //读取是否继续
save(s[0]); //调用保存函数
}while(strcmp(c,"yes")==0); //判断是否继续删除
}
void borrow(structbook *p)//借书模块
{ int z;
char name3[20],name4[20];
char w[3];
do
{ p=s[0];
printf("请先查找您要借阅的图书!");
printf("请选择查找方式:\n");//打印查询方式菜单
printf(" 1.按书名查找\n 2.按作者查找\n 0.返回\n");
printf("请在0-2中选择:\n");
scanf("%d",z);//读取查找方式
if(z==0) break;
switch(z)
{ case 1: printf("请输入书名:\n");scanf("%s",name3);break;
case 2: printf("请输入作者:\n");scanf("%s",name4);break;
}
read(s[0]);//调用读取函数
for(;ps[m];p++)
{ if(strcmp(p-title,name3)==0||strcmp(p-author,name4)==0)
{
printf("\n查找图书信息成功!\n");
printf("书名 编号 作者 价格 数量\n");
printf("%-10s%-10d%-10s%-10.2fs%-10d\n",p-title,p-number,
p-author,p-price,p-store);//打印信息
printf("请输入您的姓名:");scanf("%s",p-borrower_name);
printf("请输入您的性别:");scanf("%s",p-borrower_gender);
printf("请输入您的学号:");scanf("%d",p-borrower_number);
p-store--;
printf("借书成功!\n");
printf("书名 编号 作者 价格 数量 借书人 性别 学号\n");
printf("%-10s%-10d%-10s%-10.2f%-10d%-10s%-10s%-10d\n",p-title,p-number,p-author,
p-price,p-store,p-borrower_name,p-borrower_gender,p-borrower_number);
break;
}
}
printf("是否继续借书??");
printf("“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",w); //读取是否继续
save(s[0]); //调用保存函数
}while(strcmp(w,"yes")==0); //判断是否继续借书
}
void retur(structbook *p)//还书模块
{ int e,f;
char name5[20];
char name6[20];
char t[3];
do
{ p=s[0];
printf("请先查找您要还的图目!");
printf("请选择查找方式:\n"); //打印查询方式菜单
printf(" 1.按书名查找\n 2.按作者查找\n 0.返回\n");
printf("请在0-2中选择:\n\n");
scanf("%d",e); //读取查找方式
if(e==0) break;
switch(e)
{ case 1: printf("请输入书名:\n");scanf("%s",name5);break;
case 2: printf("请输入作者:\n");scanf("%s",name6);break;
}
read(s[0]);//调用读取函数
for(;ps[m];p++)
{ if(strcmp(p-title,name5)==0||strcmp(p-author,name6)==0)
{ printf("\n查找图书信息成功!\n");
printf("确认还书请按“1”!");//确认是否还书
scanf("%d",f);
if(f==1)
{ strcpy(p-borrower_name,"0");
strcpy(p-borrower_gender,"0");
p-borrower_number=0;
p-store++;
printf("书名 编号 作者 价格 数量 借书人 性别 学号\n");
printf("%-10s%-10d%-10s%-10.2f%-10d%-10s%-10s%-10d\n",p-title,p-number,p-author,
p-price,p-store,p-borrower_name,p-borrower_gender,p-borrower_number);
//打印信息
}
break;
}
else {printf("没有该书记录!!");
break;}
}
printf("是否继续还书?\n");
printf("“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",t); //读取是否继续
save(s[0]); //调用保存函数
}while(strcmp(t,"yes")==0); //判断是否继续还书
}
void save(structbook *p)//保存文件
{ FILE *fp,*fp1;
int i;
if((fp=fopen("tushu.txt","wb"))==NULL)//打开文件并判断是否出错
{ printf("创建文件失败!\n\n");//打印出错提示
getchar(); return;
}
if((fp1=fopen("book.txt","wb"))==NULL)//打开文件并判断是否出错
{ printf("创建文件失败!\n\n");//打印出错提示
getchar(); return;
}
for(i=0;im;i++,p++)
if(fwrite(p,sizeof(structbook),1,fp)==0)//向文件写入数据,并判断是否出错
printf("向文件输入数据失败!\n\n");
fprintf(fp1,"%d",m);
fclose(fp);//关闭文件
fclose(fp1);//关闭文件
}
void read(structbook *p)//从文件读取信息模块
{ FILE *fp,*fp1;
int i;
if((fp=fopen("tushu.txt","rb"))==NULL)//打开文件,并判断是否出错
{ printf("出错,请检查文件是否存在,按任意键返回住菜单");//打印出错提示
getchar();
}
if((fp1=fopen("book.txt","rb"))==NULL)//打开文件并判断是否出错
{ printf("创建文件失败!\n\n");//打印出错提示
getchar(); return;
}
fscanf(fp1,"%d",m);
fclose(fp1);//关闭文件
for(i=0;im;i++,p++)
{ fread(p,sizeof(struct book),1,fp);//从文件中读取信息
}
fclose(fp);//关闭文件
}
你把保存的文件地址自己修改一下就可以了。。希望能帮到你
急求C语言编写的图书管理系统源代码,具体要求如下
/*这有个以前用过的程序,你可以自己改改使用,但是有些功
能好像有问题,会中断运行。至于程序的缩进式格式就你自己
敲回车和退格解决吧,不然代码看起来会很乱不好看。*/
#includestdio.h
#includestring.h
#includeconio.h
#includestdlib.h
#includectype.h
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,用于存放借出的书籍*/
{
int carnum;
char lendbook[10];
}student[1000];
struct employ /*定义职工类型*/
{
int employnum;
char employname[15];
int employage;
char employsex[2];
char employleve[10];
long int employtage;
}employ[50];
struct book /*定义书的类型*/
{
int booknum;
char bookname[10];
char bookcreat[10];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
{
n=i;
fclose(fp);
printf("请输入你要还的书的名字\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*删除还掉的书的借书记录*/
}
fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件的记录*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件*/
fclose(fp2);
printf("还书完毕,按任意键返回\n");
getch();
return 1;
}
}
printf("你没有借这样的书,任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
return 0;
}
}
printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
}
findbook()
{
FILE *fp;
char bookname[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的作者名\n");
scanf("%s",bookcreat);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键\n");
getch();
return n;
}
chabook()
{
char ch5;
do
{
printf("---------------欢迎进入图书查询系统!--------------\n");
printf(" 1:按书名查找\n");
printf(" 2:按作者查找\n");
printf(" 0:返回\n");
printf("请输入0--2,其他输入非法!\n");
scanf("%s",ch5);
switch(ch5)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch5!='0');
return FALSE;
}
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("请输入你要借阅的书的名字\n");
scanf("%s",student[n].lendbook);
fp=fopen("book.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;}
else
fclose(fp);
fp=fopen("record.txt","a+");
student[n].carnum=carnum;
fwrite(student[n],sizeof(struct student),1,fp);
fclose(fp);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
book[i].turefalse=0;
fwrite(book[i],sizeof(struct book),1,fp2);
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借书完毕,按任意键返回\n");
getch();
return;
}
}
printf("不存在这样的书,任意键返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡号不存在,请申请新卡,按任意键返回\n");
fclose(fp);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡卡号:%d 姓名:%s 班级:%d\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的卡号\n");
printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%d",carnum);
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("请你输入卡号\n");
scanf("%d",car[i].carnum);
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",car[i].studentclass);
fwrite(car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getch();
}
changemploy()
{
FILE *fp,*fp2;
char employname[10],choice;
int i;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的职工的名字\n");
scanf("%s",employname);
for(i=0;fread(employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employ[i].employname,employname)==0)
{
printf("你所要修改的职工的资料如下,请选择你要修改的内容\n");
printf("职工号:%d职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d\n",employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
printf("2:修改职工名\n");
printf("3:修改职工年龄\n");
printf("4:修改职工工资\n");
printf("5:修改职工学历\n");
printf("请输入1-5:");
scanf("%s",choice);
switch(choice)
{
case '1':
{
printf("请输入新的职工号\n");
scanf("%d",employ[i].employnum);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '2':
{
printf("请输入新的职工姓名\n");
scanf("%s",employ[i].employname);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '3':
{
printf("请输入新的年龄\n");
scanf("%d",employ[i].employage);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '4':
{
printf("请输入新的职工工资\n");
scanf("%d",employ[i].employtage);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '5':
{
printf("请输入新的职工学历\n");
scanf("%s",employ[i].employleve);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}
default:printf("没有这样的操作");break;
}
continue;
}
fwrite(employ[i],sizeof(struct employ),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
delemploy()
{
FILE *fp,*fp2;
int i;
char employname[10],choice;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的职工名\n");
printf("如果你输入的职工存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",employname);
for(i=0;fread(employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employname,employ[i].employname)!=0)
{
fwrite(employ[i],sizeof(struct employ),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该职工信息?删除后的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return TRUE;
}
else
{
printf("按任意键返回\n");
getch();
return FALSE;
}
}
employcount()
{
FILE *fp;
int i,n=0;
fp=fopen("employ.txt","r");
for(i=0;fread(employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
printf("第%d职工的信息如下:\n职工号:%d 职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d\n",n+1,employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
n++;
}
fclose(fp);
printf("目前共有%d个职工\n",n);
printf("按任意键返回\n");
}
addemploy()
{
FILE *fp;
char choice='y';
int i=1;
fp=fopen("employ.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入职工号码\n");
scanf("%d",employ[i].employnum);
printf("请你输入职工名\n");
scanf("%s",employ[i].employname);
printf("请输入职工年龄\n");
scanf("%d",employ[i].employage);
printf("请你输入性别\n");
scanf("%s",employ[i].employsex);
printf("请你输入职工的学历水平\n");
scanf("%s",employ[i].employleve);
printf("请输入职工的工资\n");
scanf("%d",employ[i].employtage);
fwrite(employ[i],sizeof(struct employ),1,fp);
printf("是否要输入下个职工信息?\n");
scanf("%s",choice);
}
printf("按任意键返回\n");
fclose(fp);
}
addbook()
{
FILE *fp;
int i=0;
char choice='y';
fp=fopen("book.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入第%d本书的序号\n",i+1);
scanf("%d",book[i].booknum);
printf("请你输入书名\n");
scanf("%s",book[i].bookname);
printf("请你输入书的作者\n");
scanf("%s",book[i].bookcreat);
printf("请设为1或0,1代表书还没人借,0表示书已经借出,设其他值,程序运行时无法得出正常结果\n");
printf("请你设定书的状态\n");
scanf("%d",book[i].turefalse);
fwrite(book[i],sizeof(struct book),1,fp);
printf("是否要输入下本书\n");
scanf("%s",choice);
}
fclose(fp);
}
bookcount()
{
FILE *fp;
int i,n=0;
fp=fopen("book.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(book[i].booknum!=0strlen(book[i].bookname)!=0strlen(book[i].bookcreat)!=0)
{
printf("第%d本书序号:%d 书名:%s 作者:%s 状态:%d\n",i+1,book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].turefalse);
n=n+1;
}
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
}
delbook()
{
FILE *fp,*fp2;
int i;
char bookname[10],choice;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的书名\n");
printf("如果你输入的书名存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)!=0)
{
fwrite(book[i],sizeof(struct book),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该书籍?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
changebook()
{
FILE *fp,*fp2;
char bookname[10],choice;
int i;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的书籍的书字\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,bookname)==0)
{
printf("你所要修改的书的资料如下,请选择你要修改的内容\n");
printf("序号:〈%d〉 书名:〈%s〉 作者:〈%s〉 \n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf("1:修改书的序号\n");
printf("2:修改书名\n");
printf("3:修改作者\n");
printf("请输入1-3:");
scanf("%s",choice);
switch(choice)
{
case '1':
{
printf("请输入新的序号\n");
scanf("%d",book[i].booknum);
fwrite(book[i],sizeof(struct book),1,fp2);
}break;
case '2':
{
printf("请输入新的书名\n");
scanf("%s",book[i].bookname);
fwrite(book[i],sizeof(struct book),1,fp2);
}break;
case '3':
{
printf("请输入新的作者\n");
scanf("%s",book[i].bookcreat);
fwrite(book[i],sizeof(struct book),1,fp2);
}break;
defaut:printf("没有这样的操作");break;
}
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
main()
{
char ch1,ch2,ch3,ch4,ch5;
do
{
printf("\t\t请你选择操作类型:\n");
printf(" 1:查阅图书\n");
printf(" 2:借阅图书\n");
printf(" 3:管理系统\n");
printf(" 4:还书\n");
printf(" 0:退出\n");
printf("请输入0--4\n");
scanf("%s",ch1);
switch(ch1)
{
case '1':chabook();break;
case '2':lendbook();;break;
case '3':{
do
{
printf("---------------欢迎进入管理系统!--------------\n");
printf(" 1:增加图书\n");
printf(" 2:删除图书\n");
printf(" 3:修改图书资料\n");
printf(" 4:书籍统计\n");
printf(" 5:职工管理系统\n");
printf(" 6:学生管理系统\n");
printf(" 0:返回\n");
printf("请输入0--6,其他输入非法!\n");
scanf("%s",ch2);
switch(ch2)
{
case '1':addbook();
break;
case '2':delbook();break;
case '3':changebook();break;
case '4':bookcount();getch();break;
case '5':{do
{
printf("---------------欢迎进入职工管理系统!--------------\n");
printf(" 1:增加员工\n");
printf(" 2:删除员工\n");
printf(" 3:修改员工资料\n");
printf(" 4:员工统计\n");
printf(" 0:返回\n");
printf("请输入0--4,其他输入非法!\n");
scanf("%s",ch3);
switch(ch3)
{
case '1':addemploy();getch();break;
case '2':delemploy();break;
case '3':changemploy();break;
case '4':employcount();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch3!='0');}break;
case '6':{
do
{
printf("---------------欢迎进入学生管理系统!--------------\n");
printf(" 1:申请新卡\n");
printf(" 2:删除卡号\n");
printf(" 3:借书统计\n");
printf(" 4:卡号统计\n");
printf(" 0:返回\n");
printf("请输入0--4,其他输入非法!\n");
scanf("%s",ch4);
switch(ch4)
{
case '1':addcar();break;
case '2':delcar();break;
case '3':lendcount();break;
case '4':carcount();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch4!='0');}break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch2!='0');}break;
case '4':huanbook();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch1!='0');
}
急求用C语言编写的图书管理系统源代码
#includestdio.h
#includestring.h
#includeconio.h
#includestdlib.h
#includectype.h
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,用于存放借出的书籍*/
{
int carnum;
char lendbook[10];
}student[1000];
struct employ /*定义职工类型*/
{
int employnum;
char employname[15];
int employage;
char employsex[2];
char employleve[10];
long int employtage;
}employ[50];
struct book /*定义书的类型*/
{
int booknum;
char bookname[10];
char bookcreat[10];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
{
n=i;
fclose(fp);
printf("请输入你要还的书的名字\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*删除还掉的书的借书记录*/
}
fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件的记录*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件*/
fclose(fp2);
printf("还书完毕,按任意键返回\n");
getch();
return 1;
}
}
printf("你没有借这样的书,任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
return 0;
}
}
printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
}
findbook()
{
FILE *fp;
char bookname[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的作者名\n");
scanf("%s",bookcreat);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键\n");
getch();
return n;
}
chabook()
{
char ch5;
do
{
printf("---------------欢迎进入图书查询系统!--------------\n");
printf(" 1:按书名查找\n");
printf(" 2:按作者查找\n");
printf(" 0:返回\n");
printf("请输入0--2,其他输入非法!\n");
scanf("%s",ch5);
switch(ch5)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch5!='0');
return FALSE;
}
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("请输入你要借阅的书的名字\n");
scanf("%s",student[n].lendbook);
fp=fopen("book.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;}
else
fclose(fp);
fp=fopen("record.txt","a+");
student[n].carnum=carnum;
fwrite(student[n],sizeof(struct student),1,fp);
fclose(fp);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
book[i].turefalse=0;
fwrite(book[i],sizeof(struct book),1,fp2);
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借书完毕,按任意键返回\n");
getch();
return;
}
}
printf("不存在这样的书,任意键返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡号不存在,请申请新卡,按任意键返回\n");
fclose(fp);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡卡号:%d 姓名:%s 班级:%d\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的卡号\n");
printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%d",carnum);
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("请你输入卡号\n");
scanf("%d",car[i].carnum);
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",car[i].studentclass);
fwrite(car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getch();
}
跪求c语言教务管理系统源代码
#include stdio.h
#include string.h
#include windows.h
struct student
{
long int num;
char name[20];
int age;
char sex[4];
char b[30];
char p[15];
};
int n=0;
struct student stu[100];
struct student *p;
void lr();
void ll();
void cx();
void xg();
void sc();
void main()
{
int z;
printf("+---------------------------+\n");
printf("| 欢迎使用学生信息管理系统 |\n");
printf("+---------------------------+\n");
printf("提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n");
do
{
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ 主菜单 |\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----录入学生信息 |\n");
printf("\t\t\t+ [2]----浏览学生信息 |\n");
printf("\t\t\t+ [3]----查询学生信息 |\n");
printf("\t\t\t+ [4]----删除学生信息 |\n");
printf("\t\t\t+ [5]----修改学生信息 |\n");
printf("\t\t\t+ [0]----退出系统 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", z);
system("color 2f");
switch(z)
{
case 0 : break;
case 1 :lr();break;
case 2 :ll();break;
case 3 :cx();break;
case 4 :sc();break;
case 5 :xg();break;
default:printf("\n无效选项!");
}
}
while(z!= 0);
}
void lr()/*录入函数*/
{
int y;
if(n==0)
p=stu;
do
{
printf("--------------------\n");
printf("请输入学生的学号:");
scanf("%ld",p-num);
printf("请输入学生的姓名:");
scanf("%s",p-name);
printf("请输入学生的年龄:");
scanf("%d",p-age);
printf("请输入学生的性别:");
scanf("%s",p-sex);
printf("请输入学生的地址:");
scanf("%s",p-b);
printf("请输入学生的电话:");
scanf("%s",p-p);
n++;
p++;
printf("\n1.继续输入.\n0.输入完毕.\n");
printf("请选择:");
scanf("%d",y);
}
while(y==1);
printf("提示:输入完毕!你一共输入%d个\n",n);
}
void ll()/*浏览函数*/
{
int i,j;
if(n!=0)
{ printf("学生总数:%d\n", n);
printf("学号\t姓名\t年龄\t性别\t地址\t\t电话\n");
printf("-----------------------------------------------------\n");
for(i=0;in;i++)
printf("%ld\t%s\t%d\t%s\t%s\t\t%s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].b,stu[i].p);
}
else printf("提示:无学生数据,请输入数据!");
}
void cx()/*查询函数*/
{
int c;
int w,i,j=0;
char name[20];
if(n!=0)
{
do{ printf("\n");
printf("+--------------------+\n");
printf("| 按学号查询 请按 1 |\n");
printf("| 按姓名查询 请按 2 |\n");
printf("| 取消 请按 0 |\n");
printf("+--------------------+\n");
printf("请输入您的选择:");
scanf("%d", c);
switch(c)
{
case 0:break;
case 1:
printf("请输入学生的学号;");
scanf("%ld", w);
printf("\n");
for(i=0;in;i++)
if(stu[i].num==w)
{
printf("\n学号\t姓名\t年龄\t性别\t地址\t\t电话\n");
printf("%ld\t%s\t%d\t%s\t%s\t\t%s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].b,stu[i].p);
j=1;
}
if(j==0)
printf("提示:没有该学生记录,请核对!");
break;
case 2:
printf("请输入学生的姓名:");
scanf("%s", name);
printf("\n");
for(i=0;in;i++)
if(strcmp(name,stu[i].name)==0)
{
printf("\n学号\t姓名\t年龄\t性别\t地址\t\t电话\n");
j=1;
printf("%ld\t%s\t%d\t%s\t%s\t\t%s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].b,stu[i].p);
}
if(j==0)
printf("提示:没有该学生记录,请核对!");
break;
default:
printf("\n提示:无效选项!");
break;
}
}while(c!= 0);
}else printf("提示:无学生数据,请输入数据!");
return;
}
void xg()/*修改函数*/
{
long int num;
int i,j,c;
if(n!=0)
{
printf("请输入您要修改的学生的学号:");
scanf("%ld", num);
printf("\n");
for(i=0;in;i++)
if(stu[i].num==num)
j=i;
do{
printf("请选择您要修改的学生的信息内容:\n");
printf("+----------------------+\n");
printf("| 姓名 请按 1 |\n");
printf("| 年龄 请按 2 |\n");
printf("| 性别 请按 3 |\n");
printf("| 学号 请按 4 |\n");
printf("| 地址 请按 5 |\n");
printf("| 电话 请按 6 |\n");
printf("| 取消 请按 0 |\n");
printf("+----------------------+\n");
printf("请输入您的选择:");
scanf("%d", c);
printf("\n");
switch(c)
{
case 0:break;
case 1:printf("请输入新姓名:");
scanf("%s",stu[j].name);
break;
case 2:printf("请输入新年龄:");
scanf("%d",stu[j].age);
break;
case 3:printf("请输入新性别:");
scanf("%s",stu[j].sex);
break;
case 4:printf("请输入新学号:");
scanf("%ld",stu[j].num);
break;
case 5:printf("请输入新地址:");
scanf("%s",stu[j].b);
break;
case 6:printf("请输入新电话:");
scanf("%s",stu[j].p);
break;
default:
printf("\n无效选项!");
break;
}
}while(c!= 0);
}else printf("提示:无学生数据,请输入数据!");
}
void sc()/*删除函数*/
{
long int num;
int i,j,e;
if(n!=0)
{
printf("学号\t姓名\t年龄\t性别\t地址\t\t电话\n");
printf("-----------------------------------------------------\n");
for(i=0;in;i++)
printf("%ld\t%s\t%d\t%s\t%s\t\t%s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].b,stu[i].p);
printf("请输入您要删除的学生的学号:");
scanf("%ld", num);
printf("\n");
for(i=0;in;i++)
if(num==stu[i].num)
j=i;
if(j!=(n-1))
{
for(e=i-1;en;e++,j++)
{
stu[j].num=stu[j+1].num;
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j].sex,stu[j+1].sex);
stu[j].age=stu[j+1].age;
strcpy(stu[j].b,stu[j+1].b);
strcpy(stu[j].p,stu[j+1].p);
n--;p--;
}
}else {n--;p--;}
printf("提示:删除完毕!");
}else printf("提示:无学生数据,请输入数据!");
}
c语言 图书管理系统 源代码
#include
#include
#include
#include
#include
struct book{
char number[100];
char tittle[100];
char writer[100];
char publisher[100];
char date[100];
char price[100];
char status[100];
char reader[100];
};
void search_book();
void borrow_book();
void return_book();
void add_book();
void delete_book();
void modify_book();
void scan_book();
int main()
{
int c1=0,c2,c3;
int l,x,z;
while(1)
{
system("color 2C");
printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");
printf("\t\t\t* [1] 用户登录 *\n");
printf("\t\t\t* [2] 管理员登录 *\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\n");
printf("请选择操作 :");
scanf("%d",c1);
system("cls");
break;
}
if(c1==1)
{
while(1){
system("color 2C");
printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");
printf("\t\t\t* [1] 查询图书 *\n");
printf("\t\t\t| [2] 借阅图书 |\n");
printf("\t\t\t* [3] 借图书 *\n");
printf("\t\t\t* [4] 浏览图书信息 *\n");
printf("\t\t\t| [5] 退图书管理系统 |\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\n");
printf("请选择操作 :");
scanf("%d",c2);
getchar();
switch(c2)
{
case 1:search_book(); break;
case 2:borrow_book(); break;
case 3:return_book(); break;
case 4:scan_book(); break;
case 5:system("cls"); return 0;
}
}
}
if(c1==2)
{
while(1){
system("color 2C");
printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");
printf("\t\t\t| [1] 添加图书 |\n");
printf("\t\t\t* [2] 删减图书 *\n");
printf("\t\t\t| [3] 修改图书信息 |\n");
printf("\t\t\t* [4] 浏览图书信息 *\n");
printf("\t\t\t| [5] 退图书管理系统 |\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\n");
printf("请选择操作 :");
scanf("%d",c3);
getchar();
switch(c3)
{
case 1:add_book(); break;
case 2:delete_book(); break;
case 3:modify_book(); break;
case 4:scan_book(); break;
case 5:system("cls"); return 0;
}
}
}
}
/*查询图书*/
void search_book()
{
FILE*fp;
struct book n;
struct book nn;
int l,r;
char x,z;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");
while(1)
{
l=0;
system("cls");
printf("请输入图书名称:");
scanf("%s",n.tittle);
fflush(stdin);
rewind(fp);
while(1)
{
fread(nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle );
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("没要查询图书\n\n ");
}
else
{
printf("查询图书:");
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n\n\n");
}
printf("否继续查询图书 ? [(y)/否(n)] ? \n\n");
do
{
x=getche();
}while(x!='n'x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//添加
void add_book()
{
FILE *fp;
struct book n;
struct book nn;
char x,z;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");
do
{
system("cls");
do
{
l=0;
printf("\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
fflush(stdin);
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
system("cls");
rewind(fp);
while(!feof(fp))
{
fread(nn,sizeof(nn),1,fp);
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
printf(" 该图书已存请输入新图书信息: \n\n");
break;
}
}
}while(l);
fwrite(n,sizeof(n),1,fp);
printf("\n");
printf("否继续输入新图书信息[y/n] \n\n");
do
{
x=getche();
}while(x!='n'x!='y');
}while(x=='y');
fclose(fp);
system("cls");
}
//删除图书
void delete_book()
{
FILE *fp,*fp1;
char x,z;
struct book n;
struct book nn;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要删除图书名: \n\n");
fflush(stdin);
scanf("%s",n.tittle);
rewind(fp);
while(1)
{
fread(nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书 \n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
printf("确认删除图书信息 [(y)/否(n)]\n\n");
do
{
z=getche();
}while(z!='n'z!='y');
if(z=='n')
break;
else
{
fp1=fopen("F:\\课程设计\\图书管理系统new.txt","wb");
rewind(fp);
while(1)
{
fread(nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r!=0)
fwrite(nn,sizeof(nn),1,fp1);
}
fclose(fp);
fclose(fp1);
fp=fopen("F:\\课程设计\\图书管理系统.txt","wb");
fp1=fopen("F:\\课程设计\\图书管理系统new.txt","rb");
while(1)
{
fread(nn,sizeof(nn),1,fp1);
if(feof(fp1))
break;
fwrite(nn,sizeof(nn),1,fp);
}
fclose(fp);
fclose(fp1);
}
}
printf("\n");
printf("否继续删除图书信息 [(y)/否(n)] \n");
do
{
x=getche();
}while(x!='n'x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//修改图书信息
void modify_book()
{
FILE *fp;
struct book n;
struct book nn;
int l,r;
char x,z;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
printf("\n");
system("cls");
printf("请输入需要修改图书名: \n\n");
fflush(stdin);
scanf("%s",n.tittle);
system("cls");
rewind(fp);
while(1)
{
fread(nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书信息 \n\n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("请依修改图书信息\n\n\n");
fflush(stdin);
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,sizeof(nn),1);
fwrite(n,sizeof(nn),1,fp);
}
printf("\n");
printf(" 否继续修改用户信息[y/n]? \n\n");
do
{
x=getch();
}while(x!='n'x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//借书
void borrow_book()
{
FILE*fp;
struct book n;
struct book nn;
char x,z;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要借阅图书名: \n");
fflush(stdin);
scanf("%s",n.tittle);
rewind(fp);
while(1)
{
fread(nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书 \n");
}
else
{ printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
fflush(stdin);
printf("请输入图书信息并修改库状态及借阅者信息");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,sizeof(nn),1);
fwrite(n,sizeof(nn),1,fp);
}
printf("\n");
printf(" 否继续借书 [(y)/否(n)] \n\n");
do
{
x=getch();
}while(x!='n'x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//书
void return_book()
{
FILE*fp;
struct book n;
struct book nn;
char x,z;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要借图书名: \n");
fflush(stdin);
scanf("%s",n.tittle);
rewind(fp);
while(1)
{
fread(nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书 \n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
fflush(stdin);
printf("请输入图书信息并修改库状态 \n\n");
printf("****************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,-(int)sizeof(nn),1);
fwrite(n,sizeof(nn),1,fp);
}
printf("\n");
printf("否继续书 [(y)/否(n)] \n");
do
{
x=getche();
}while(x!='n'x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//浏览
void scan_book()
{
FILE*fp;
char x,z;
struct book n;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");
rewind(fp);
system("cls");
while(1)
{
fread(n,sizeof(n),1,fp);
if(feof(fp))
break;
else
{
printf("********************************************\n");
printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
printf("\n");
}
}
printf("\n");
printf("主菜单请按车");
do
{
x=getche();
}while(x!='\r');
if(x=='\r')
{
fclose(fp);
system("cls");
}
}