2020-12-24

标题C++大作业你还烦恼吗?图书管理系统让你得到老师欣慰的目光…

C++图书管理系统
1.图书信息类
2.安全类。
3.菜单类
#include <iostream>
#include"Book_Manage.h"
#include"Safe_Mange.h"
#include"Menu_Manage.h"
using namespace std;
/**
 *  我在主函数,声明了三个全局变量的类的类型;
 *  以便于以后的调用;
 */
Book_Manage_Function BMF;
Safe_Mange_Function SMF;
Menu_Manage MM;
int main()
{
      int N=0;
      U_B_S* head_safe=SMF.Create_head();//创建安全系统的表头;
      B_I* head_book=BMF.Createlist();//创建图书信息得头链表;
      BMF.Login(head_book);
      SMF.Load_All_ID(head_safe);
    while(1)
    {
        MM.Menu_Login();
        N=MM.Control_Login(head_safe);
        if(N!=0){break;}
        system("cls");
    }
    while(1)
    {
        MM.Menu_Initial();
        MM.Control_Initial(head_safe,head_book);
        system("cls");
    }
    return 0;
}

这是Book_Manage.h
#ifndef BOOK_MANAGE_H
#define BOOK_MANAGE_H
#include<iostream>
#include<stdio.h>
#include<windows.h>
using namespace std;



/**
 *                            书籍管理系统
 *  1.首先我将书籍信息数据抽象,为1.编号2.书名3.作者4.出版社5.库存量
 *  2.然后创建图书类,将其包含进去,
 *  3.再创一个类分别声明以及实现 增.删.改.查.功能待加.回主菜单一系列函数;
 *  直接就在类下面实现。
 *  4.注意:该书籍信息的存储用的是链表,且表头在主函数创建,因为借阅书籍的时候会用到;
 *  4.以上是我的思想;
 */
class Book_Manage
{
    public:
        Book_Manage() {}
        virtual ~Book_Manage() {}
        char Serial_Number[20];//编号;
        char Book_Title[20];//书的名字;
        char Book_Author[20];//书的作者;
        char Book_Publisher[20];//出版商;
        int Book_number;//书的库存量;
protected:

private:
};
typedef struct Book_Information
{
    Book_Manage book;
    struct Book_Information* next;
}B_I;
class Book_Manage_Function
{
private:
//Book_Manage_Function();
//~Book_Manage_Function();
public:
//创建头节点
B_I* Createlist();
//增加新的节点;
void Add_List(B_I*,B_I*);
//加载信息至内存;
B_I* Login(B_I*);
//删除图书信息;
void Delete_List(B_I*);
//查重复
int check(B_I*,char []);
//用于修改图书信息;
void Modify_List(B_I*);
//查看某个图书;
void Print_List(B_I*);
//保存至文件;
void Prvation_Book(B_I*);
//搜寻链表
void Search_List(B_I*);

protected:

};
//输出运算符重载
ostream& operator<<(ostream& out,Book_Manage& variable)
{
    out<<"-------------------书籍信息如下---------------------"<<endl;
    out<<"\t\t"<<"<<"<<"编    号:"<<variable.Serial_Number<<">>"<<endl;
    cout<<endl;
    out<<"书    名:"<<variable.Book_Title<<"\t\t"<<"出版  商:"<<variable.Book_Publisher<<endl;
    cout<<endl;
    out<<"作    者:"<<variable.Book_Author<<"\t\t\t"<<"库存  量:"<<variable.Book_number<<endl;
    out<<"---------------------------------------------------"<<endl;
    return out;
}
//输入运算符重载
istream& operator>>(istream& it,Book_Manage& variable)
{
   cout<<"请输入书籍信息:1.编号2.书名3.作者4.出版商5.书的库存"<<endl;
   it>>variable.Serial_Number>>variable.Book_Title>>variable.Book_Author>>variable.Book_Publisher>>variable.Book_number;
   return it;
}
/**=================实现类中函数===============*/
//创建头节点
B_I* Book_Manage_Function::Createlist()
{
    B_I* head_List=new B_I;
    head_List->next=NULL;
    return head_List;
}
//增加新的节点;
void Book_Manage_Function::Add_List(B_I* p,B_I* head)
{
     int i=0,n=0;
    cout<<"请输入你要加入书籍类型个数:"<<endl;
    cin>>n;
  for(i=1;i<=n;++i){
    B_I* pnew=new B_I;
    cout<<"请输入第"<<i<<"个书籍信息"<<endl;
    cin>>pnew->book;//重载运算符;
    pnew->next=NULL;
    p->next=pnew;
    p=p->next;
  }
}
//加载信息至内存;
B_I* Book_Manage_Function::Login(B_I* head)
{
    FILE* fp;
    B_I* pnew=NULL;
    B_I* p=head;
    fp=fopen("D:/C/list_Book_information.txt","r");
    if(fp==NULL){
     cout<<"加载文件打开失败!!!"<<endl;
     exit(1);
    }
  	while(1){
		pnew=new B_I;
		if(pnew==false){
			printf("\n内存申请失败!!!\n");
			system("pause");
		}
			if(fscanf(fp,"%s %s %s %s %d\n",pnew->book.Serial_Number,pnew->book.Book_Title,pnew->book.Book_Author,pnew->book.Book_Publisher,&pnew->book.Book_number)==EOF){
				break;
			}
		pnew->next=NULL;
		p->next=pnew;
		p=p->next;
	}
    fclose(fp);
    return p;
}
//删除图书信息;
void Book_Manage_Function::Delete_List(B_I* head)
{
     B_I* pmove1=head;
     B_I* pmove2=pmove1->next;
     char n[20];
     cout<<"请输入你要删除书籍的编号:";
     while(1){
     cin>>n;
        if(strlen(n)>10){
           cout<<"你输入编号错误,请重新输入!!!"<<endl;
           continue;
        }break;
     }
while(pmove2!=NULL){
		if(strcmp(pmove2->book.Serial_Number,n)==0){
			pmove1->next=pmove2->next;
			delete pmove2;
			cout<<"已删除该书籍"<<endl;
            system("pause");
			break;
		}
		pmove1=pmove1->next;
		pmove2=pmove2->next;
	}
    if(pmove2==NULL)
	cout<<"未找到该书籍信息,请检查您输入的编号是否正确!!!"<<endl;
}
//查重复
int Book_Manage_Function::check(B_I* head,char B_L[])
{
    B_I* pmove=head->next;
    while(pmove!=NULL){
        if(strcmp(pmove->book.Serial_Number,B_L)==0){
            return 1;
        }
        pmove=pmove->next;
    }
    return 0;
}
//用于修改图书信息;
void Book_Manage_Function::Modify_List(B_I* head)
{
    int d=0;
    char B_L3[20];
    char B_L4[20];
    char B_L[20];//编号;
    char n[20];
    char a[2];
    int A=0;
    int c=0;
    int C=0;
    B_I* pmove=head;
    while(1){
            cout<<"请输入你要修改书籍的编号:";
            cin>>n;
            if(strlen(n)>10){
                cout<<"你输入的编号过长"<<endl;
                continue;
            }break;
    }
    while(pmove->next!=NULL){
            pmove=pmove->next;
            if(strcmp(pmove->book.Serial_Number,n)==0){
            cout<<"已找到该书籍,原本信息如下:"<<endl;
            d++;
            cout<<pmove->book;
            break;
            }
    }
    if(d==0){
        goto Endl;
    }
    while(1){
                 cout<<"请选择你要修改的信息:1.编号2.书名3.作者4.库存量"<<endl;
                 cin>>a;
                 if(strlen(a)>1){
                    cout<<"你输入的指令有误,请重新输入!!!"<<endl;
                    system("pause");
                    continue;
                 }
                 if(strcmp(a,"1")==0){
                    A=1;cout<<"你将要修改编号"<<endl;break;
                 }
                 if(strcmp(a,"2")==0){
                    A=2;cout<<"你将要修改书名"<<endl;break;
                 }
                 if(strcmp(a,"3")==0){
                    A=3;cout<<"你将要修改作者"<<endl;break;
                 }
                 if(strcmp(a,"4")==0){
                    A=4;cout<<"你将要修改库存量"<<endl;break;
                 }
                 else{
                    cout<<"你输入的指令有误,请重新输入!!!"<<endl;
                    continue;
                 }
    }
//按编号修改;
            if(A==1){
            while(1){
                cout<<"情输入你要修改后的编号:";
                cin>>B_L;
                c=check(head,B_L);
                if(c==1){
                    cout<<"你要修改的编号在库存里已存在,请重新输入"<<endl;
                    system("pause");
                    continue;
                }else if(c==0){
                  strcpy(pmove->book.Serial_Number,B_L);
                  cout<<"修改成功"<<endl;
                  break;
                }
            }
        }
//按书名修改;
            if(A==2){
                cout<<"情输入你要修改后的书名:";
                cin>>B_L4;
                strcpy(pmove->book.Book_Title,B_L4);
            }
//按作者修改;
            if(A==3){
                cout<<"情输入你要修改后的作者:";
                cin>>B_L3;
                strcpy(pmove->book.Book_Author,B_L3);
            }
//按库存修改;
            if(A==4){
                cout<<"情输入你要修改后的库存:";
                cin>>C;
                pmove->book.Book_number=C;
            }
Endl:
cout<<"";
}
//查看某个图书;
void Book_Manage_Function::Print_List(B_I* head)
{
    int a=0;
    char B_L[20]=" ";
    B_I* pmove=head->next;
    while(1){
        cout<<"请输入你想要查看书籍的编号:"<<endl;
        cin>>B_L;
        if(strlen(B_L)>10){
        cout<<"编号不大于10个字符"<<endl;
        cout<<"你输入的编号过长,请重新输入!!!"<<endl;system("pause");
        continue;
        }break;
    }
    while(pmove!=NULL){
      if(strcmp(pmove->book.Serial_Number,B_L)==0){
        cout<<"书籍信息如下:"<<endl;
        cout<<pmove->book<<endl;
        a++;
        break;
      }
      pmove=pmove->next;
    }
    if(a==0){
      cout<<"未找到该书籍信息"<<endl;
    }
}
//保存至文件;
void Book_Manage_Function::Prvation_Book(B_I* head)
{
   FILE* fp;
   B_I* pmove=NULL;
   pmove=head->next;
   fp=fopen("D:/C/list_Book_information.txt","w");
   while(pmove!=NULL){
    fprintf(fp,"%s %s %s %s %d\n",pmove->book.Serial_Number,pmove->book.Book_Title,pmove->book.Book_Author,pmove->book.Book_Publisher,
            pmove->book.Book_number);
       pmove=pmove->next;
   }
   fclose(fp);
}
//搜寻链表
void Book_Manage_Function::Search_List(B_I* head)
{
    B_I *k=head;
	k=k->next;
	cout<<"结果如下:"<<endl;
	while(k!=NULL){
		cout<<"编号:"<<k->book.Serial_Number<<"\t"<<"书名:"<<k->book.Book_Title<<"\t"<<"库存量:"<<k->book.Book_number<<endl;
		k=k->next;
	}
}
#endif // BOOK_MANAGE_H
这是Mnue_Manage.h
#ifndef MENU_MANAGE_H
#define MENU_MANAGE_H
#include"Safe_Mange.h"
#include"Book_Manage.h"
#include<iostream>
#include<conio.h>
#include<cstdio>
#include<string.h>
#include<windows.h>
using namespace std;
/**
 *                  菜单管理——主控区
 *  1.我将所有功能的菜单以及主控函数抽象到菜单管理类
 */
 //声明三个个全局的类类型的变量;
 Safe_Mange_Function safe;
 Book_Manage_Function book;
 Borrow_Still_Mange_Function borrow;
class Menu_Manage
{
    public:
        //Menu_Manage() {}
        //virtual ~Menu_Manage() {}
        void Menu_Login();
        void Menu_Initial();
        void Menu3_Borrow_Still();
        void Menu4_BookInformation();
        int Control_Login(U_B_S*);
        int Control_Initial(U_B_S*,B_I*);
        int Control_Borrow_Still(U_B_S*,B_I*);
        int Control_BookInformation(B_I*);
    protected:

    private:
};
//登录时菜单
void Menu_Manage::Menu_Login()
{
    cout<<"----------------登录系统--------------"<<endl;
        cout<<"\t\t1.注册"<<endl;
        cout<<"\t\t2.登录"<<endl;
        cout<<"\t\t3.找回密码"<<endl;
        cout<<"\t\t4.修改密码"<<endl;
        cout<<"\t\t5.查看所有用户名"<<endl;
        cout<<"\t\t6.退出系统"<<endl;
        cout<<"--------------------------------------"<<endl;
        cout<<"输入选择(1-6):";
}
//初始界面的菜单
void Menu_Manage::Menu_Initial()
{
    cout<<"----------------图书管理系统--------------"<<endl;
        cout<<"\t\t1.借阅管理"<<endl;
        cout<<"\t\t2.书库管理"<<endl;
        cout<<"\t\t3.退出系统"<<endl;
        cout<<"--------------------------------------"<<endl;
        cout<<"输入选择(1-3):";
}
//借书还书的菜单
void Menu_Manage::Menu3_Borrow_Still()
{
    cout<<"---------------书库管理系统---------------"<<endl;
    cout<<"*"<<"\t\t1.归还书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t2.借阅情况"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t3.借阅书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t4.帮    助"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t5.回主菜单"<<"\t\t *"<<endl;
    cout<<"------------------------------------------"<<endl;
    cout<<"输入选择(1-5):";
}
//书籍管理的菜单
void Menu_Manage::Menu4_BookInformation()
{
    cout<<"---------------书库管理系统---------------"<<endl;
    cout<<"*"<<"\t\t1.增加书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t2.删除书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t3.修改书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t4.查询书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t5.所有书籍"<<"\t\t *"<<endl;
    cout<<"*"<<"\t\t6.回主菜单"<<"\t\t *"<<endl;
    cout<<"------------------------------------------"<<endl;
    cout<<"输入选择(1-6):";
}
//登录的控制区域
int Menu_Manage::Control_Login(U_B_S* head)
{
    U_B_S* K=NULL;
    int N=0;
    int A=0;
    char n[10];
while(1){
        cin>>n;
        if(strlen(n)>1){
            cout<<"请输入有效指令"<<endl;
            continue;
        }
        if(strcmp(n,"1")==0){
            A=1;break;
        }
        if(strcmp(n,"2")==0){
            A=2;break;
        }
        if(strcmp(n,"3")==0){
            A=3;break;
        }
        if(strcmp(n,"4")==0){
            A=4;break;
        }
        if(strcmp(n,"5")==0){
            A=5;break;
        }
        if(strcmp(n,"6")==0){
            A=6;break;
        }
        else
            {
                cout<<"你输入的指令无效"<<endl;
        continue;
            }
}
       switch(A){
           case  1:K=safe.Load_All_ID(head);safe.Add_ID(K,head);
                   safe.Preservation_ID(head);
                   break;
           case  2:safe.Load_All_ID(head);N=safe.Loagin(head);
                   break;
           case  3:safe.Load_All_ID(head);safe.Seek_ID(head);
                   break;
           case  4:safe.Load_All_ID(head);safe.Modify(head);
                   safe.Preservation_ID(head);
                   break;
           case  5:safe.Load_All_ID(head);safe.Printf_All_ID(head);
                   break;
           case  6:cout<<"感谢本次访问"<<endl;exit(0);break;
           default:break;
       }
       return N;//用于判断是否登录成功的int类型的返回值
}
//借书的控制区域
int Menu_Manage::Control_Borrow_Still(U_B_S* head_safe,B_I* head_book)
{
    int A=0;
    char n[10];
    while(1){
        cin>>n;
        if(strlen(n)>1){
            cout<<"请输入有效指令"<<endl;
            continue;
        }
        if(strcmp(n,"1")==0){
            A=1;break;
        }
        if(strcmp(n,"2")==0){
            A=2;break;
        }
        if(strcmp(n,"3")==0){
            A=3;break;
        }
        if(strcmp(n,"4")==0){
            A=4;break;
        }
        if(strcmp(n,"5")==0){
            A=5;break;
        }
        else
            {
            cout<<"你输入的指令无效"<<endl;
            continue;
        }
    }
        switch(A){
            case 1:borrow.Still_Book(head_safe,head_book);safe.Preservation_ID(head_safe);
                   book.Prvation_Book(head_book);
                   break;//归还书籍
            case 2:borrow.Print_All_Borrow(head_safe);
                   break;//借阅情况
            case 3:borrow.Borrow_Book(head_safe,head_book);safe.Preservation_ID(head_safe);
                   book.Prvation_Book(head_book);
                   break;//借阅书籍
            case 4:borrow.B_S();
                   break;//功能待加
            case 5:return 6;
                   break;   //返回主菜单
            default:break;
       }
}
//书籍个管理的控制区域
int Menu_Manage::Control_BookInformation(B_I* head)
{
    B_I* K=NULL;
    int A;
    char a[2];
  while(1){
    cin>>a;
    if(strlen(a)>1){
        cout<<"你输入的指令无效,请重新输入!!!"<<endl;
        continue;
    }
    else{
        if(strcmp(a,"1")==0){
            A=1;break;
        }
        if(strcmp(a,"2")==0){
            A=2;break;
        }
        if(strcmp(a,"3")==0){
            A=3;break;
        }
        if(strcmp(a,"4")==0){
            A=4;break;
        }
        if(strcmp(a,"5")==0){
            A=5;break;
        }
        if(strcmp(a,"6")==0){
            A=6;break;
        }
        else{
        cout<<"你输入的指令无效,请重新输入!!!"<<endl;
        continue;
        }
    }
}
  switch(A){
    case 1:K=book.Login(head);book.Add_List(K,head);
           book.Prvation_Book(head);
           break;       //cout<<"增加书籍"<<endl;break;
    case 2:book.Login(head);book.Delete_List(head);
           book.Prvation_Book(head);
           break;      //cout<<"删除书籍"<<endl;break;
    case 3:book.Login(head);book.Modify_List(head);
           book.Prvation_Book(head);
           break;    //cout<<"修改书籍"<<endl;break;
    case 4:book.Login(head);book.Print_List(head);
           break;     //cout<<"查询书籍"<<endl;break;
    case 5:book.Login(head);book.Search_List(head);
           break;    //cout<<"查询书籍"<<endl;break;
    case 6:return 6; //返回值为判断是否返回主菜单;
    default:break;
  }
}
//初始的控制区域
int Menu_Manage::Control_Initial(U_B_S* head_safe,B_I* head_book)
{
    int b=0;
    int A=0;
    char a[2];
  while(1){
    cin>>a;
    if(strlen(a)>1){
        cout<<"你输入的指令无效,请重新输入!!!"<<endl;
        continue;
    }
    else{
        if(strcmp(a,"1")==0){
            A=1;break;
        }
        if(strcmp(a,"2")==0){
            A=2;break;
        }
        if(strcmp(a,"3")==0){
            A=3;break;
        }
        else{
        cout<<"你输入的指令无效,请重新输入!!!"<<endl;
        continue;
        }
    }
  }
    switch(A){
        //借阅管理系统
        case 1:
        while(1){
        system("cls");
        Menu3_Borrow_Still();
        book.Login(head_book);
        b=Control_Borrow_Still(head_safe,head_book);
        if(b==6){break;}
        system("pause");
        system("cls");
        }break;
        //书库管理系统
        case 2:while(1){
        system("cls");
        Menu4_BookInformation();
        b=Control_BookInformation(head_book);
        if(b==6){break;}
        system("pause");
        system("cls");
        }break;
        case 3:cout<<"感谢您的本次访问!!!"<<endl;exit(0);system("pause");break;
        default:break;
    }
}
#endif // MENU_MANAGE_H

这是Safe_Manage.h
#ifndef SAFE_MANGE_H
#define SAFE_MANGE_H
#include<iostream>
#include<conio.h>
#include<cstdio>
#include<string.h>
#include<windows.h>
using namespace std;
/**
 *                     安全系统——借阅——还书
 *  1.我将安全系统于图书的借阅和还书,写在一起,目的是为了,
 *    可以达到多个用户使用的情况,即创建不同账户其借书还书信息是不同的
 *  2.抽象安全系统的类,得到,1.账号2.密码3.密保(用于找回密码)4.借书信息
 *    (编号,书名,作者,出版社)5.还书信息
 *  3.其借书于还书的本质就是,增与删除(搜索+修改);
 *  4.怎样实现,借书库存量减少,还书库存量增加呢?
 *    思想:获得图书系统的头链表地址,跟随借书进行遍历;
 *    如果借书,就当前pmove(假如说为指向图书系统的指针)的书籍信息的库存量减一
 *    同样还书就加一,这也是为什么我把图书系统的头节点创建在主函数上
 *    (这样就可以共享链表信息,以便借书,还书时对图书库存量修改);
 *  5.以上是我的思想;
 */
class Safe_Mange
{
    public:
        virtual ~Safe_Mange() {}
        char user_ID[30];//用户ID
	    char user_Secret[30];//用户密码
	    char user_Problem[30];//用户密保
	    char Serial_Number[20];//编号;
        char Book_Title[20];//书的名字;
        char Book_Author[20];//书的作者;
        char Book_Publisher[20];//出版商;
protected:
private:

};
typedef struct Users_Borrow_Still
{
    Safe_Mange safe;
	struct Users_Borrow_Still *next;
}U_B_S;
class Safe_Mange_Function
{
private:
   // Safe_Mange_Function();
    //~Safe_Mange_Function();
public:
//用户ID查重;
int Compare_ID(U_B_S*,char [100]);
//创建储存用户信息的链表头
U_B_S *Create_head();
//新增或注册的模块
void Add_ID(U_B_S*,U_B_S*);
//用于找回密码的模块
void Seek_ID(U_B_S*);
//用于修改用户密码模块
void Modify(U_B_S*);
//用于打印所有用户账号信息的模块
void Printf_All_ID(U_B_S*);
//用于加载到栈内存的模块
U_B_S *Load_All_ID(U_B_S*);
//用于保存账户信息的模块;
void Preservation_ID(U_B_S*);
//用于登录的模块;
int Loagin(U_B_S*);
protected:

};
class Borrow_Still_Mange_Function
{
private:

public:
//归还书籍
void Still_Book(U_B_S*,B_I*);
//借阅情况
void Print_All_Borrow(U_B_S*);
//借阅书籍
void Borrow_Book(U_B_S*,B_I*);
//功能待加
void B_S();
protected:
};
/**
 *   我是怎样的思想:
 *   我让每个账户成为借书的头节点;
 *   这样我就可以实现,不同账户借书情况不同,可以更加接近实际应用;
 */
//归还书籍;
void Borrow_Still_Mange_Function::Still_Book(U_B_S* head_safe,B_I* head_book)
{
    char ID[30];char Secret[30];char Serial_Number[20];int a=0;int A=0;
    U_B_S* pmove1_Back=NULL;
    U_B_S* move_ID=head_safe->next;//第一个账户信息;
    U_B_S* pmove1=NULL;
    B_I* pmove2=head_book->next;//这是书籍信息的第一个有效数据;
while(1)
{
    cout<<"你正在办理归还书籍手续......"<<endl;
          cout<<"请输入你的账号:";
          cin>>ID;
          cout<<"请输入你的密码:";
          cin>>Secret;
    while(move_ID!=NULL){
        if((strcmp(ID,move_ID->safe.user_ID)==0)&&(strcmp(Secret,move_ID->safe.user_Secret)==0)){
        A++;
          pmove1=move_ID->next;//用户借的第一本书
          pmove1_Back=move_ID;//用户账号信息;
          break;
        }
        move_ID=move_ID->next;
    }
    if(A!=0){break;}
    else{
            cout<<"该用户不存在"<<endl;
            goto Endl;
    }
}
    if(strcmp(pmove1->safe.Serial_Number,"默认")==0){
          cout<<"你没有借书记录"<<endl;
    }
    else{
        a++;
        while(pmove1!=NULL){
                cout<<"请输入要归还的书籍编号:";
                cin>>Serial_Number;
                    if(strcmp(Serial_Number,pmove1->safe.Serial_Number)==0){//若找到该书
                        pmove1_Back->next=pmove1->next;
                        delete pmove1;
                        while(pmove2!=NULL){
                            if(strcmp(pmove2->book.Serial_Number,Serial_Number)==0){
                                pmove2->book.Book_number+=1;
                                break;
                            }
                            pmove2=pmove2->next;
                        }
                        cout<<"还书成功"<<endl;system("pause");a++;
                    }
              pmove1=pmove1->next;
              pmove1_Back=pmove1_Back->next;
              if(strcmp("默认",pmove1->safe.user_ID)!=0){
                    break;//若用户ID不等于默认了说明已经遍历到下一个用户信息了,
                    //即当前用户没有借书;
              }
        }
    }
    if(a==1){cout<<"你没有借该书的记录"<<endl;system("pause");}
Endl:
cout<<"";
}
//借阅情况
void Borrow_Still_Mange_Function::Print_All_Borrow(U_B_S* head_safe)
{
    int a=0;char ID[30];char Secret[30];int A=0;
    U_B_S* pmove1=head_safe->next;
    U_B_S* pmove2=NULL;
while(1)
{
    cout<<"你正在办理查询借阅书籍情况的手续......"<<endl;
          cout<<"请输入你的账号:";
          cin>>ID;
          cout<<"请输入你的密码:";
          cin>>Secret;
while(pmove1!=NULL){
    if((strcmp(ID,pmove1->safe.user_ID)==0)&&(strcmp(Secret,pmove1->safe.user_Secret)==0)){
          A++;
          cout<<"验证成功..."<<endl;
          pmove2=pmove1->next;//第一个有效信息;
          break;
    }
    pmove1=pmove1->next;
}
    if(A!=0){break;}
    else{
    cout<<"该用户不存在"<<endl;
    continue;
    }
}
   if(strcmp(pmove2->safe.Serial_Number,"默认")==0){cout<<"没有借书记录"<<endl;}
   else{
        while(pmove2!=NULL){
        cout<<"编号:"<<pmove2->safe.Serial_Number<<"\t\t"<<"书名:"<<pmove2->safe.Book_Title<<endl;
        pmove2=pmove2->next;
        if(strcmp(pmove2->safe.Serial_Number,"默认")==0){
           break;
        }
        }
   }
}
//借阅书籍
void Borrow_Still_Mange_Function::Borrow_Book(U_B_S* head_safe,B_I* head_book)
{
    char ID[30];char Secret[30];char Serial_Number[20];int a=0;int A=0;
    U_B_S* pmove1_Back=NULL;
    U_B_S* move_ID=head_safe->next;//第一个账户信息;
    U_B_S* pmove1=NULL;
    U_B_S* pnew=NULL;
    B_I* pmove2=head_book->next;//这是书籍信息的第一个有效数据;
    while(1)
{
    cout<<"你正在办理借阅书籍的手续......"<<endl;
          cout<<"请输入你的账号:";
          cin>>ID;
          cout<<"请输入你的密码:";
          cin>>Secret;
    while(move_ID!=NULL){
        if((strcmp(ID,move_ID->safe.user_ID)==0)&&(strcmp(Secret,move_ID->safe.user_Secret)==0)){
        A++;
          pmove1=move_ID->next;//用户借的第一本书或者是第二个用户;
          pmove1_Back=move_ID;//用户账号信息;
          break;
        }
        move_ID=move_ID->next;
    }
    if(A!=0){break;}
    else{
            cout<<"该用户不存在"<<endl;
            goto Endl;
    }
}
        cout<<"请输入你想借的书籍编号:";
        cin>>Serial_Number;
        while(pmove2!=NULL){
            if((strcmp(pmove2->book.Serial_Number,Serial_Number)==0)&&(pmove2->book.Book_number!=0)){
                a++;
                pnew=new U_B_S;
                strcpy(pnew->safe.user_ID,"默认");
                strcpy(pnew->safe.user_Secret,"默认");
                strcpy(pnew->safe.user_Problem,"默认");
                strcpy(pnew->safe.Serial_Number,pmove2->book.Serial_Number);
                strcpy(pnew->safe.Book_Title,pmove2->book.Book_Title);
                strcpy(pnew->safe.Book_Author,pmove2->book.Book_Author);
                strcpy(pnew->safe.Book_Publisher,pmove2->book.Book_Publisher);
                pmove1_Back->next=pnew;
                pnew->next=pmove1;
                pmove2->book.Book_number-=1;
                break;
            }
            pmove2=pmove2->next;
        }
          if(a==0){cout<<"该编号不存在,或者书籍库存量为零"<<endl;}
Endl:
cout<<"";
}
//功能待加
void Borrow_Still_Mange_Function::B_S()
{
           cout<<"------------------------本产品介绍如下--------------------------"<<endl;
           cout<<"1.还书,借书都需要登录账号密码.加强安全,也为了统计借书还书情况."<<endl;
           cout<<"2.借书还书以及查询书籍信息都是按照唯一编号来的(唯一编号,每种书籍都特有一种编号)如:X123,G124等"<<endl;
           cout<<"3.不同账户,代表不同用户的使用情况."<<endl;
           cout<<"-----------------------------------------------------------------"<<endl;
           cout<<"感谢你的使用"<<endl;
}
//用户ID查重;
int Safe_Mange_Function::Compare_ID(U_B_S *p,char Users_ID[100])
{
    U_B_S *Move;
	Move=p->next;
	while(Move!=NULL){
		if(strcmp(Users_ID,Move->safe.user_ID)==0){
			return 0;
		}
		Move=Move->next;
	}
	if(Move==NULL){
		return 1;
	}
}
//创建储存用户信息的链表头
U_B_S *Safe_Mange_Function::Create_head()
{
    U_B_S *head;
	head= new U_B_S;
	if(head==false){
		cout<<"头节点内存申请失败!!!"<<endl;
		system("pause");
		exit(1);
	}
	head->next=NULL;
	return head;
}
//新增或注册的模块
void Safe_Mange_Function::Add_ID(U_B_S *p,U_B_S *C)
{
    int x;
	int n;
	char ID_LinShi[30];
	char Secret_LinShi[30];
	char Problem_LinShi[30];
	FILE *fp;
	U_B_S *pnew=NULL;
	fp=fopen("D:/C/users_ID.txt","r");
	if(fp==NULL){
		cout<<"新增节点时打开文件失败!!"<<endl;
		system("pause");
		exit(1);
	}
	fscanf(fp,"%s %s %s",ID_LinShi,Secret_LinShi,Problem_LinShi);
	fclose(fp);
	if(strlen(ID_LinShi)>1){
		cout<<"你已经注册过,是否选择继续添加用户:\n1.是 2.否"<<endl;
	while(1){
        cin>>n;
		if(n==2){
			goto end1;
		}
		break;
	}
}
	pnew=new U_B_S;
	if(pnew==false){
		cout<<"新增节点内存申请失败!!!"<<endl;
		system("pause");
		exit(1);
	}
	cout<<"账号长度不超过十个字符"<<endl;
	cout<<"请输入注册信息:"<<endl;
	while(1){
		cout<<"账号:";
	    cin>>pnew->safe.user_ID;
	    x=Compare_ID(C,pnew->safe.user_ID);
	    if(x==0){
	    	cout<<"你注册的账号重复!!!"<<endl;
			continue;
		}
	    if(strlen(pnew->safe.user_ID)>10){
		cout<<"你输入的账号太长,请重新输入!!"<<endl;
		system("pause");
		continue;
	    }
		break;
	}
	cout<<"密码不能超过十个字符"<<endl;
	while(1){
		cout<<"密码:";
		cin>>pnew->safe.user_Secret;
		if(strlen(pnew->safe.user_Secret)>10){
			cout<<"你输入的密码过长,请重新输入!!!"<<endl;
			system("pause");
			continue;
		}
		break;
	}
	cout<<"密保不超过十字符:"<<endl;
	while(1){
		cout<<"密保:";
		cin>>pnew->safe.user_Problem;
		if(strlen(pnew->safe.user_Problem)>10){
			cout<<"你输入的密保过长,请重新输入!!!"<<endl;
			system("pause");
			continue;
		}
		break;
	}
	strcpy(pnew->safe.Serial_Number,"默认");
    strcpy(pnew->safe.Book_Title,"默认");
    strcpy(pnew->safe.Book_Author,"默认");
    strcpy(pnew->safe.Book_Publisher,"默认");
	pnew->next=NULL;
	p->next=pnew;
end1:
cout<<"";
}
//用于找回密码的模块
void Safe_Mange_Function::Seek_ID(U_B_S *p)
{
    char Seek_ID_LinShi[30];
	U_B_S *k=NULL;
	k=p->next;//k为第一个有效数据;
	cout<<"密保不超过十个字符"<<endl;;
    while(1){
    	cout<<"请输入你要寻找的账户密保:";
	    cin>>Seek_ID_LinShi;
	    if(strlen(Seek_ID_LinShi)>10){
		cout<<"你输入的密保过长,请重新输入!!"<<endl;
		system("pause");
		continue;
	    }
	    break;
	}
	while(k!=NULL){
		if(strcmp(k->safe.user_Problem,Seek_ID_LinShi)==0){
			cout<<"已找到该用户,信息如下:"<<endl;
			cout<<"账号:"<<k->safe.user_ID<<"密码:"<<k->safe.user_Secret<<"密保:"<<k->safe.user_Problem<<endl;
			system("pause");
		}
		k=k->next;
	}
}
//用于修改用户密码模块
void Safe_Mange_Function::Modify(U_B_S *p)
{
    char Problem[30];
	U_B_S *k=NULL;
	k=p->next;
	cout<<"密保长度不超过十个字符"<<endl;
	cout<<"请输入你要修改的账户的密保:"<<endl;
	cin>>Problem;
	while(k!=NULL){
		if(strcmp(k->safe.user_Problem,Problem)==0){
			cout<<"你原来的账户信息如下:"<<endl;
			cout<<"账号:"<<k->safe.user_ID<<"密码:"<<k->safe.user_Secret<<"密保:"<<k->safe.user_Problem<<endl;
		    while(1){
		    		cout<<"密码长度不超过十个字符,请输入你要修改的密码:"<<endl;
			        cin>>k->safe.user_Secret;
			        if(strlen(k->safe.user_Secret)>10){
				    cout<<"你修改后的密码太长,请重新输入!!"<<endl;
				    system("pause");
				    continue;
			        }
			        break;
			}
		}
		k=k->next;
	}
}
//用于打印所有用户账号信息的模块
void Safe_Mange_Function::Printf_All_ID(U_B_S *p)
{
    U_B_S *k;
	k=p;
	k=k->next;
	cout<<"结果如下:"<<endl;
	while(k!=NULL){
            cout<<"账号:"<<k->safe.user_ID<<endl;
		k=k->next;
	}
	system("pause");
}
//用于加载到栈内存的模块
U_B_S *Safe_Mange_Function::Load_All_ID(U_B_S *p)
{
    U_B_S *pnew=NULL;
	FILE *fileopen=NULL;
	fileopen=fopen("D:/C/users_ID.txt","a+");
	if(fileopen==NULL){
		cout<<"不能打开文件"<<endl;
		system("pause");
		exit(1);
	}
	while(1){
		pnew=new U_B_S;
		if(pnew==false){
			cout<<"内存申请失败"<<endl;
		}
			if(fscanf(fileopen,"%s %s %s %s %s %s %s\n",pnew->safe.user_ID,pnew->safe.user_Secret,pnew->safe.user_Problem,pnew->safe.Serial_Number,pnew->safe.Book_Title,pnew->safe.Book_Author,pnew->safe.Book_Publisher)==EOF){
				break;
			}                                                                                         //为啥呢
		pnew->next=NULL;
		p->next=pnew;
		p=p->next;
	}
	fclose(fileopen);
	return p;
}
//用于保存账户信息的模块;
void Safe_Mange_Function::Preservation_ID(U_B_S *p)
{
    FILE *fp;
	U_B_S *k=NULL;
	k=p->next;
	fp=fopen("D:/C/users_ID.txt","w");
	if(fp==false){
		cout<<"保存时打开文件失败!!"<<endl;
		system("pause");
		exit(1);
	}
	while(k!=NULL){
		fprintf(fp,"%s %s %s %s %s %s %s\n",k->safe.user_ID,k->safe.user_Secret,k->safe.user_Problem,k->safe.Serial_Number,
          k->safe.Book_Title,k->safe.Book_Author,k->safe.Book_Publisher);
		k=k->next;
	}
	fclose(fp);
}
//用于登录的模块;
int Safe_Mange_Function::Loagin(U_B_S *p)
{
       //int i;
	int count=0;
	U_B_S *k=NULL;
	k=p->next;
	char ID[30];
	char Scret[30];
int s=0;
while(1){
	FILE *fp;
	fp=fopen("D:/C/users_ID.txt","r");
	if(fp==NULL){
		cout<<"登陆时打开文件失败!!!"<<endl;
		system("pause");
		exit(1);
	}
	while(1){
		count++;
	    cout<<"账号:";
	    cin>>ID;
	    if(strlen(ID)>10){
		   cout<<"你输入的账号太长,请重新输入!!"<<endl;
		   system("pause");
		   continue;
	    }
	    break;
}
char ch;
//char str[20];
int i=0;
cout<<"密码:";
	do{
		char ch;
		ch=getch();
		if(ch==' '){
			continue;
		}
		if(ch=='\r'){
			break;
		}
		if(ch=='\b'&&i>=0){
			if(i==0){
				continue;
			}
			printf("\b \b");
			i=i-1;
		    Scret[i+2]='\0';
			continue;
		}
		else{
		Scret[i++]=ch;
		cout<<"*";
		Scret[i]='\0';
		}
	}while(1);
	while(k!=NULL){
		if((strcmp(ID,k->safe.user_ID)==0)&&(strcmp(Scret,k->safe.user_Secret)==0)){
        system("cls");
        cout<<"\t\t\t   登陆成功"<<endl;
        cout<<"---------------------------------------------------------"<<endl;
        cout<<"\t\t欢迎来到huangyusen图书管理系统"<<endl;
        cout<<"---------------------------------------------------------"<<endl;
        system("pause");
        system("cls");
		    return s=1;
		}
		k=k->next;
	}
	cout<<endl;
	cout<<"你输入的信息有误请检查输入!!!"<<endl;
	system("pause");
	continue;
	if(count==3){
		cout<<"你输入的次数过多,请稍后在登录"<<endl;
		break;
	}
}
}









#endif // SAFE_MANGE_H
上一篇:MySQL错误修复:Table crashed repair


下一篇:Macos下重置MySQL密码