c++实现图书管理系统

一.简介

实现一个小型的图书管理系统,方便读者借书还书及办理各种手续,更方便工作人员对
图书进行更有效的管理,是一个记录图书借记和存储的工具。

二.程序主要功能

该程序的主要功能有:
读者功能:
可进行读者注册、修改密码、查询书籍、查询借阅记录。

读者:

 

 

管理员:

 


图书信息管理
可以进行添加新书、删除图书、修改、显示所有书籍等操作。
其中添加内容包括:书名、ISBN 编号、作者、出版社
是否在架,方便读者根据不同需要进行查找、查看;
(数据全部存储在文本文件内)

添加书籍:向图书管理系统中添加新书

显示书籍:显示图书的所有书籍信息

书籍删除:按照书名进行删除指定书籍

查找书籍:按照姓名查看指定书籍信息

修改书籍:按照姓名重新修改指定书籍

退出图书管理系统:退出当前使用的系统
————————————————

三.程序运行平台

程序语言:C++

IDEA: xcode

 

代码:

#ifndef UNTITLED4_LIBRARY_H

#define UNTITLED4_LIBRARY_H

#include <iostream>

#include <string>

#include <fstream>

#include <ctime>

 

using namespace std;

const int size = 200;

int jd;

 

//书籍类

class Book{

protected:

   string name;  // 书名

   string writer;    // 作者

   string press;     // 出版社

   string leibie; // 类别

   string ISBN; // 编码

   int num = 0; // 库存

 

   friend class Library;

public:

    Book(){name = "",writer = "",press = "",ISBN = "";};

   int bk_num;       // 数量

   

   

   void set_name();

   void set_writer();

   void set_press();

   void set_ISBN();

   void set_leibie();

   void set_num();

    

   string get_name(){return name;}

   string get_writer(){return writer;}

   string get_press(){return press;}

   string get_ISBN(){return ISBN;}

   

   friend istream & operator >> (istream & is,Book & book){

       is >> book.name >> book.writer >> book.press >> book.leibie >> book.num >> book.ISBN;

       return is;

   }

   friend ostream & operator << (ostream & os,Book & book){

       os << book.name << "   " << book.writer <<  "   "  << book.press << "  "  << book.leibie << "   " << book.num << "      " << book.ISBN << endl;

       return os;

   }

};

 

 

 

//用户类

class User{

protected:

   string name;    // 用户名

   string password;  // 密码

   friend class Library;

 

public:

    User(){name = "",password = "";};

   char id; // 判断用户类型

   int key; // 判断用户当前情况

   int nums = 0;    // 当前用户数量

   int bk_size = 0; // 当前用户借阅书籍数量

   string br_name;    // 借阅书籍名称

   void set_username();

   void set_password();

   bool is_login(int);

   bool is_match(string,string); // 匹配用户名

   bool is_teacher();bool is_student();

   string get_username(){return name;}

   string get_password(){return password;}

   void revise_password(); // 修改密码

   void re_gister(); // 注册

   int log_in(string,char);

   void user_information();

   void read(string); // 浏览数组数据

   void save();  // 文本数据存储至数组函数

   int pos(string); // 获取用户名在文件中第几行

   bool is_password(string str);

   void add_user();

   void del_user();

  

 

};

User tp;

 

//图书管理类

class Library : public User,Book

{

public:

   int key;  // 判断用户是否正常登录

   int lent(User &); // 还书

   int pos();

   int bk_size = 0;

   void read();

   void borrow(char,User &);

   void show_history(); // 个人借阅记录查询

   void show_list(); // 打印书籍信息

   void view_history(char);

   Book* show_info(User&);

   const string get_time();

   bool is_lent();

   void renew(User &);

   void save();

   void modify(); // 修改图书信息

   bool is_borrow();

   void research();

   void add_book();

   void del_book(User &);

};

   void menu();

   void denglu();

   void jiehuanshu();

#endif /* library_system_h */

 

 

Book* bk = new Book[size];

User* ur = new User[size];

 

string GetLocaltime(){// 获取系统当前时间

   time_t now;

   time(&now);

   struct tm* lt;

   lt = localtime(&now);

   char buffer[50];

   sprintf(buffer, "%d/%d/%d% 2d:%2d",(int)lt->tm_year+1900 ,(int)(lt->tm_mon+1),(int)lt->tm_mday,(int)lt->tm_hour,(int)lt->tm_min);

   return string(buffer);

}

string Getdeadline(){ // 计算还书日期

   time_t now;time_t k;

   k = time(&now) + 1728000;

   struct tm* lt;

   lt = localtime(&k);

   char buffer[50];

   sprintf(buffer, "%d/%d/%d%",(int)lt->tm_year+1900 ,(int)(lt->tm_mon+1),(int)lt->tm_mday);

   return (buffer);

}

void Book::set_name(){

   cin >> name;

}

void Book:: set_writer(){

   cin >> writer;

}

void Book:: set_press(){

   cin >> press;

}

void Book:: set_ISBN(){

   cin >> ISBN;

}

void Book::set_leibie(){

   cin >> leibie;

}

void Book::set_num(){

    cin >> num;

}

//user

// 获取用户文本数据

bool User::is_login(int n){

   if(n == 1)

       return 1;

   else

       return 0;

}

void User::read(string filename){

   ifstream infile;

   nums = 0;

   infile.open(filename,ios::in);

   while (!infile.is_open()) {

       cout << "Could not open it\n";

       exit(0);

   }

   if(filename == "user.txt"){

       for (int i = 0; infile.peek()!=EOF; i++) {

        if(infile.fail())

            break;

        infile >> ur[i].name;

        infile >> ur[i].password;

           nums++;

   }

       nums = nums - 1;

}

   else

       cout << "【系统提示】暂未开通此模块\n";

   

       infile.close();

   }

 

// 保存新用户信息

void User::save(){      // 添加到user info.txt文件

   ofstream outfile;

   outfile.open("user.txt",ios::out);

   int i = 0;

   while(!outfile.eof()){

       outfile << ur[i].name << "    " << ur[i].password << endl;

       i++;

   }

   outfile.close();

}

void User:: set_username(){

   int a;

   cout << "输入用户名:";

   cin >> tp.name;

   a = tp.is_match(tp.name, "register");

   while(a == 0){

       cout << "【警告】用户名重复,请重新输入:\n";

       cin >> tp.name;

       a = tp.is_match(tp.name, "register");

   }

}

void User:: set_password(){

    string key1,key2;

   cout << "请输入密码:\n";

    cin >> key1;

   cout << "再次输入密码:\n";    //崩溃写不来了 ^^

    

   do

   {

       cin >> key2;

       if(key1!=key2)

           cout << "两次密码不一致,请重新输入:\n";

   }while(key1 != key2);

    tp.password = key2;

}

void User:: revise_password(){

   fstream file;

   string str;string key1,key2; int a;int b;

   tp.read("user.txt");

   cout << "输入要修改的用户名:\n";

   cin >> str;

   a = tp.is_match(str, "log");

   

  be: if(a == 0){

       cout << "用户名不存在,请重新输入:\n";

       cin >> str;

       a = tp.is_match(str, "log");

       goto be;

   }

   else

       b = tp.pos(str);

       cout << "请输入原密码:\n";

   cin >> str;

rt:  if(str == ur[b].password)

       file << ur[b].password;

    else {

           cout << "【警告】密码错误,请重新输入:\n";

           cin >> str;

           goto rt;

       }

   

   cout << "输入新密码:\n";

   cin >> key1;

   cout << "再次输入:\n";

   cin >> key2;

go:   if(key1 == key2)

       ur[b].password = key1;

   else

   {

       cout << "【警告】两次密码不一致,请重新输入:\n";

       cin >> key2;

       goto go;

   }

   tp.save();

   cout << "【系统提示】修改成功!";

  

  }

 

// 匹配用户名

bool User::is_match(string str,string mode){

// 匹配函数分为注册用和登录用,如果登录时存在此用户名返回true,注册时存在返回false

   ifstream infile;

   int i;

   infile.open("user.txt",ios::in);

    for (i = 0; !infile.eof(); i++) {

        infile >> ur[i].name;

        infile >> ur[i].password;

        if(str == ur[i].name && mode == "register"){

            return 0;

        }

    

        else if(str == ur[i].name && mode == "log")

            return 1;

   }

 

   if(mode == "register")

       return 1;

   

   else

       return 0;

   

        infile.close();

   return 0;

}

bool User::is_password(string str){

   ifstream infile;

   infile.open("user.txt",ios::in);

    for (int i = 0; infile.peek()!=EOF; i++) {

        infile >> ur[i].name;

        infile >> ur[i].password;

        if(str == ur[i].password)return 1;

   }

   return 0;

}

// 计数

int User::pos(string str){

   int i = 0;

   ifstream in;

   User* buffer = new User [size];

   in.open("user.txt");

   while(in.peek()!=EOF){

       in >> buffer[i].name;

       in >> buffer[i].password;

       if(str == buffer[i].name)

           break;

       i++;

   }

   in.close();

   delete [] buffer;

   return i;

}

// 注册

void User:: re_gister(){

   fstream fp;

   fp.open("user.txt",ios::app);

    while(!fp.is_open())

        cout << "could not open";

   tp.set_username();

   tp.set_password();

   cout << "【系统提示】注册成功\n";

   fp << tp.name << "    " << tp.password << endl;

    fp.close();

}

// 登录

   int User::log_in(string filename, char jd){

       int i;  // 记录用户名在文件的位置

       int index = 0;

       string str;

       char password[30];

       string key;

   switch (jd) {

   case '1':

       {

           cout << "请输入用户名:\n";    // 学生登录

           cin >> tp.name;

           int a = tp.is_match(tp.name,"log");

           while(!a){

               cout << "【警告】用户名不存在!请重新输入:\n";

               cin >> tp.name;

               a = tp.is_match(tp.name,"log");

           }

           i = tp.pos(tp.name);

           cout << "请输入密码:\n";

           cin >> key;

           for(int i = 0; i < index; i++)

              key += password[i];

           tp.password = key;

           // 验证密码

           while(1){

               tp.read("user.txt");

               if(tp.password == ur[i].password){

                   tp.key = tp.is_login(1);

                   cout << "【系统提示】登录成功!\n";break;

               }

               else

               {

                   cout << "【警告】密码错误,请重新输入:\n";

                   cin >> tp.password;

               }

           }

           break;

       }

       case '2':

       {

           char buffer[20];

           char str[20];

           cout << "输入管理员密码:\n";

           cin >> str;

           ofstream outfile;

           outfile.open("admin.txt",ios::out);

           outfile << "123";

           outfile.close();

           ifstream in(filename);

           in.getline(buffer,20);

           if(strcmp(str,buffer) == 0){

              int a = tp.is_login(1);

               cout << "登录成功" << endl;

               return a;

       }

           do

           {

               cout << "密码错误,请重新输入:\n";

               cin >> str;

           }while(strcmp(str,buffer));

           break;

       }

       default:

           break;

   }

       return 1;

}

 // 个人信息

void User::user_information(){

   fstream file;

   string str;

   char temp[100];

   str = tp.name;

   file.open("user info",ios::in || ios::app);

   int i = 0;

   

   while(file.peek()!=EOF){

       if (str == ur[i].name){

           file.getline(temp,100);

       }

          

       else{

           file << endl << str;

           break;

           }

       i++;

     }

}

void User::add_user(){

   ofstream file;

   file.open("user.txt",ios::app);

   tp.set_username();

   tp.set_password();

   

    cout << "【系统提示】添加成功\n";

   file << tp.name << "    " << tp.password << endl;

       file.close();

}

void User::del_user(){

    int a;char aa;

   read("user.txt");

   for(int i = 0; i < nums; i++)

        cout << i+1 << ".用户名:" << ur[i].name << endl;

   cout << "请选择你要删除的用户:\n";

 

    while(1){

        cin >> a;

        if(cin.fail() || a < 0){

            cout << "【系统提示】重新输入:\n";

            cin.clear();

            cin.get();

        }

        else

            break;

    }

   cout << "确定要删除吗? y确定,其他键取消\n";

    cin >> aa;

    if(aa == 'y'){

    for(int i = a-1; i < nums; i++)

        ur[i] = ur[i+1];

        cout << "【系统提示】删除成功!\n";

        save();

    }

  

}

//library

// 获取书籍文本数据

void Library::read(){

   ifstream in("list.txt");

   int i = 0;bk_num = 0;

   while(in.peek()!=EOF){

       in >> bk[i];

       i++;

       bk_num++;

   }

    bk_num--;

   in.close();

}

// 定位文件中的位置

int Library::pos(){

   ifstream in;

   Book* buffer = new Book [size];

   in.open("list.txt");

   while(in.peek()!=EOF){

       in >> buffer[bk_num];

       bk_num++;

   }

   in.close();

   delete [] buffer;

   return bk_num;

}

// 打印书籍信息到终端

void Library::show_list(){

   read();

   cout << "        --------------   图书信息   ------------" << endl;

   cout << "目前书库内有" << bk_num << "类目" << endl;

   cout << "编号   书名     作者     出版社    类别  库存      ISBN" << endl;

   

   for(int i = 0; i < bk_num; i++)

   cout << " " << i+1 << "     " << bk[i] << endl;

   

}

 

// 借书

void Library:: borrow(char id,User & ps){

   fstream fp;

   fp.open("history.txt",ios::app);

    fstream fp2("reader.txt",ios::app);

    fstream fp3("reader.txt",ios::in);

    char buffer[30];

    while(fp3.peek()!=EOF){

        fp3.getline(buffer,30);

        bk_size++;

    }

 

   read();

   show_list();

   if(tp.id == 1)     // 设置借书数量

       tp.nums = 5;

   else if(tp.id == 2)

       tp.nums = 10;

   int a;int b;string word;string key;string data = word + key;

   cout << "【系统提示】借几本书?______\n";

    while(true){

        cin >> a;

        if(cin.fail() || a < 0){

            cout << "【系统提示】请重新输入:\n";

            cin.clear();

            cin.get();

        }

        else

            break;

        

    }

      while(a--){

       if(tp.id == 1 && a+bk_size > 5){

           cout << "【系统提示】您的借书权限不够,最多借5本书";

           break;

       }

       if(tp.id == 2 && a+bk_size > 10){

           cout << "【系统提示】您的借书权限不够,最多借10本书";

           break;

       }

       cout << "输入借阅书籍序号:\n";

          while(true){

              cin >> b;

              if(cin.fail()){

                  cout << "【系统提示】请重新输入:\n";

                  cin.clear();

                  cin.get();

              }

              else

                  break;

          }

          if(bk[b-1].num == 0)

              cout << "【系统提示】此书库存不够\n";

          bk[b-1].num--;

          fstream fp4("list.txt",ios::out);

          for(int i = 0; i < bk_num; i++)

             fp4 << bk[i] << endl;

          

       cout << "【系统提示】借书成功!\n" << "借书时间:" << GetLocaltime() << endl;

       cout << "还书时间:" << Getdeadline() << endl;  // 用户历史借阅

       bk_size++;

       key = Getdeadline();

       fp2 << tp.name << " " << bk[b-1].name << endl;

       fp2 << key << endl;

       fp << tp.name << "在" << GetLocaltime() << "借了" << bk[b-1].name << endl;

      

 }

    fp.close();

    fp2.close();

}

// 还书

int  Library::lent(User & tp){

    read();

    string book[20];

    string time[20];

    fstream fp;

     int i = 0;

    int a;

    char aa;

    string str[200];

    ifstream file;

    ofstream file2;

    string now = GetLocaltime();

    file.open("reader.txt",ios::in);

    

    while(!file.is_open()){

        cout << "could not open\n";

        exit(EXIT_FAILURE);

    }

    while(file.peek()!=EOF){

        file >> str[i];

            file >> book[i];

            file >> time[i] ;

            i++;

    }

    int n = 1;

    while(n){

    for(int j = 0; j < i; j++){

        if(tp.name == str[j])

            

            cout << j+1 << "." << book[j] << endl;

        else

            continue;

    }

        if(i-1 == 0){

        cout << "【系统提示】您没有借阅书籍\n" << endl;

            return 1;

        }

    else{

    cout << "【系统提示】您有" << i << "本书未还\n" << endl;

    cout << "选择您要归还的书籍:\n";

        

        while(1){

            cin >> a;

            if(cin.fail()){

                cout << "【系统提示】请重新输入:\n";

                cin.clear();

                cin.get();

            }

            else

                break;

    }

    

        for(int j = a-1; j < i; j++){  // 删除前面的内容

            str[j] = str[j+1];

            book[j] = book[j+1];

            time[j] = time[j+1];

    }

      

 

    file2.open("reader.txt",ios::out);

    for(int j = 0; j < i-1; j++){       // 打印到文件里

        file2 << str[j] << " " << book[j] << endl;

        file2 << time[j] << endl;

    }

        i--;

        

        bk[a-1].num++;

        fp.open("list.txt",ios::out);

        for(int k = 0; k < bk_num; k++)

           fp << bk[k] << endl;

        

    if(time[a-1] < now)

        cout << "【系统提示】还书成功!\n";    // 与还书时间做比较

    else

        cout << "【系统提示】还书超时,请缴纳罚金\n";

   

        cout << "【系统提示】是否继续操作,按y确认,其他键退出\n";

        cin >> aa;

        if(aa == 'y')

            n = 1;

        else

            n = 0;

     }

        file.close();

        file2.close();

}

    return 1;

  

}

void Library::renew(User & pr){

    fstream file;

    file.open("reader.txt");

    string str[20];

    string book[20];

    string time[20];

    int i = 0;

    int a;

    string now = Getdeadline();

    while(!file.is_open()){

        cout << "could not open\n";

        exit(EXIT_FAILURE);

    }

    while(file.peek()!=EOF){

        file >> str[i];

            file >> book[i];

            file >> time[i] ;

            i++;

    }

    int n = 1;

    while(n){

    for(int j = 0; j < i; j++){

        if(tp.name == str[j])

            

            cout << j+1 << "." << book[j] << endl;

        else

            continue;

    }

        cout << "选择您要续借的书籍:\n";

        

        while(1){

            cin >> a;

            if(cin.fail() || (a < 0 && a > i)){

                cout << "【系统提示】重新输入:\n";

                cin.clear();

                cin.get();

            }

            else

                break;

        }

           

        time[a-1] = now;

        for(int j = 0; j < i-1; j++){       // 打印到文件里

            file << str[j] << " " << book[j] << endl;

            file << time[j] << endl;

        }

        cout << "【系统提示】续借成功!请您于" << time[a-1] << "归还\n";

        cout << "【系统提示】是否继续操作,按y确认,其他键退出\n";

        char aa;

        cin >> aa;

        if(aa == 'y')

            n = 1;

        else

            n = 0;

     }

    file.close();

    }

 

void Library::save(){

   ofstream out("list.txt");

   for(int i = 0; i < bk_num; i++)

   out << bk[i];

   out.close();

}

// 添加书籍

void Library::add_book(){

   fstream f_ile;

    Book book;

   int count = 0;

   read();

   f_ile.open("list.txt",ios::app);

   while(!f_ile.is_open()){

       cout << "【系统提示】Could not open it, please restart\n";

       exit(0);

   }

   cout << "【系统提示】添加几本书?";

    while(1){

        cin >> count;

        if(cin.fail() || count < 0){

            cout << "【系统提示】重新输入:\n";

            cin.clear();

            cin.get();

        }

        else

            break;

    }

   if(bk_num+count > size){

       cout << "【系统提示】数据库已满\n";

       exit(1);

   }

   

   while(count--){

       cout << "书名:\n";

       book.set_name();

       cout << "作者:\n";

       book.set_writer();

       cout << "出版社:\n";

       book.set_press();

       cout << "类别:\n";

       book.set_leibie();

       cout << "数量:\n";

       book.set_num();

       cout << "ISBN:\n";

       book.set_ISBN();

       f_ile << book;

       

       cout << "录入成功!" << endl;

   }

   f_ile.close();

}

void Library::del_book(User & us){

    read();

    int a;char aa;

   if(bk_num == 0){

       cout << "【系统提示】数据库已空\n";

       exit(1);

   }

   show_list();

   cout << "输入要删除的书籍序号:";

    while(1){

        cin >> a;

        if(cin.fail() || (a < 0 && a > bk_num)){

            cout << "【系统提示】重新输入:\n";

            cin.clear();

            cin.get();

        }

        else

            break;

    }

   read();

    cout << "确定要删除吗? y确定,其他键取消\n";

    cin >> aa;

      if(aa == 'y'){

      for(int i = a-1; i < bk_num; i++)

          bk[i] = bk[i+1];

          cout << "【系统提示】删除成功!\n";

          save();

      }

 

}

 

void Library:: view_history(char id){ // 根据id来区分是由用户还是管理员

   ifstream fp;

    char name[10];

    string book;

    string time;

    char temp[40];

    if(id == '1'){

        fp.open("history.txt",ios::in);

        while(!fp.is_open()){

            cout << "【系统提示】文件打不开";

            EXIT_FAILURE;

        }

        for(int k = 0; k < tp.name.size(); k++)

              name[k] = tp.name[k];

        while(fp.peek()!=EOF){

            fp.getline(temp,40);

            for(int k = 0; k < tp.name.size(); k++){

                if(name[k] == temp[k])

                    cout << temp << endl;

                else

                    continue;

            }

            

        }

            cout << "【系统提示】任意键退出\n";

            char a;

        while(1){

            cin >> a;

            if(cin.fail()){

                cout << "【系统提示】重新输入:\n";

                cin.clear();

                cin.get();

            }

            else

                break;

        }

    }

    

    

    if(id == '2'){

        fp.open("history.txt",ios::in);

        while(!fp.is_open()){

            cout << "【系统提示】文件打不开";

            EXIT_FAILURE;

        }

        

        while(fp.peek()!=EOF){

            fp.getline(temp,40);

            cout << temp << endl;

            continue;

        }

        

         cout << "【系统提示】任意键退出\n";

         char a;

         cin >> a;

    }

    fp.close();

}

void Library::research(){

   read();

   int i;

   int count = 0;

   char a;char aa;

   string str;

   while(1){

       cout << "选择通过什么方式查询:\n" << endl;

       cout << "1.书籍名称" << endl;

       cout << "2.书籍作者" << endl;

       cout << "3.ISBN编码" << endl;

       cout << "4.退出" << endl;

       cin >> a;

   

       if(a=='1'){

           cout << "输入书籍名称\n";

           cin >> str;

           cout << "        --------------   查找图书   ------------" << endl;

           cout << "编号   书名     作者     出版社    类别  库存      ISBN" << endl;

           

           

           for(i = 0; i < bk_num; i++)

           if(str == bk[i].name){

               cout << i+1 << ".     " << bk[i];

               count++;

           }

           if(count == 0)

               cout << "【系统提示】抱歉没有查询到\n";

           else if(count > 0)

               cout << "查询到" << count << "个结果\n";

       }

       else if(a=='2'){

           cout << "输入书籍作者\n";

           cin >> str;

           for(i = 0; i < bk_num; i++)

           if(str == bk[i].writer){

               cout << bk[i];

               count++;

           }

           if(count == 0)

               cout << "【系统提示】抱歉没有查询到\n";

           else if(count > 0)

               cout << "查询到" << count << "个结果\n";

       }

       else if(a=='3'){

           cout << "输入书籍编码\n";

           cin >> str;

           for(i = 0; i < bk_num; i++)

           if(str == bk[i].ISBN){

               cout << bk[i];

               count++;

           }

           if(count == 0)

               cout << "【系统提示】抱歉没有查询到\n";

           else if(count > 0)

               cout << "查询到" << count << "个结果\n";

       }

       else

           break;

      

   cout << "【系统提示】是否继续查询? 按y继续,其他键退出\n";

   cin >> aa;

   if(aa == 'y')

       continue;

   else

       break;

       }

   

   }

void Library::modify(){

    int a;char aa;

    Book* bb = nullptr;

   read();

   show_list();

   if(bk_num == 0){

       cout << "【系统提示】书库没有书籍可修改\n";

       exit(0);

   }

       

   while(1){

       cout << "请选择你要修改的书籍序号:\n";

       cin >> a;

       while(a <= 0){

           cout << "【系统提示】输入错误,请重试\n";

           cin >> a;

       }

       

       cout << "1.修改书名" << endl;

       cout << "2.修改作者" << endl;

       cout << "3.修改编码" << endl;

       cout << "4.修改出版社" << endl;

       cout << "5.修改类别" << endl;

       cout << "6.退出" << endl;

 

       cin >> aa;

       switch (aa) {

           case '1':

               cout << "书名:\n";

               bk[a-1].set_name();

               cout << "修改完成" << endl;

               break;

           case '2':

               cout << "作者:\n";

               bk[a-1].set_name();

               cout << "修改完成" << endl;

               break;

           case '3':

               cout << "ISBN:\n";

               bk[a-1].set_ISBN();

               cout << "修改完成" << endl;

               break;

           case '4':

               cout << "出版社:\n";

               bk[a-1].set_press();

               cout << "修改完成" << endl;

               break;

           case '5':

               cout << "类别:\n";

               bk[a-1].set_leibie();

               cout << "修改完成" << endl;

               break;

           case '6':

               cout << "库存:\n";

               bk[a-1].set_num();

               cout << "修改完成" << endl;

               break;

           default:

               break;

       }

       

       save();

       cout << "【系统提示】请问是否继续更改,y确认,其他键退出:\n";

       cin >> aa;

       if(aa == 'y')

           continue;

       else break;

      

   }

}

 

//界面

void menu(){

   cout << " ------------ 图书管理系统 ------------  " << endl;

   cout << "[1] 注册 " << endl;

   cout << "[2] 登录 " << endl;

   cout << "[3] 退出管理系统 " << endl;

 

}

void denglu(){

   cout << "------------- 登录 ---------------" << endl << endl;

   cout << "[1] 用户登录" << endl;

   cout << "[2] 管理员登录" << endl;

   cout << "[3] 返回主菜单" << endl;

 

}

void jiehuanshu(){

   cout << endl << "[1] 查询书籍" << endl;

   cout << "[2] 借阅书籍" << endl;

   cout << "[3] 归还书籍" << endl;

   cout << "[4] 续借" << endl;

   cout << "[5] 个人借阅查询" << endl;

   cout << "[6] 修改密码" << endl;

   cout << "[7] 退出登录" << endl;

}

void guanliyuan(){

   cout << "[1] 添加书籍" << endl;

   cout << "[2] 删除书籍" << endl;

   cout << "[3] 变更书籍信息" << endl;

   cout << "[4] 查看书库" << endl;

   cout << "[5] 查看用户借阅记录" << endl;

   cout << "[6] 增加用户" << endl;

   cout << "[7] 删除用户" << endl;

   cout << "[8] 退出登录" << endl;

}

 

 

 main.cpp:

#include "library.hpp"

 

int main(){

    Library lb;

    User admin;

    char a;char aa;

    while(1){

s0:   menu();        // 主菜单

      cout << endl << "现在时间:" << GetLocaltime() << endl;

    cin >> a;

    switch (a) {

        

        case '1':

            tp.re_gister();

        case '2':{

            int n = 1;

            while(n){

          denglu();     // 登录界面

             cin >> aa;

            if (aa == '1'){

                    tp.log_in("user.txt", '1');

s1:                jiehuanshu();

                cin >> a;

                    switch (a) {

                        case '1':

                            lb.research();

                            goto s1;

                        case '2':

                            lb.borrow(1, tp);

                            goto s1;

                        case '3':

                            lb.lent(tp);

                            goto s1;

            

                        case '4':

                            lb.renew(tp);

                            goto s1;

                        case '5':

                            lb.view_history('1');

                            goto s1;

                        case '6':

                            tp.revise_password();

                            goto s1;

                        case '7':

                            goto s0;

                        default:

                            goto s1;

                    }

                }

            

            

            else if (aa == '2'){

                admin.log_in("admin.txt", '2');

s2:              guanliyuan();

                cin >> a;

                switch (a) {

                    case '1':

                        lb.add_book();

                        goto s2;

                    case '2':

                        lb.del_book(admin);

                        goto s2;

                    case '3':

                        lb.modify();

                        goto s2;

                    case '4':{

                        char y;

                        lb.show_list(); // 4.9

                        cout << "任意键退出\n";

                        cin >> y;

                        goto s2;

                    }

                    case '5':

                        lb.view_history('2');

                        goto s2;

                    case '6':

                        admin.add_user();

                        goto s2;

                    case '7':

                        admin.del_user();

                        goto s2;

                    case '8':

                        goto s0;

                    default:

                        goto s2;

                }

            }

            else if(aa == '3')

                goto s0;

            else

                n = 1;

        }

    }

        case '3':

            return 0;

        

  }

        

}

    

    return 0;

}

 

本文作者:YAO_YUAN

本文链接:https://www.cnblogs.com/yaoyuan1010/p/16174925.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   YAO_YUAN  阅读(1176)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.