橘猫图书管理系统--数据库原理期末项目

本文档介绍了一个使用C++语言编写的橘猫图书管理系统,旨在实现图书登记、删除、查询等功能,以及学生借阅、还书等操作。系统包括对书籍、图书种类和借阅信息的管理,有助于减轻图书馆管理者的负担。管理员默认密码为123456。
摘要由CSDN通过智能技术生成

需求分析

图书馆作为文学的聚集地和展示平台,书籍是从古至今文化传递记载的介质。图书馆是高校不可缺少的基础设施,图书馆管理系统是图书馆正常运转的关键。此次数据库课程设计采用C++语言编写程序,实现图书登记、删除、查询、浏览、读者借阅、还书、会员登录、密码修改等功能。程序包括数据链表和文件指针的操作,包括结构数据的定义和使用,文件的读写、定位和修改。
橘猫书馆管理系统主要是完成对书籍,书的种类,学生借阅信息的管理,能够有效的查看借阅记录以及书籍信息。从而减轻书馆管理者的人工负担。书馆管理员首先完成对图书类别管理,图书信息的查询、增加、删除、修改等操作,以及学生借阅图书信息的查询、增加、删除等。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

管理员默认密码为123456

代码实现

#include<stdio.h>
#include<stdlib.h>  
#include<conio.h>   
#include<string>  
#include<math.h>
#include<cstdio>
#include <math.h>
#include <dos.h>
#include <windows.h>
#include<iostream>
#define  LEN   sizeof(struct library)
#define  LEN1  sizeof(struct reader) 
#define LEN2 sizeof(struct land)
using namespace std;
int role; 
struct library
{
   
	int xcl;//库存
	float price;//单价
	char name[20],author[20],chuban[20],kind[20],shuhao[20];
	struct library *next;
};
struct reader//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读者结构体
{
   
	int zhenghao;
	char mingzi[20],riqi[20],zname[20];
	struct reader *next;
};
struct land//登录信息
{
   
	int zhanghao;
	char password[20];
	struct land*next;
};
int match(int m,char a[20])//匹配数据库中的账号密码
{
   
	void lmain();
	FILE*fp;
	int n=0,i=0;
	int zhanghao;
	char password[20];

	if ((fp=fopen("land.txt","r"))==NULL)//不存在读者文件
	  {
   
         system ("cls");
		 printf("\n 小主还没有创建该账号呢..喵!");
		 getch();
	 	system("cls");
		lmain();
	
      }


        for(;!feof(fp);)
      {
   
        fscanf(fp,"%d%s",&zhanghao,password);
        if(m==zhanghao)
        {
   
        	if(strcmp(a,password)==0)
			return 1;
			else
			{
   
			return -1;
		   }
	    }
	  }
	  return 0;
 }
// void lmain()//登录功能函数
//{
   
//	void xgmm();
//	void lmenu();
//	void land();
//	void xinjian();
//	char choose;
//	lmenu();
//	scanf(" %c",&choose);
//	switch(choose)//功能函数
//  {
   
//	  case'1':
//	    land();
//	    break;
//	  case'2':
//	  	xinjian();
//	  	break;
//	  	case'3':
//	  	xgmm();
//	  	break;
//	  case'4':
//	  	system("cls");
//    getch();
//  	exit(0);
//  	system ("cls");
//	break;
//  }
//}
void xinjian()//新建账户密码
{
   
	void lmain();
	FILE *fp;
	int zhanghao;char password[20],password1[20];
	char hit=0;
	cout<"hhhh"; 
	if ((fp=fopen("land.txt","r"))==NULL)//if语句:打开图书馆文件,不存在此文件则新建
	{
   
      fp=fopen("land.txt","w");
      fclose(fp);
    }
    system("cls");
	fp=fopen("land.txt","a");
	for(;;)//输入两次密码确认,两次相同才能确认
	{
   
	   printf("\n请按以下格式输入账户:\n橘猫编号 橘猫密码\n");
	   printf("请输入:");
	   scanf("%d %s",&zhanghao,password);
       printf("再次输入密码:\n");
	   scanf("%s",password1);
	   printf("hhhh");
	   printf("你输入的账号是%d",zhanghao);
	   if(strcmp(password,password1)==0)
	   {
   
	       fprintf(fp,"%d %s\n",zhanghao,password);
		   break;
       }
       else
	   {
   
	       printf("两次输入密码不一致,继续创建按回车,退出按ESC");
	       hit=getch();
		   if(hit=27)
		   system("cls");
		   lmain();
		         }
   }
   fclose(fp);
   printf("创建成功,按任意键返回");getch();system("cls");lmain();
}
void land()//输入账户密码的登录函数
{
   
	void main1();void lmain();
	void jieshuxitong(); 
	int zhanghao;
	char password[20];
	int i=2,j,k,n;
	char hit=0;
	system("cls");
	do
	{
   
	   printf("\输入橘猫账号吧:");
       scanf("%d",&zhanghao);
       printf("小主确认输入请按回车,要重新输入啦请按ECS键");
       hit=getch();//暂停程序当i接收后继续下一条指令
       for (;hit!=13&&hit!=27;)//保证只能是CR和ESC才能退出循环,输入其他字符无用,暂停程序,按'CR'继续。
       {
   
	        hit=getch();
	   }
    }
    while(hit==27);
	 printf("\n小主请输入橘猫密码:");
	 scanf("%s",password);
     i=match(zhanghao,password);
     if(i==1)
	 {
   
       printf("登陆成功啦...喵喵喵");getch();jieshuxitong();
	 }
	 else
	 {
   
	 	if(i==-1)
		 {
   
		 printf("小主的密码不正确呢!");getch(); land();
		 }
		 if(i==0)
		 printf("没有这个橘猫账户喵");getch();
		 system("cls"); lmain();
	 }
}
int tjzs3()//统计账号密码文本个数
{
   
FILE *fp;
int zhao=0,n;
char mm[20]={
   '\0'};
fp=fopen("land.txt","r");//打开文件
for (n=0;!feof(fp);n++)//逐个读文件
fscanf(fp,"%d %s",&zhao,mm);
n--;
fclose(fp);//关闭文件
return (n);//返回个数
}
void xg(int z,char m[20])//修改函数
{
   
	FILE *fp;
	int zhanghao1,n,j,k;
	char mima1[20];
	struct land *head,*p,*p1,*p2;

	 fp=fopen("land.txt","r");
	   j =tjzs3();

	   for (k=0;k<=j;k++)
       {
   
	       fscanf(fp,"%d %s",&zhanghao1,mima1);
           if (z!=zhanghao1)//比较名字,将不同名字的信息复制到链表
          {
   
	            n++;//相同返回值为0不执行if语句继续循环,不同则执行直到将所有不同的书名建立成链表
	            if (n==1)//建立链表
                {
   
		          p1=p2=(struct land*)malloc(LEN2);
                  head=p1;
				}
                else
			    {
   
			      p2->next=p1;
				  p2=p1;
                  p1=(struct land*)malloc(LEN2);//新建链表
                }
 				p1->zhanghao=zhanghao1;
                strcpy(p1->password,mima1);//复制账号密码
          }
       }
        if (n==0)
			 {
   
			 head=NULL;
			 }
			 else//建立链表的最后剩余一个储存空间,所以封底
			 {
   
			 p2->next=p1;
			 p1->next=NULL;
			 fclose(fp);
			 }
			  fp=fopen("land.txt","w");//清空文件,只写打开,然后关闭
              fclose(fp);
              fp=fopen("land.txt","a");//追加文件
              p=head;
            for (;p!=NULL;)//把链表内容覆盖到文件
   			{
   
   	   		 	fprintf(fp,"%d %s%\n",p->zhanghao,p->password);
   	   			p=p->next;
	        }
	        fprintf(fp,"%d %s\n",z,m);
            fclose(fp);
             system ("cls");

}
void xgmm()//修改账户密码的函数 
{
   
	   void main1();  void lmain();
	   FILE *fp;int zh=0,k=0,many=0,m=0,n=0;
       int chazhao,hit;
       char mima[20]={
   '\0'},password1[20]={
   '\0'};char  mm[20]={
   '\0'}; char i;
       if ((fp=fopen("land.txt","r"))==NULL)//打开文件
       {
   
	       system ("cls");
           printf("\n记录文件不存在!按任意键返回");
  		   getch();
  		   system("cls");
		   lmain();
       }
	   system("cls");
       printf("请小主输入橘猫账号和橘猫密码:\n");
       scanf("%d %s",&chazhao,mima);
	   m =tjzs3();
	   for (n=0;n<=m;n++)
	   {
   
	    fscanf(fp,"%d %s",&zh,mm);
        if(zh==chazhao)
        {
   
        	if(!strcmp(mm,mima))
        	{
   
        		printf("请输入新的橘猫密码");
        		scanf("%s",mima);
       		    printf("再次输入橘猫密码喵:\n");
	            scanf("%s",password1);
	             if(strcmp(mima,password1)==0)
	   			 {
   
		             xg(chazhao,mima);
		            getch();
				    lmain();
	                system("cls");
   			     }
       			  else
	   			  {
   
	       		   	  printf("小主密码两次不一致喵");
	       			  hit=getch();
		   			  system("cls");
				      lmain();

   				  }
			}
			else
			{
   
				printf("原来橘猫账户的旧密码错误,好可惜呀!");
				getch();
				system("cls");
				lmain();
	            
			}

        }
      }
	   printf("不存在此账号,按任意键返回")
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值