C++實現(xiàn)簡易圖書館管理系統(tǒng)
本文實例為大家分享了C++實現(xiàn)簡易圖書館管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
思路
在本程序中共有四個類:
book類:此類有書的基本信息:書名,編號,作者,價格等,和基本的get()和set()方法。類圖如下:
library類:此類中有一個存放的書的數(shù)組,并且可以對書進行,查詢,借閱,歸還,添加,等相關(guān)操作。類圖如下:
reader_infor類:此類中有讀者的相關(guān)信息:名字,學(xué)號,年級,借書數(shù)量。和基本的get()和set()方法,類圖如下:
reader_admin類:此類中有一個存放讀者對象的數(shù)組,并且可以進行添加讀者,修改讀者信息等操作。類圖如下:
登陸頁面如下
讀者頁面
管理員頁面
在本程序過程中的不足:
1.書和讀者的存儲是通過靜態(tài)數(shù)組實現(xiàn)的,如果用動態(tài)數(shù)組的話更好一點。
2.還有一些其他點感覺寫的不是很好,但還不知道要怎么改。
后面有時間會再完善一下。
代碼
“book.h"
#pragma once #include <iostream> using namespace std; class book { public: ?? ?book(); ?? ?book(string name, int n_number, int s_number, int id, string author, double price); ?? ?//get方法 ?? ?string get_name(); ?? ?int get_n_number(); ?? ?int get_s_number(); ?? ?int get_id(); ?? ?string get_author(); ?? ?double get_price(); ?? ?//set方法 ?? ?void set_name(string name); ?? ?void set_n_number(int n_number); ?? ?void set_s_number(int s_number); ?? ?void set_id(int id); ?? ?void set_author(string author); ?? ?void set_price(double price); private: ?? ?string name;//名稱 ?? ?int n_number;//現(xiàn)有數(shù)量 ?? ?int s_number;//庫存數(shù)量 ?? ?int ?id;//編號 ?? ?string author;//作者 ?? ?double price;//價格?? ? };
"book.cpp"
#include "book.h" book::book() { ?? ?name = " ?"; ?? ?n_number = 0; ?? ?s_number = 0; ?? ?id = 0; ?? ?author = " ?"; ?? ?price = 0; } book::book(string name, int n_number, int s_number, int id, string author, double price) { ?? ?this->name = name; ?? ?this->n_number = n_number; ?? ?this->s_number = s_number; ?? ?this->id = id; ?? ?this->author = author; ?? ?this->price = price; } //get方法。 string book::get_name() { ?? ?return name; } int book::get_n_number() { ?? ?return n_number; } int book::get_s_number() { ?? ?return s_number; } int book::get_id() { ?? ?return id; } string book::get_author() { ?? ?return author; } double book::get_price() { ?? ?return price; } //set方法。 void book::set_name(string name) { ?? ?this->name = name; } void book::set_n_number(int n_number) { ?? ?this->n_number = n_number; } void book::set_s_number(int s_number) { ?? ?this->s_number = s_number; } void book::set_id(int id) { ?? ?this->id = id; } void book::set_author(string author) { ?? ?this->author = author; } void book::set_price(double price) { ?? ?this->price = price; }
"library.h"
#pragma once #include"reader_admin.h" #include "book.h" using namespace std; class library { public: ?? ?library(); ?? ?int get_m();//返回存放書的總數(shù)量 ?? ?int get_place();//返回查找到書的位置 ?? ?void set_book1();//存放書籍 ?? ?void show_book();//顯示書籍的相關(guān)信息 ?? ?bool search();//查找書籍 ?? ?//修改書的相關(guān)信息 ?? ?bool chang_book1(); ?? ?bool borrow_book(reader_admin&r_ad);//借書 ?? ?bool return_book(reader_admin& r_ad);//還書 private: ?? ?int m;//存放書的總數(shù)。 ?? ?int place;//記錄查找到書的位置。 ?? ?book book1[1000];//一個存放1000本書的數(shù)組。 };
librayry.cpp
#include "library.h" #include "book.h" //book類作為書籍的基類 //書共有的屬性:名稱,現(xiàn)有數(shù)量,庫存數(shù)量,編號,作者,價格 library::library() { ?? ? m = 0; } int library::get_m() { ?? ?return m; } int library::get_place() { ?? ?return place;//返回查找到書的位置。 } void library::set_book1() { ?? ?cout << "請輸入書的名稱:" << endl; ?? ?string name; ?? ?cin >> name; ?? ?cout << "請輸入書的現(xiàn)存數(shù)量:" << endl; ?? ?int now; ?? ?cin >> now; ?? ?cout << "請輸入書的庫存數(shù)量:" << endl; ?? ?int s; ?? ?cin >> s; ?? ?cout << "請輸入書的編號:" << endl; ?? ?int id; ?? ?cin >> id; ?? ?cout << "請輸入書的作者:" << endl; ?? ?string author; ?? ?cin >> author; ?? ?cout << "請輸入書的價格:" << endl; ?? ?double price; ?? ?cin >> price; ?? ?book b(name, now, s, id, author, price); ?? ?this->book1[m] = b; ?? ?m++; ?? ?cout << "恭喜您完成書的存儲!" << endl; } void library::show_book() { ?? ?cout << "您好,下面將為您顯示圖書信息!" << endl; ?? ?cout << "名稱" << " ? ?" << "編號" << " ? ?" << "現(xiàn)有數(shù)量" << " ? ?" << "庫存數(shù)量" << " ? ?" << "作者" << " ? ?" << "價格" << endl; ?? ?for (int i = 0; i < m; i++) ?? ?{? ?? ??? ?cout << book1[i].get_name() << " ? ? ?" << book1[i].get_id() << " ? ? ? ?" << book1[i].get_n_number() << " ? ? ? ? ? ?" << book1[i].get_s_number() << " ? ? ? ? ?" << book1[i].get_author() << " ? ? ? ? ?" << book1[i].get_price() << endl; ?? ?} } bool library::search() { ?? ?int id; ?? ?cout << "請輸入您借閱書籍的ID:" << endl; ?? ?cin >> id; ?? ?for (int i = 0; i < m; i++) ?? ?{ ?? ??? ?if (book1[i].get_id() == id) ?? ??? ?{ ?? ??? ??? ?cout << "名稱" << " ? ?" << "編號" << " ? ?" << "現(xiàn)有數(shù)量" << " ? ?" << "庫存數(shù)量" << " ? ?" << "作者" << " ? ?" << "價格" << endl; ?? ??? ??? ?cout << book1[i].get_name() << " ? ? ?" << book1[i].get_id() << " ? ? ? ?" << book1[i].get_n_number() << " ? ? ? ? ? ?" << book1[i].get_s_number() << " ? ? ? ? ?" << book1[i].get_author() << " ? ? ? ? ?" << book1[i].get_price() << endl; ?? ??? ??? ?return true; ?? ??? ?} ?? ?} ?? ?cout << "您查找的書不存在!" << endl; ?? ?return false; } bool library::borrow_book(reader_admin&r_ad)//借書 { ?? ?char c = ' '; ?? ?do ?? ?{ ?? ??? ?cout << "請輸入您的學(xué)號:" << endl; ?? ??? ?string r_id; ?? ??? ?cin >> r_id; ?? ??? ?if (r_ad.sreach_id(r_id) == true)//判斷輸入的學(xué)號是否存在 ?? ??? ?{ ?? ??? ??? ?char d = ' '; ?? ??? ??? ?do { ?? ??? ??? ??? ?int id; ?? ??? ??? ??? ?cout << "請輸入您借閱書籍的ID:" << endl; ?? ??? ??? ??? ?cin >> id; ?? ??? ??? ??? ?for (int i = 0; i < m; i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?if (book1[i].get_id() == id)//如果查找的書本存在 ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?if (book1[i].get_n_number() == 0) ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ?cout << "您找的書已借閱完!" << endl; ?? ??? ??? ??? ??? ??? ??? ?return false; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?else ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ?book1[i].set_n_number(book1[i].get_n_number() - 1);//使書本的數(shù)量少一。 ?? ??? ??? ??? ??? ??? ??? ?r_ad.r_borrow();//讀者的借閱量加一。 ?? ??? ??? ??? ??? ??? ??? ?cout << "恭喜您借閱成功!" << endl; ?? ??? ??? ??? ??? ??? ??? ?return true; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?cout << "您查找的書籍不存在!/已借閱完!" << endl; ?? ??? ??? ??? ?cout << "重新輸入請按Y!按其他任意鍵退出!" << endl; ?? ??? ??? ??? ?cin >> d; ?? ??? ??? ?} while (d == 'Y' || d == 'y'); ?? ??? ??? ??? ?return false; ?? ??? ?} ?? ??? ?cout << "您輸入的學(xué)號不存在!" << endl; ?? ??? ?cout << "重新輸入請按Y!按其他任意鍵退出!" << endl; ?? ??? ?cin >> c; ?? ?} while (c == 'Y' || c == 'y'); ? ? return false; } bool library::return_book(reader_admin& r_ad) { ?? ?char c = ' '; ?? ?do ?? ?{ ?? ??? ?cout << "請輸入您的學(xué)號:" << endl; ?? ??? ?string r_id; ?? ??? ?cin >> r_id; ?? ??? ?if (r_ad.sreach_id(r_id) == true)//判斷輸入的學(xué)號是否存在 ?? ??? ?{ ?? ??? ??? ?char d = ' '; ?? ??? ??? ?do { ?? ??? ??? ??? ?int id; ?? ??? ??? ??? ?cout << "請輸入您借閱書籍的ID:" << endl; ?? ??? ??? ??? ?cin >> id; ?? ??? ??? ??? ?for (int i = 0; i < m; i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?if (book1[i].get_id() == id)//如果查找的書本存在 ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?if (book1[i].get_n_number() == 0) ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?else ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ?book1[i].set_n_number(book1[i].get_n_number() +1);//使書本的數(shù)量加一。 ?? ??? ??? ??? ??? ??? ??? ?r_ad.r_reutrn();//讀者的借閱量減一。 ?? ??? ??? ??? ??? ??? ??? ?cout << "恭喜您借閱成功!" << endl; ?? ??? ??? ??? ??? ??? ??? ?return true; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?cout << "您查找的書籍不存在!/已借閱完!" << endl; ?? ??? ??? ??? ?cout << "重新輸入請按Y!按其他任意鍵退出!" << endl; ?? ??? ??? ??? ?cin >> d; ?? ??? ??? ?} while (d == 'Y' || d == 'y'); ?? ??? ??? ?return false; ?? ??? ?} ?? ??? ?cout << "您輸入的學(xué)號不存在!" << endl; ?? ??? ?cout << "重新輸入請按Y!按其他任意鍵退出!" << endl; ?? ??? ?cin >> c; ?? ?} while (c == 'Y' || c == 'y'); ?? ?return false; } //修改書的相關(guān)信息 bool library::chang_book1() { ?? ?char c = ' '; ?? ?char d = ' '; ?? ?do ?? ?{ ?? ??? ?cout << "請輸入您要修改信息書的id:" << endl; ?? ??? ?int id; ?? ??? ?cin >> id; ?? ??? ?for (int i = 0; i < m; i++) ?? ??? ?{ ?? ??? ??? ?if (book1[i].get_id() == id) ?? ??? ??? ?{ ?? ??? ??? ??? ?do { ?? ??? ??? ??? ??? ?cout << "請選擇您要修改的信息:" << endl; ?? ??? ??? ??? ??? ?cout << "1.name" << "2.id" << "3.n_number" << "4.s_number" << "5.id" << "6.author" << "7.price" << endl; ?? ??? ??? ??? ??? ?int n; ?? ??? ??? ??? ??? ?cin >> n; ?? ??? ??? ??? ??? ?//修改名稱 ?? ??? ??? ??? ??? ?if (n == 1) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的名稱:" << endl; ?? ??? ??? ??? ??? ??? ?string new_name; ?? ??? ??? ??? ??? ??? ?cin >> new_name; ?? ??? ??? ??? ??? ??? ?book1[i].set_name(new_name); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?//修改id ?? ??? ??? ??? ??? ?if (n == 2) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的id" << endl; ?? ??? ??? ??? ??? ??? ?int new_id; ?? ??? ??? ??? ??? ??? ?cin >> new_id; ?? ??? ??? ??? ??? ??? ?book1[i].set_id(new_id); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?//修改n_number ?? ??? ??? ??? ??? ?if (n == 3) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的現(xiàn)有數(shù)量" << endl; ?? ??? ??? ??? ??? ??? ?int new_n_number; ?? ??? ??? ??? ??? ??? ?cin >> new_n_number; ?? ??? ??? ??? ??? ??? ?book1[i].set_n_number(new_n_number); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?//修改庫存信息 ?? ??? ??? ??? ??? ?if (n == 4) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的庫存數(shù)量" << endl; ?? ??? ??? ??? ??? ??? ?int new_s_number; ?? ??? ??? ??? ??? ??? ?cin >> new_s_number; ?? ??? ??? ??? ??? ??? ?book1[i].set_s_number(new_s_number); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?//修改書的編號 ?? ??? ??? ??? ??? ?if (n == 5) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的編號" << endl; ?? ??? ??? ??? ??? ??? ?int new_id; ?? ??? ??? ??? ??? ??? ?cin >> new_id; ?? ??? ??? ??? ??? ??? ?book1[i].set_id(new_id); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?//修改作者信息 ?? ??? ??? ??? ??? ?if (n == 6) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的作者" << endl; ?? ??? ??? ??? ??? ??? ?string new_name; ?? ??? ??? ??? ??? ??? ?cin >> new_name; ?? ??? ??? ??? ??? ??? ?book1[i].set_name(new_name); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?//修改價格信息 ?? ??? ??? ??? ??? ?if (n == 7) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout << "請輸入您修改的價格" << endl; ?? ??? ??? ??? ??? ??? ?double new_price; ?? ??? ??? ??? ??? ??? ?cin >> new_price; ?? ??? ??? ??? ??? ??? ?book1[i].set_price(new_price); ?? ??? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?cout << "繼續(xù)修改請按Y!" << endl; ?? ??? ??? ??? ??? ?cin >> d; ?? ??? ??? ??? ?} while (d == 'Y' || d == 'y'); ?? ??? ??? ?} ?? ??? ?} ?? ??? ?cout << "您查找的書不存在" << endl; ?? ??? ?cout << "重新輸入請按Y!按其他任意鍵退出!" << endl; ?? ??? ?cin >> c; ?? ?} while (c == 'Y' || c == 'y'); ?? ?return false; }
"reader_infor.h"
#pragma once //存儲學(xué)生信息 #include"book.h" class reader_infor { public: ?? ?reader_infor(); ?? ?reader_infor(string Id, string Name, string Grade, int Number); ?? ?//get函數(shù) ?? ?string get_r_id();//返回學(xué)生的學(xué)號。 ?? ?string get_r_name();//返回學(xué)生的名字。 ?? ?string get_r_grade();//返回學(xué)生的班級。 ?? ?int get_r_borrow();//返回學(xué)生借閱書籍的數(shù)量。 ?? ?//set函數(shù) ?? ?void set_r_id(string ID); ?? ?void set_r_name(string Name); ?? ?void set_r_grade(string Grade); ?? ?void set_r_borrow(int Number); private: ?? ?string r_id;//學(xué)生的學(xué)號 ?? ?string r_name;//學(xué)生的名字 ?? ?string r_grade;//學(xué)生的班級 ?? ?int r_borrow;//學(xué)生借閱書籍的數(shù)量 };
"reader_infor.cpp"
#include"reader_infor.h" //構(gòu)造函數(shù) reader_infor::reader_infor() { ?? ?r_id = ""; ?? ?r_name = ""; ?? ?r_grade = ""; ?? ?r_borrow = 0; } reader_infor::reader_infor(string id, string name, string grade, int number) { ?? ?this->r_id = id; ?? ?this->r_name = name; ?? ?this->r_grade = grade; ?? ?this->r_borrow = number; } //get函數(shù) string reader_infor::get_r_id() { ?? ?return this->r_id; } string reader_infor::get_r_name() { ?? ?return this->r_name; } string reader_infor::get_r_grade() { ?? ?return this->r_grade; } int reader_infor::get_r_borrow() { ?? ?return this->r_borrow; } //set函數(shù) void reader_infor::set_r_id(string Id) { ?? ?this->r_id = Id; } void reader_infor::set_r_name(string Name) { ?? ?this->r_name = Name; } void reader_infor::set_r_grade(string Grade) { ?? ?this->r_grade = Grade; } void reader_infor::set_r_borrow(int Borrow) { ?? ?this->r_borrow = Borrow; }
"reader_admin.h
#pragma once #include"reader_infor.h" //管理學(xué)生信息 class reader_admin { public: ?? ?reader_admin(); ?? ?int get_borrow_number(); ?? ?void set_borrow_number(int i); ?? ?void set_reader_infor();//創(chuàng)建學(xué)生信息。 ?? ?void show_reader_infor();//顯示學(xué)生的信息。 ?? ?bool chang_reader();//修改讀者信息。 ?? ?bool sreach_id(string id);//查找學(xué)生的學(xué)號。 ?? ?void r_borrow();//讀者的借閱量+1。 ?? ?void r_reutrn();//讀者的借閱量-1。 private: ?? ?int borrow_number;//查找的相關(guān)位置。 ?? ?int reader_number;//記錄學(xué)生的個數(shù)。 ?? ?reader_infor reader1[1000];//存放學(xué)生信息。 };
"reader_admin.cpp
#include"reader_admin.h" reader_admin::reader_admin() { ?? ?reader_number = 0; ?? ?borrow_number = -1; } int reader_admin::get_borrow_number() { ?? ?return borrow_number; } void reader_admin::set_borrow_number(int i) { ?? ?this->borrow_number = i; } //添加讀者信息 void reader_admin::set_reader_infor() { ?? ?cout << "請輸入學(xué)生的id:" << endl; ?? ?string r_id; ?? ?cin >> r_id; ?? ?cout << "請輸入學(xué)生的姓名:" << endl; ?? ?string r_name; ?? ?cin >> r_name; ?? ?cout << "請輸入學(xué)生的年級:" << endl; ?? ?string r_grade; ?? ?cin >> r_grade; ?? ?cout << "請輸入學(xué)生的借書數(shù)量:" << endl; ?? ?int r_number; ?? ?cin >> r_number; ?? ?reader_infor reader_new(r_id, r_name, r_grade, r_number); ?? ?reader1[reader_number] = reader_new; ?? ?reader_number++;//學(xué)生數(shù)量加1. } //顯示讀者信息 void reader_admin::show_reader_infor() { ?? ?for (int i = 0; i < reader_number; i++) ?? ?{ ?? ??? ?cout << "學(xué)生的學(xué)號是:" << reader1[i].get_r_id() << endl; ?? ??? ?cout << "學(xué)生的姓名是:" << reader1[i].get_r_name() << endl; ?? ??? ?cout << "學(xué)生的年級是:" << reader1[i].get_r_grade() << endl; ?? ??? ?cout << "學(xué)生的借書數(shù)量是:" << reader1[i].get_r_borrow() << endl; ?? ?} } bool reader_admin::sreach_id(string id)//查找學(xué)號是否存在 { ?? ?for (int i = 0; i < reader_number; i++) ?? ?{ ?? ??? ?if (reader1[i].get_r_id() == id) ?? ??? ?{ ?? ??? ??? ?borrow_number = i; ?? ??? ??? ?return true; ?? ??? ?} ?? ?} ?? ?return false; } //借書數(shù)量加一 void reader_admin::r_borrow() { ?? ?reader1[borrow_number].set_r_borrow(reader1[borrow_number].get_r_borrow() + 1); ?? ?borrow_number = -1; } //借書數(shù)量減一 void reader_admin::r_reutrn() { ?? ?reader1[borrow_number].set_r_borrow(reader1[borrow_number].get_r_borrow() - 1); ?? ?borrow_number = -1; } //修改書籍信息 bool reader_admin::chang_reader() { ?? ?char c = ' '; ?? ?char d = ' '; ?? ?do { ?? ??? ?cout << "請輸入您要修改信息學(xué)生的id" << endl; ?? ??? ?string r_id; ?? ??? ?cin >> r_id; ?? ??? ?if (sreach_id(r_id) == true) ?? ??? ?{ ?? ??? ??? ?do { ?? ??? ??? ??? ?cout << "請選擇您要修改的信息:" << endl; ?? ??? ??? ??? ?cout << "1.學(xué)號" << "2.名字" << "3.班級" << "4.借閱書籍?dāng)?shù)量" << endl; ?? ??? ??? ??? ?int i; ?? ??? ??? ??? ?cin >> i; ?? ??? ??? ??? ?//修改學(xué)號 ?? ??? ??? ??? ?if (i == 1) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout << "請輸入您修改的學(xué)號" << endl; ?? ??? ??? ??? ??? ?string new_r_id; ?? ??? ??? ??? ??? ?cin >> new_r_id; ?? ??? ??? ??? ??? ?reader1[borrow_number].set_r_id(new_r_id); ?? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?//修改名稱 ?? ??? ??? ??? ?if (i == 2) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout << "請輸入您修改的名稱" << endl; ?? ??? ??? ??? ??? ?string new_r_name; ?? ??? ??? ??? ??? ?cin >> new_r_name; ?? ??? ??? ??? ??? ?reader1[borrow_number].set_r_name(new_r_name); ?? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?//修改班級 ?? ??? ??? ??? ?if (i == 3) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout << "請輸入您修改的班級" << endl; ?? ??? ??? ??? ??? ?string new_r_grade; ?? ??? ??? ??? ??? ?cin >> new_r_grade; ?? ??? ??? ??? ??? ?reader1[borrow_number].set_r_grade(new_r_grade); ?? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?//修改借閱數(shù)量 ?? ??? ??? ??? ?if (i == 4) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout << "請輸入您修改的數(shù)量" << endl; ?? ??? ??? ??? ??? ?int new_r_number; ?? ??? ??? ??? ??? ?cin >> new_r_number; ?? ??? ??? ??? ??? ?reader1[borrow_number].set_r_borrow(new_r_number); ?? ??? ??? ??? ??? ?cout << "恭喜您修改成功!" << endl; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?cout << "繼續(xù)修改信息請按Y!按任意鍵退出!" << endl; ?? ??? ??? ??? ?cin >> d; ?? ??? ??? ?} while(d == 'Y' || d == 'y'); ?? ??? ??? ?borrow_number = -1;//將查找到的位置初始化。 ?? ??? ??? ?break;//跳出本次修改。 ?? ??? ?} ?? ??? ?cout << "繼續(xù)修改請按Y!按任意鍵退出!" << endl; ?? ??? ?cin >> c; ?? ?} while (c == 'Y' || c == 'y'); ?? ?return false; }
test.cpp
#include <string> #include "book.h" #include "library.h" #include"reader_infor.h" #include"reader_admin.h" using namespace std; int main() { ?? ?reader_admin r_ad; ?? ?library lib; ?? ?int i; ?? ?while (1) ?? ?{ ?? ??? ?cout << "************歡迎來到圖書館************" << endl; ?? ??? ?cout << "**********請選擇您的登陸身份**********" << endl; ?? ??? ?cout << " ? ? ? ? ? ?1. 借閱者登陸 ? ? ? ? ? ? " << endl; ?? ??? ?cout << " ? ? ? ? ? ?2. 管理員登陸 ? ? ? ? ? ? " << endl; ?? ??? ?cin >> i; ?? ??? ?int j; ?? ??? ?if (i == 1) ?? ??? ?{ ?? ??? ??? ?do ?? ??? ??? ?{ ?? ??? ??? ??? ?cout << "********請選擇您要進行的操作**********" << endl; ?? ??? ??? ??? ?cout << "********1.瀏覽圖書信息**********" << endl; ?? ??? ??? ??? ?cout << "********2. ? 查找 ? ? **********" << endl; ?? ??? ??? ??? ?cout << "********3. ? 借書 ? ? **********" << endl; ?? ??? ??? ??? ?cout << "********4. ? 還書 ? ? **********" << endl; ?? ??? ??? ??? ?cout << "********5. ? 退出 ? ? **********" << endl; ?? ??? ??? ??? ?cin >> j; ?? ??? ??? ??? ?switch (j) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ?case 1:lib.show_book(); break; ?? ??? ??? ??? ?case 2:lib.search(); break; ?? ??? ??? ??? ?case 3:lib.borrow_book(r_ad); break; ?? ??? ??? ??? ?case 4:lib.return_book(r_ad); break; ?? ??? ??? ??? ?case 5:break; ?? ??? ??? ??? ?} ?? ??? ??? ?} while (j == 1 || j == 2 || j == 3 || j == 4); ?? ??? ?} ?? ??? ?int m; ?? ??? ?if (i == 2) ?? ??? ?{ ?? ??? ??? ?do ?? ??? ??? ?{ ?? ??? ??? ??? ?cout << "********請選擇您要進行的操作**********" << endl; ?? ??? ??? ??? ?cout << "********1. ?瀏覽圖書信息 ? ?**********" << endl; ?? ??? ??? ??? ?cout << "********2. ?瀏覽讀者信息 ? ?**********" << endl; ?? ??? ??? ??? ?cout << "********3. ?添加圖書信息 ? ?**********" << endl; ?? ??? ??? ??? ?cout << "********4. ?添加讀者信息 ? ?**********" << endl; ?? ??? ??? ??? ?cout << "********5. ?修改圖書信息 ? ?**********" << endl; ?? ??? ??? ??? ?cout << "********6. ?修改讀者信息 ? ?**********" << endl; ?? ??? ??? ??? ?cout << "********7. ? ? ?退出 ? ? ? ?**********" << endl; ?? ??? ??? ??? ?cin >> m; ?? ??? ??? ??? ?switch (m) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ?case 1:lib.show_book(); break; ?? ??? ??? ??? ?case 2:r_ad.show_reader_infor(); break; ?? ??? ??? ??? ?case 3:lib.set_book1(); break; ?? ??? ??? ??? ?case 4:r_ad.set_reader_infor(); break; ?? ??? ??? ??? ?case 5:lib.chang_book1(); break; ?? ??? ??? ??? ?case 6:r_ad.chang_reader(); break; ?? ??? ??? ??? ?case 7:continue; ?? ??? ??? ??? ?} ?? ??? ??? ?} while (m==1||m==2||m==3||m==4||m==5||m==6); ?? ??? ?} ?? ? ? ?? ?} ?? ?return 0; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++動態(tài)規(guī)劃算法實現(xiàn)矩陣鏈乘法
動態(tài)規(guī)劃算法通常用于求解具有某種最優(yōu)性質(zhì)的問題。在這類問題中,可能會有許多可行解。每一個解都對應(yīng)于一個值,我們希望找到具有最優(yōu)值的解2022-06-06