大一c语言课程设计:图书馆管理系统。

图书管理系统,功能齐全拿来就能用

1.主界面

 

代码段

void main()
{	
	int n;
	Sleep(300);
	loop1:
	tongji();	
	printf("\n\n\t\t********************************图书管理系统**************************************");
	printf("\n\n\n\t\t\t*********欢迎使用图书馆管理系统,请选择你需要的操作**********");
	printf("\n\n\n\n当前图书馆藏书一共有%d本。",tushuzongshu);
	printf("\n\n\n\t\t\t\t\t\t1.图书录入系统");
	printf("\n\n\n\t\t\t\t\t\t2.图书查询系统");
	printf("\n\n\n\t\t\t\t\t\t3.图书删除系统");
	printf("\n\n\n\t\t\t\t\t\t4.图书修改系统");
	printf("\n\n\n\t\t\t\t\t\t5.图书借阅次数最值系统");
	printf("\n\n\n\t\t\t\t\t\t6.退出图书管理系统");
	printf("\n\n\n\t\t\t\t\t\t请选择您所需要的操作:    ");
	scanf("%d",&n);
	if(n>=1&&n<=5){
		system("ClS");
	} 
	else if(n==6){
		system("ClS");
		printf("再次按下回车键退出,谢谢使用!");
	}
	else{
		system("CLS");
		goto loop1;
	}
	switch(n)
	{
		case 1:luru();goto loop1;
		case 2:chaxun();goto loop1;
		case 3:shanchu();goto loop1;
		case 4:xiugai();goto loop1;
		case 5:chaxuncishu();goto loop1;
	}
}

 2.图书录入界面

运用文件录入多次使用

 

代码段

int luru()
{	
	FILE *fp=NULL;
	book stu;
	char flag = 'y';
	fp=fopen("book1.dat","ab+");
	
	while((flag == 'y'||flag == 'Y')){
		printf("\n\n\n\n\t\t\t\t****************这里是图书录入系统*******************");
		printf("\n请输入图书id: ");
		scanf("%d",&stu.num);
		printf("\n请输入图书书名: ");
		scanf("%s",stu.name);
		printf("\n请输入图书作者: ");
		scanf("%s",stu.author_name);
		printf("\n请输入图书出版社: ");
		scanf("%s",stu.chubanshe);
		stu.jieyucishu=0;
		
		fwrite(&stu,LEN,1,fp);
		fflush(stdin);
		
		printf("\n\n\n是否继续输入?继续请输入y或Y:");
		scanf("%c",&flag); 
	}
	system("CLS");
	fclose(fp);
	return;
	
} 

 3.图书查询界面

根据输入书的数据与文件中数据进行比对 ,查找后输出。

代码段

void chaxun()
{
	FILE *fp=NULL;
	book stu;
	int n,i,j,t=-1;
	int nums;
	char name[N],authors_name[40],chubanshe1[40];
	loop3:
	fp = fopen("book1.dat","rb+");		
	printf("\n\n\n\n\t\t\t\t****************这里是图书查询系统*******************");
	printf("\n\t\t\t\t\t请选择你所查询的方式:");
	printf("\n\n\t\t\t\t\t1.编号查询;");
	printf("\n\n\t\t\t\t\t2.书名查询;"); 
	printf("\n\n\t\t\t\t\t3.作者查询;"); 
	printf("\n\n\t\t\t\t\t4.出版社查询;");
	printf("\n\n\t\t\t\t\t5.返回主菜单;");
	printf("请输入您的选择:");
	scanf("%d",&n);
	system("CLS");
	if(n==1){
		printf("\n\t\t\t\t\t\t请您输入图书编号:");
		scanf("%d",&nums);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(nums==stu.num)
			{
				t=1;
				printf("\n\t\t\t\t\t此书为%s,借阅数为%d,是否选择借阅?1.是   2.否",stu.name,stu.jieyucishu);
				printf("\n请输入你的选择:");
				scanf("%d",&j);
				if(j==1){
					stu.jieyucishu++;
					fseek(fp,-4,SEEK_CUR);
					fwrite(&stu.jieyucishu,sizeof(int),1,fp);
					printf("\n借阅成功!请从管理员处领取书籍。3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000); 
					system("CLS");
					goto loop3;
				}
				else{
					printf("\n3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000);
					system("CLS");
					goto loop3;
				} 
			}
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop3;
		}
	}

	else if(n==2){
		printf("\n\t\t\t\t\t请输入书名:");
		scanf("%s",&name);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(name,stu.name) == 0)
			{
				t=1;
				printf("\n\t\t\t\t\t此书为%s,借阅数为%d,是否选择借阅?1.是   2.否",stu.name,stu.jieyucishu);
				printf("\n请输入你的选择:");
				scanf("%d",&j);
				if(j==1){
					stu.jieyucishu++;
					fseek(fp,-4,SEEK_CUR);
					fwrite(&stu.jieyucishu,sizeof(int),1,fp);
					printf("\n借阅成功!请从管理员处领取书籍。3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000);
					system("CLS"); 
					goto loop3;
				}
				else{
					printf("\n3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000);
					system("CLS");
					goto loop3;
				}				
			}
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop3;
		}
	
	}

	else if(n==3){
		printf("\n\t\t\t\t\t请输入书作者:");
		scanf("%s",&authors_name);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(authors_name,stu.author_name) == 0){
				printf("\n\t\t\t\t\t作者的图书有%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);
		if(t==-1){
			printf("\n\t\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop3;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t\t是否返回主菜单?1.是  2.否");
			t=-1;
			scanf("%d",&j);
			if(j==1){
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS"); 
			}
			else{
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS");
			} 
		}
	}
	else if(n==4){
		printf("\n\t\t\t\t\t请输入书出版社:");
		scanf("%s",&chubanshe1);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(chubanshe1,stu.chubanshe) == 0){
				printf("\n\t\t\t\t\t出版社的图书有%s\n",stu.name);
			}
			t=1;
		}		
		fclose(fp);
		if(t==-1){
			printf("\t\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			goto loop3;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t\t是否返回主菜单?1.是  2.否");
			scanf("%d",&j);
			if(j==1){
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS"); 
			}
			else{
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS");
			} 
		}
	}
	else if(n==5){
		printf("\n\t\t\t\t\t3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");
	} 
}

4.图书修改

输入修改图书数据并在文件中查找后对文件中的修改图书数据进行全修改。

代码段

void xiugai(){
	book stu;
	FILE *fp;
	int n,m,t=-1;
	int nums;
	char name[N],authors_name[40],chubanshe1[40];
	loop4:
	fp = fopen("book1.dat","rb+");
	printf("\n\n\n\n\t\t\t\t****************这里是图书修改系统*******************");
	printf("\n\t\t\t\t\t请选择你所需要修改图书的信息:");
	printf("\n\n\t\t\t\t\t1.编号;");
	printf("\n\n\t\t\t\t\t2.书名;"); 
	printf("\n\n\t\t\t\t\t3.作者;"); 
	printf("\n\n\t\t\t\t\t4.出版社;");
	printf("\n\n\t\t\t\t\t5.返回主菜单;");
	printf("\n\n\t\t\t\t\t请输入您的选择:");	
	scanf("%d",&n);
	system("CLS");
	if(n==1){
		printf("\n\n\t\t\t\t\t请输入修改图书的编号:");
		scanf("%d",&nums); 
		fseek(fp, 0, SEEK_SET);
		while (fread(&stu, LEN, 1, fp))
		{

			if (nums==stu.num)
			{
				printf("\n\n\t\t\t\t\t请重新输入图书编号:   ");
				scanf("%d", &stu.num);
	
				printf("\n\n\t\t\t\t\t请重新输入书名:    ");
				scanf("%s", &stu.name);

				printf("\n\n\t\t\t\t\t请重新输入书籍作者: ");
				scanf("%s", &stu.author_name);

				printf("\n\n\t\t\t\t\t请重新输入图书出版社: ");
				scanf("%s", &stu.chubanshe);

				fflush(stdin);
				fseek(fp, 0-LEN, SEEK_CUR);
				fwrite(&stu, LEN, 1, fp);
				fclose(fp);
			}
		}
		printf("\n\t\t\t\t图书修改完成,3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");
	}
	if(n==2){
		printf("\n\n\t\t\t\t\t请输入修改图书的书名:");
		scanf("%s",&name); 
		fseek(fp, 0, SEEK_SET);
		
		while (fread(&stu, LEN, 1, fp))
		{

			if (strcmp(name,stu.name) == 0)
			{
				printf("请重新输入图书id:   ");
				scanf("%d", &stu.num);

				printf("请重新输入书名:    ");
				scanf("%s", &stu.name);

				printf("请重新输入书籍作者  : ");
				scanf("%s", &stu.author_name);
	
				printf("请重新输入图书出版社  : ");
				scanf("%s", &stu.chubanshe);

				fflush(stdin);
				fseek(fp,0-LEN, SEEK_CUR);
				fwrite(&stu, LEN, 1, fp);
				fclose(fp);
			}
		}
		printf("\n\t\t\t\t图书修改完成,3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");		
	}
	if(n==3){
		printf("\n\t\t\t\t请输入作者名称:");
		scanf("%s",&authors_name);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(authors_name,stu.author_name) == 0){
				printf("\n\t\t\t\t\t此出版社的图书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
		} 
		else if(t!=-1){
			printf("\n3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
			}							
		}
	
	if(n==4){
		printf("\n\t\t\t\t请输入出版社名称:");
		scanf("%s",&chubanshe1);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(chubanshe1,stu.chubanshe) == 0){
				printf("\n\t\t\t\t\t此出版社的图书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
		} 
		else if(t!=-1){ 
			printf("\n3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
			}
		}
	if(n==5){
		printf("\n3秒后返回主菜单。");
		Sleep(3000);
		system("CLS");
	}
}

5.图书修改

 创建新文件,将除删除书的其他书数据录入新文件夹(rwrite函数),再删除原文件(remove函数),之后重命名新文件夹为之前删除的文件夹名称。

代码段

int shanchu()
{
	int n,i,j,t=-1;
	int nums;
	book stu;
	FILE *fp;
	
	char name[20],authors_name[40],chubanshe1[40];
	loop2:
	fp = fopen ("book1.dat","rb+");
	printf("\n\n\n\n\t\t\t\t****************这里是图书删除系统*******************");
	printf("\n\t\t\t\t请输入您想要删除的书的数据:");
	printf("\n\t\t\t\t1.书籍编号。");
	printf("\n\t\t\t\t2.书籍书名。");
	printf("\n\t\t\t\t3.书籍作者。");
	printf("\n\t\t\t\t4.书籍出版社。");
	printf("\n\t\t\t\t5.返回主菜单。"); 
	printf("\n\t\t\t\t请输入您的选择:");
	scanf("%d",&n);
	system("CLS");
	if(n==1){
		printf("\n\t\t\t\t请输入书籍编号:");
		scanf("%d",&nums);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(nums==stu.num){
				t=1;
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
				printf("\n\t\t\t\t是否确定删除图书%s。1.是   2.否",stu.name);
				scanf("%d",&j);
				if(j==1){
					printf("\n\t\t\t\t图书删除成功");
					printf("\n\t\t\t\t3秒后返回之前界面。");
					fseek(fp,0,SEEK_SET);
					FILE *fp1;
					fp1 = fopen("linshi.dat","ab+");
				
					while(fread(&stu,LEN,1,fp)){
						if(nums!=stu.num){
							fwrite(&stu,LEN,1,fp1);
						}
					} 
					fclose(fp);
					fclose(fp1);
					while(remove("book1.dat")!=0);
					rename("linshi.dat","book1.dat");				    
					fflush(stdin);
					Sleep(3000);
					system("CLS");
					return;									
				}
				else{
					printf("\n\t\t\t\t3秒后返回之前界面。");
				}
				Sleep(3000);
				system("CLS");
				
				goto loop2; 				
			}
		}
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		} 
	}
	else if(n==2){
		printf("\n\t\t\t\t请输入书籍名称:");
		scanf("%s",&name);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(name,stu.name) == 0){
				t=1;
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
				printf("\n\t\t\t\t是否确定删除图书%s。1.是   2.否",stu.name);
				scanf("%d",&j);
				if(j==1){
					printf("\n\t\t\t\t图书删除成功");
					printf("\n\t\t\t\t3秒后返回主界面。");
					fseek(fp,0,SEEK_SET);
					FILE *fp1;
					fp1 = fopen("linshi.dat","ab+");
				
					while(fread(&stu,LEN,1,fp)){
						if(strcmp(name,stu.name) != 0){
							fwrite(&stu,LEN,1,fp1);
						}
					} 
					fclose(fp);
					fclose(fp1);
					while(remove("book1.dat")!=0);
					rename("linshi.dat","book1.dat");
				
					fflush(stdin);
					Sleep(3000);
					system("CLS");
					return; 
				}
				else{
					printf("\n\t\t\t\t3秒后返回上一界面。");
					Sleep(3000);
					system("CLS");
					goto loop2;
				}		
			}

		}
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		} 
	}
	else if(n==3){
		printf("\n\t\t\t\t请输入书籍作者:");
		scanf("%s",&authors_name);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(authors_name,stu.author_name) == 0){
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);		
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t请确认好需要删除图书的书名,返回上次界面从新选择删除方式。\n\t\t\t\t3秒后返回之前界面。");	
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
	}
	else if(n==4){
		printf("\n\t\t\t\t请输入书籍出版社:");
		scanf("%s",&chubanshe1);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(chubanshe1,stu.chubanshe) == 0){
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);	
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t请确认好需要删除图书的书名,返回上次界面从新选择删除方式。\n\t\t\t\t3秒后返回之前界面。");	
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
	}
	else if(n==5){
		printf("\n\t\t\t\t3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");	
	}
}

6.图书借阅次数最值

 代码段

void chaxuncishu()
{
	FILE *fp;
	book stu;
	int min=10000,max=0,m;
	loop7: 
	fp = fopen("book1.dat","rb+");
	fseek(fp, 0, SEEK_SET);
	while (fread(&stu,LEN,1,fp)){
		if(stu.jieyucishu>=max){
			max=stu.jieyucishu;
			strcpy(temp.name,stu.name);	
		}
		if(stu.jieyucishu<=min&&stu.jieyucishu>=0){
			min=stu.jieyucishu;
			strcpy(temp2.name,stu.name);
		}
	}
	fclose(fp);
	printf("\n\n\t\t******************这里是图书借阅次数最值界面*********************"); 
	printf("\n\n\t\t******************图书借阅次数最多的图书为:%s,借阅次数为:%d********************",temp.name,max);
	printf("\n\n\t\t******************图书借阅次数最少的图书为:%s,借阅次数为:%d********************",temp2.name,min);
	printf("\n\n\t\t******************是否返回主菜单?1.是 2.否********************");
	scanf("%d",&m);
	if(m==1){
		printf("\n\n\t\t******************3秒后返回主菜单。***********************");
		Sleep(3000);
		system("CLS");
	}
	else if(m==2){
		system("CLS");
		goto loop7;
	}			
}

7.图书总数统计

图书总数会在主菜单界面左上角显示

 代码段

void tongji(){
	FILE *fp;
	book stu;
	tushuzongshu=0;
	fp = fopen("book1.dat","rb+");
	fseek(fp, 0, SEEK_SET);
	while(fread(&stu,LEN,1,fp)){
		tushuzongshu++;
	}
	fclose(fp);	
}

8.源码

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<string.h>
#define N 1000
#define LEN sizeof(book)

typedef struct book
{
	int num;							//编号 
	char name[31];						//书名 
	char author_name[27];				//作者名 
	char chubanshe[20];					//出版社 
	int jieyucishu;						//借阅次数 
}book; 

struct book temp;
struct book temp2;
int  tushuzongshu;

int luru();
void chaxun();
int shanchu();
void xiugai();
void chaxuncishu();
void tongji();

void main()
{	
	int n;
	Sleep(300);
	loop1:
	tongji();	
	printf("\n\n\t\t********************************图书管理系统**************************************");
	printf("\n\n\n\t\t\t*********欢迎使用图书馆管理系统,请选择你需要的操作**********");
	printf("\n\n\n\n当前图书馆藏书一共有%d本。",tushuzongshu);
	printf("\n\n\n\t\t\t\t\t\t1.图书录入系统");
	printf("\n\n\n\t\t\t\t\t\t2.图书查询系统");
	printf("\n\n\n\t\t\t\t\t\t3.图书删除系统");
	printf("\n\n\n\t\t\t\t\t\t4.图书修改系统");
	printf("\n\n\n\t\t\t\t\t\t5.图书借阅次数最值系统");
	printf("\n\n\n\t\t\t\t\t\t6.退出图书管理系统");
	printf("\n\n\n\t\t\t\t\t\t请选择您所需要的操作:    ");
	scanf("%d",&n);
	if(n>=1&&n<=5){
		system("ClS");
	} 
	else if(n==6){
		system("ClS");
		printf("再次按下回车键退出,谢谢使用!");
	}
	else{
		system("CLS");
		goto loop1;
	}
	switch(n)
	{
		case 1:luru();goto loop1;
		case 2:chaxun();goto loop1;
		case 3:shanchu();goto loop1;
		case 4:xiugai();goto loop1;
		case 5:chaxuncishu();goto loop1;
	}
}

int luru()
{	
	FILE *fp=NULL;
	book stu;
	char flag = 'y';
	fp=fopen("book1.dat","ab+");
	
	while((flag == 'y'||flag == 'Y')){
		printf("\n\n\n\n\t\t\t\t****************这里是图书录入系统*******************");
		printf("\n请输入图书id: ");
		scanf("%d",&stu.num);
		printf("\n请输入图书书名: ");
		scanf("%s",stu.name);
		printf("\n请输入图书作者: ");
		scanf("%s",stu.author_name);
		printf("\n请输入图书出版社: ");
		scanf("%s",stu.chubanshe);
		stu.jieyucishu=0;
		
		fwrite(&stu,LEN,1,fp);
		fflush(stdin);
		
		printf("\n\n\n是否继续输入?继续请输入y或Y:");
		scanf("%c",&flag); 
	}
	system("CLS");
	fclose(fp);
	return;
	
} 

void chaxun()
{
	FILE *fp=NULL;
	book stu;
	int n,i,j,t=-1;
	int nums;
	char name[N],authors_name[40],chubanshe1[40];
	loop3:
	fp = fopen("book1.dat","rb+");		
	printf("\n\n\n\n\t\t\t\t****************这里是图书查询系统*******************");
	printf("\n\t\t\t\t\t请选择你所查询的方式:");
	printf("\n\n\t\t\t\t\t1.编号查询;");
	printf("\n\n\t\t\t\t\t2.书名查询;"); 
	printf("\n\n\t\t\t\t\t3.作者查询;"); 
	printf("\n\n\t\t\t\t\t4.出版社查询;");
	printf("\n\n\t\t\t\t\t5.返回主菜单;");
	printf("请输入您的选择:");
	scanf("%d",&n);
	system("CLS");
	if(n==1){
		printf("\n\t\t\t\t\t\t请您输入图书编号:");
		scanf("%d",&nums);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(nums==stu.num)
			{
				t=1;
				printf("\n\t\t\t\t\t此书为%s,借阅数为%d,是否选择借阅?1.是   2.否",stu.name,stu.jieyucishu);
				printf("\n请输入你的选择:");
				scanf("%d",&j);
				if(j==1){
					stu.jieyucishu++;
					fseek(fp,-4,SEEK_CUR);
					fwrite(&stu.jieyucishu,sizeof(int),1,fp);
					printf("\n借阅成功!请从管理员处领取书籍。3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000); 
					system("CLS");
					goto loop3;
				}
				else{
					printf("\n3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000);
					system("CLS");
					goto loop3;
				} 
			}
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop3;
		}
	}

	else if(n==2){
		printf("\n\t\t\t\t\t请输入书名:");
		scanf("%s",&name);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(name,stu.name) == 0)
			{
				t=1;
				printf("\n\t\t\t\t\t此书为%s,借阅数为%d,是否选择借阅?1.是   2.否",stu.name,stu.jieyucishu);
				printf("\n请输入你的选择:");
				scanf("%d",&j);
				if(j==1){
					stu.jieyucishu++;
					fseek(fp,-4,SEEK_CUR);
					fwrite(&stu.jieyucishu,sizeof(int),1,fp);
					printf("\n借阅成功!请从管理员处领取书籍。3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000);
					system("CLS"); 
					goto loop3;
				}
				else{
					printf("\n3秒钟后返回主菜单");
					t=-1;
					fclose(fp);
					Sleep(3000);
					system("CLS");
					goto loop3;
				}				
			}
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop3;
		}
	
	}

	else if(n==3){
		printf("\n\t\t\t\t\t请输入书作者:");
		scanf("%s",&authors_name);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(authors_name,stu.author_name) == 0){
				printf("\n\t\t\t\t\t作者的图书有%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);
		if(t==-1){
			printf("\n\t\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop3;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t\t是否返回主菜单?1.是  2.否");
			t=-1;
			scanf("%d",&j);
			if(j==1){
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS"); 
			}
			else{
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS");
			} 
		}
	}
	else if(n==4){
		printf("\n\t\t\t\t\t请输入书出版社:");
		scanf("%s",&chubanshe1);
		fseek(fp,0,SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(chubanshe1,stu.chubanshe) == 0){
				printf("\n\t\t\t\t\t出版社的图书有%s\n",stu.name);
			}
			t=1;
		}		
		fclose(fp);
		if(t==-1){
			printf("\t\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			goto loop3;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t\t是否返回主菜单?1.是  2.否");
			scanf("%d",&j);
			if(j==1){
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS"); 
			}
			else{
				printf("\n\t\t\t\t\t3秒钟后返回主菜单");
				Sleep(3000);
				system("CLS");
			} 
		}
	}
	else if(n==5){
		printf("\n\t\t\t\t\t3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");
	} 
}

int shanchu()
{
	int n,i,j,t=-1;
	int nums;
	book stu;
	FILE *fp;
	
	char name[20],authors_name[40],chubanshe1[40];
	loop2:
	fp = fopen ("book1.dat","rb+");
	printf("\n\n\n\n\t\t\t\t****************这里是图书删除系统*******************");
	printf("\n\t\t\t\t请输入您想要删除的书的数据:");
	printf("\n\t\t\t\t1.书籍编号。");
	printf("\n\t\t\t\t2.书籍书名。");
	printf("\n\t\t\t\t3.书籍作者。");
	printf("\n\t\t\t\t4.书籍出版社。");
	printf("\n\t\t\t\t5.返回主菜单。"); 
	printf("\n\t\t\t\t请输入您的选择:");
	scanf("%d",&n);
	system("CLS");
	if(n==1){
		printf("\n\t\t\t\t请输入书籍编号:");
		scanf("%d",&nums);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(nums==stu.num){
				t=1;
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
				printf("\n\t\t\t\t是否确定删除图书%s。1.是   2.否",stu.name);
				scanf("%d",&j);
				if(j==1){
					printf("\n\t\t\t\t图书删除成功");
					printf("\n\t\t\t\t3秒后返回之前界面。");
					fseek(fp,0,SEEK_SET);
					FILE *fp1;
					fp1 = fopen("linshi.dat","ab+");
				
					while(fread(&stu,LEN,1,fp)){
						if(nums!=stu.num){
							fwrite(&stu,LEN,1,fp1);
						}
					} 
					fclose(fp);
					fclose(fp1);
					while(remove("book1.dat")!=0);
					rename("linshi.dat","book1.dat");				    
					fflush(stdin);
					Sleep(3000);
					system("CLS");
					return;									
				}
				else{
					printf("\n\t\t\t\t3秒后返回之前界面。");
				}
				Sleep(3000);
				system("CLS");
				
				goto loop2; 				
			}
		}
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		} 
	}
	else if(n==2){
		printf("\n\t\t\t\t请输入书籍名称:");
		scanf("%s",&name);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(name,stu.name) == 0){
				t=1;
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
				printf("\n\t\t\t\t是否确定删除图书%s。1.是   2.否",stu.name);
				scanf("%d",&j);
				if(j==1){
					printf("\n\t\t\t\t图书删除成功");
					printf("\n\t\t\t\t3秒后返回主界面。");
					fseek(fp,0,SEEK_SET);
					FILE *fp1;
					fp1 = fopen("linshi.dat","ab+");
				
					while(fread(&stu,LEN,1,fp)){
						if(strcmp(name,stu.name) != 0){
							fwrite(&stu,LEN,1,fp1);
						}
					} 
					fclose(fp);
					fclose(fp1);
					while(remove("book1.dat")!=0);
					rename("linshi.dat","book1.dat");
				
					fflush(stdin);
					Sleep(3000);
					system("CLS");
					return; 
				}
				else{
					printf("\n\t\t\t\t3秒后返回上一界面。");
					Sleep(3000);
					system("CLS");
					goto loop2;
				}		
			}

		}
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		} 
	}
	else if(n==3){
		printf("\n\t\t\t\t请输入书籍作者:");
		scanf("%s",&authors_name);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(authors_name,stu.author_name) == 0){
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);		
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t请确认好需要删除图书的书名,返回上次界面从新选择删除方式。\n\t\t\t\t3秒后返回之前界面。");	
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
	}
	else if(n==4){
		printf("\n\t\t\t\t请输入书籍出版社:");
		scanf("%s",&chubanshe1);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(chubanshe1,stu.chubanshe) == 0){
				printf("\n\t\t\t\t\t此书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);	
		if(t==-1){
			printf("\n\t\t\t\t未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
		else if(t!=-1){
			printf("\n\t\t\t\t请确认好需要删除图书的书名,返回上次界面从新选择删除方式。\n\t\t\t\t3秒后返回之前界面。");	
			Sleep(3000);
			system("CLS");
			goto loop2;
		}
	}
	else if(n==5){
		printf("\n\t\t\t\t3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");	
	}
}
 
void xiugai(){
	book stu;
	FILE *fp;
	int n,m,t=-1;
	int nums;
	char name[N],authors_name[40],chubanshe1[40];
	loop4:
	fp = fopen("book1.dat","rb+");
	printf("\n\n\n\n\t\t\t\t****************这里是图书修改系统*******************");
	printf("\n\t\t\t\t\t请选择你所需要修改图书的信息:");
	printf("\n\n\t\t\t\t\t1.编号;");
	printf("\n\n\t\t\t\t\t2.书名;"); 
	printf("\n\n\t\t\t\t\t3.作者;"); 
	printf("\n\n\t\t\t\t\t4.出版社;");
	printf("\n\n\t\t\t\t\t5.返回主菜单;");
	printf("\n\n\t\t\t\t\t请输入您的选择:");	
	scanf("%d",&n);
	system("CLS");
	if(n==1){
		printf("\n\n\t\t\t\t\t请输入修改图书的编号:");
		scanf("%d",&nums); 
		fseek(fp, 0, SEEK_SET);
		while (fread(&stu, LEN, 1, fp))
		{

			if (nums==stu.num)
			{
				printf("\n\n\t\t\t\t\t请重新输入图书编号:   ");
				scanf("%d", &stu.num);
	
				printf("\n\n\t\t\t\t\t请重新输入书名:    ");
				scanf("%s", &stu.name);

				printf("\n\n\t\t\t\t\t请重新输入书籍作者: ");
				scanf("%s", &stu.author_name);

				printf("\n\n\t\t\t\t\t请重新输入图书出版社: ");
				scanf("%s", &stu.chubanshe);

				fflush(stdin);
				fseek(fp, 0-LEN, SEEK_CUR);
				fwrite(&stu, LEN, 1, fp);
				fclose(fp);
			}
		}
		printf("\n\t\t\t\t图书修改完成,3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");
	}
	if(n==2){
		printf("\n\n\t\t\t\t\t请输入修改图书的书名:");
		scanf("%s",&name); 
		fseek(fp, 0, SEEK_SET);
		
		while (fread(&stu, LEN, 1, fp))
		{

			if (strcmp(name,stu.name) == 0)
			{
				printf("请重新输入图书id:   ");
				scanf("%d", &stu.num);

				printf("请重新输入书名:    ");
				scanf("%s", &stu.name);

				printf("请重新输入书籍作者  : ");
				scanf("%s", &stu.author_name);
	
				printf("请重新输入图书出版社  : ");
				scanf("%s", &stu.chubanshe);

				fflush(stdin);
				fseek(fp,0-LEN, SEEK_CUR);
				fwrite(&stu, LEN, 1, fp);
				fclose(fp);
			}
		}
		printf("\n\t\t\t\t图书修改完成,3秒钟后返回主菜单");
		Sleep(3000);
		system("CLS");		
	}
	if(n==3){
		printf("\n\t\t\t\t请输入作者名称:");
		scanf("%s",&authors_name);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(authors_name,stu.author_name) == 0){
				printf("\n\t\t\t\t\t此出版社的图书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
		} 
		else if(t!=-1){
			printf("\n3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
			}							
		}
	
	if(n==4){
		printf("\n\t\t\t\t请输入出版社名称:");
		scanf("%s",&chubanshe1);
		fseek(fp, 0, SEEK_SET);
		while(fread(&stu,LEN,1,fp)){
			if(strcmp(chubanshe1,stu.chubanshe) == 0){
				printf("\n\t\t\t\t\t此出版社的图书为%s\n",stu.name);
			}
			t=1;
		}
		fclose(fp);
		if(t==-1){
			printf("未找到您所需要的书籍,3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
		} 
		else if(t!=-1){ 
			printf("\n3秒后返回上一界面。");
			Sleep(3000);
			system("CLS");
			goto loop4;
			}
		}
	if(n==5){
		printf("\n3秒后返回主菜单。");
		Sleep(3000);
		system("CLS");
	}
}

void chaxuncishu()
{
	FILE *fp;
	book stu;
	int min=10000,max=0,m;
	loop7: 
	fp = fopen("book1.dat","rb+");
	fseek(fp, 0, SEEK_SET);
	while (fread(&stu,LEN,1,fp)){
		if(stu.jieyucishu>=max){
			max=stu.jieyucishu;
			strcpy(temp.name,stu.name);	
		}
		if(stu.jieyucishu<=min&&stu.jieyucishu>=0){
			min=stu.jieyucishu;
			strcpy(temp2.name,stu.name);
		}
	}
	fclose(fp);
	printf("\n\n\t\t******************这里是图书借阅次数最值界面*********************"); 
	printf("\n\n\t\t******************图书借阅次数最多的图书为:%s,借阅次数为:%d********************",temp.name,max);
	printf("\n\n\t\t******************图书借阅次数最少的图书为:%s,借阅次数为:%d********************",temp2.name,min);
	printf("\n\n\t\t******************是否返回主菜单?1.是 2.否********************");
	scanf("%d",&m);
	if(m==1){
		printf("\n\n\t\t******************3秒后返回主菜单。***********************");
		Sleep(3000);
		system("CLS");
	}
	else if(m==2){
		system("CLS");
		goto loop7;
	}			
}

void tongji(){
	FILE *fp;
	book stu;
	tushuzongshu=0;
	fp = fopen("book1.dat","rb+");
	fseek(fp, 0, SEEK_SET);
	while(fread(&stu,LEN,1,fp)){
		tushuzongshu++;
	}
	fclose(fp);	
}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐