c语言图书管理系统

c语言实现的图书管理

使用c语言编写,功能较为全面,对每一种输入情况进行了判断,基本没有bug,代码量在1400行左右,输入提示等交互性较为完整,可以作为c语言简单的期末项目,数据保存使用的是文件

说明:

/*
李浩    Visual Studio
功能
********************************************
	 1,登录系统
		学生进入借阅系统
		管理员进入管理系统

		图书管理
		  管理员	  添加                   图书的基本信息,如 书号,书名,作者,出版社,类别,进库量,价格;
					  删除                   图书,通过图书的书号或书名进行删除;
					  查看					 查看学生图书借阅情况

		  学生	      借还书登记             先判断是否有这本书,归还截止期限,借书书名进行登记;
			          个人还书情况查看       个人借阅情况查看;

		  共用        查询                   图书通过图书的书号,书名,作者进行检索;
					  浏览                   图书的库存,将所有数目展示出来。
		   
	 2,创建账号
		可创建学生账号
		可创建管理员账号(必须输入我给的指定的密码才可以)
	 3,修改密码
		先输入账号
		再更改密码
	 4,退出系统
********************************************
执行过程:注册账号,会创建一个文件,内含账号信息。登录时会形成一个链表,依次匹配你输入的账号密码,成功后进入因进入的界面,然后继续执行操作,添加书等都会创建文件储存;
修改密码会先将文件导成链表,修改后,从头将链表再次导入文件,取代原文件全部内容。
图书操作也类似,均为从文件导入形成链表,操作后也会写入文件
核心:数据在文件与链表的相互转换;二进制文件内容与文本形式输出间的转换
*/

c代码实现,保存在gitee上


#include <stdio.h>
#include <stdlib.h>//其中包含system函数
#include <conio.h>//定义了通过控制台进行 数据输入 和数据输出的函数,如getch函数
#include <string.h>//定义字符数组
#include <math.h>
#include<malloc.h>//空间分配
#include<Windows.h>
#include<time.h>//时间使用

char books[30] = "libraryinformation.txt";  //书籍信息
char guanlipeople[40] = "adminastrationinformation.txt"; //管理信息储存
char students[40] = "studentsinformation.txt";//学生信息储存
char studentandbook[32] = "student of book information.txt";//学生借书信息储存
char choice;//选择按键
char studentnumone[17];//学生登录后记录学生账号作为学生唯一标识
int key = 123456;//我给的密码


//图书信息
struct book
{
   
	char num[20], name[20], aut[20], pub[20]; //书号,书名,作者,出版社
	int cat;//类别
	int  many;//进库量
	int  kucun;//库存
	double price;//价格
};
//图书链表
struct booknode
{
   
	struct book book;
	struct booknode *next;
};
//借阅信息
struct borrow
{
   
	char studentnum[17];//借书号,即学生登录账号
	struct tm timetime;//储存借书时间
	struct book book;//所借图书信息
};
//借阅信息链表
struct borrownode
{
   
	struct borrow borrow;
	struct borrownode*next;
};
//登录信息
struct land//登录信息
{
   
	char zhanghao[17];//账号
	char password[17];//密码
};
//登录链表
struct node
{
   
	struct land land;
	struct node*next;
};

//共用
int displaymenu();//展示主菜单
void browse(struct booknode *);//浏览所有图书
void selectinformation();//查询通过关键信息
void beginregister(char*, char*);//新建账号
void enter(char*, char*,char*);//登录  ——》》  主要操作
void updatekey(char*, char*);//更新密码
void timedisplay();//时间展示
void displayonebook(struct booknode*);//单本书展示
void studentoneborrowshow(struct borrownode*head);//单个学生借书情况查看
struct node *initDate1();//初始化管理登录
struct node *initDate2();//初始化学生登录
struct node *importData(FILE *fp);//导入数据文件中的数据
struct booknode *initDatebook();//初始化图书信息
struct booknode *importDatabook(FILE *fp);//导入图书信息
struct borrownode*initDataborrow();//初始化借阅信息
struct borrownode*importDataborrow(FILE*fp);//导入借阅信息
//管理
int displayguanli();//展示管理界面
void addbooks(char *);//添加图书
void drop(char*books);//删除图书
void chakanstudent();//查看学生借阅情况
//学生
int displaystudents();//展示学生界面
void borrowreturn();//借书操作
void studentshow();//学生借还书查看


void main()
{
   
	/*
	while (1)
	{
		//system("color 70");//白背景黑字体
		displaymenu();//展示主菜单
		switch (choice)
		{
		case '1':
			enter(guanlipeople, students,books);//登录操作
			break;
		case '2':
			beginregister(guanlipeople, students);//注册操作
			break;
		case '3':
			updatekey(guanlipeople, students);//更改密码
			break;
		case '4':exit(0);//退出系统
			break;
		default:
			printf("\n选择有误请重输\n");
			break;
		}
	}
	*/
	int i = 1;
	i = i++;
	printf("%d\n",i);
	
	system("pause");
}


//共用
//主菜单
int displaymenu()
{
   
	while (1)
	{
   
		timedisplay();
		printf("\n\t\t\t欢迎使用图书馆登陆系统\n");
		printf("************************************************************\n");
		printf("\t\t\t1  登录系统\n\t\t\t\t学生进入借阅系统\n\t\t\t\t管理员进入管理系统\n");
		printf("\t\t\t2  创建账号\n\t\t\t\t可创建学生账号\n\t\t\t\t可创建管理员账号\n");
		printf("\t\t\t\t若没有账号请创建一个,若有则可登录\n\t\t\t\t不要创建已有账号,创建不了\n");
		printf("\t\t\t3  修改密码\n\t\t\t\t先输入账号\n\t\t\t\t再更改密码\n");
		printf("\t\t\t4  退出系统\n");
		printf("\n\t\t密码账号均以16为限\n");
		printf("\n\t\t因为错误操作处理不完全所以请按照提示操作\n\n\t\t在应当输入数字时请勿输入汉字或者字母\n");
		printf("************************************************************\n");
		printf("请输入你的选择:");
		choice = getche();
		if (1 > (choice - '0') || (choice - '0') > 4)
		{
   
			printf("\n输入有误,请重输\n");
			system("pause");
			rewind(stdin);
		}
		else return choice;
	}
}
//浏览图书信息
void browse(struct booknode*head)
{
   
	struct booknode*p;
	while (head != NULL)
	{
   
		printf("\n书号为:%s\n书名为:%s\n作者:%s\n出版社:%s\n类别:%d\n库存量为:%d\n价格:%lf\n",head->book.num,head->book.name,head->book.aut,head->book.pub,head->book.cat,head->book.kucun,head->book.price);
		p=head->next ;
		head = p;
	}
	//另一种直接对文件操作
	/*FILE *fp;
	struct book book;
	fp = fopen(books, "r");
	while (fread(&book,sizeof(struct book),1,fp)==1)
	{
		printf("\n书号为:%s\n书名为:%s\n作者:%s\n出版社:%s\n类别:%d\n库存量为:%d\n价格:%lf\n",head->book.num,head->book.name,head->book.aut,head->book.pub,head->book.cat,head->book.kucun,head->book.price);
	}*/
}
//查询图书信息
void selectinformation()
{
   
	printf("\n欢迎进入图书查询功能\n您将可以通过图书的书号,书名,作者进行检索\n");
	printf("\n(1)书号(2)书名(3)作者\n");
	choice = getche();
	if (1 > (choice - '0') || (choice - '0') > 3)
	{
   
		printf("\n输入有误,请重输\n");
		system("pause");
		rewind(stdin);
	}
	//根据书号查询
	if (choice == '1')
	{
   
		int judge = 1;
		struct booknode *head, *p;
		struct book book;
		head = initDatebook();//导入书籍信息
		printf("\n请输入图书书号:\n");
		scanf("%s", book.num);
		while (head != NULL)
		{
   
			if (strcmp(head->book.num, book.num) == 0)
			{
   
				printf("\n已经匹配到图书\n");
				displayonebook(head);
				judge = 0;
			}
			p = head->next;
			head = p;
		}
		free(head);
		if (judge == 1)
			printf("\n未找到图书信息\n");
	}
	//根据书名查询
	if (choice == '2')
	{
   
		int judge = 1;
		struct booknode *head, *p;
		struct book book;
		head = initDatebook();//导入书籍信息
		printf("\n请输入图书书名:\n");
		scanf("%s", book.name);
		while (head != NULL)
		{
   
			if (strcmp(head->book.name, book.name) == 0)
			{
   
				printf("\n已经匹配到图书\n");
				displayonebook(head);
				judge = 0;
			}
			p = head->next;
			head = p;
		}
		free(head);
		if (judge == 1)
			printf("\n未找到图书信息\n");
	}
	//根据作者查询
	if (choice == '3')
	{
   
		int judge = 1;
		struct booknode *head, *p;
		struct book book;
		head = initDatebook();//导入书籍信息
		printf("\n请输入图书作者:\n");
		scanf("%s", book.aut);
		while (head != NULL)
		{
   
			if (strcmp(head->book.aut, book.aut) == 0)
			{
   
				printf("\n已经匹配到图书\n");
				displayonebook(head);
				judge = 0;
			}
			p = head->next;
			head = p;
		}
		free(head);
		if (judge == 1)
			printf("\n未找到图书信息\n");
	}
}
//新建文件(账号)
//检查账号是否存在,不存在才能注册
void beginregister(char*guanli, char*students)
{
   
	FILE *fp; int select; struct land land;
	int flag = 1;
	int guanlizhuru;
	char zhanghao[17]; char password[17];

	//注册账号
	while (flag)
	{
   
		printf("\n管理和学生任何一个文件不存在均需要再来一次\n账号密码尽量不要太长(退出输入$)\n");
		printf("输入账号:");
		scanf("%s", zhanghao);
		strcpy(land.zhanghao, zhanghao);
		//退出
		if (strcmp(zhanghao, "$") == 0)
		{
   
			printf("\n返回上级功能\n");
			return;
		}
		//判断账号是否已经存在

		int flag2;
		struct node *head, *p;
		head = initDate1();//导入管理信息文件形成链表
		while (head != NULL)
		{
   
			flag2 = 1;
			flag2 = strcmp(head->land.zhanghao, land.zhanghao);
			if (flag2 == 0)
			{
   
				printf("\n账号已经存在!请重新选择\n");
				return;
			}
			p = head->next;
			head = p;
		}

		int flag3;
		struct node *head2, *p2;
		head2 = initDate2();//导入学生信息文件形成链表
		
  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸟程序员李老板专业码代码三十年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值