亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C++實(shí)現(xiàn)圖書館管理系統(tǒng)

 更新時(shí)間:2022年03月11日 12:48:11   作者:顏問(wèn)兒  
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)圖書館管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C++實(shí)現(xiàn)圖書館管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

一、實(shí)驗(yàn)名稱

圖書館管理系統(tǒng)

二、實(shí)驗(yàn)?zāi)康?/h2>

利用C++語(yǔ)言設(shè)計(jì)開發(fā)一個(gè)小型的圖書館管理系統(tǒng)模擬程序,具有如下功能:退出系統(tǒng)、增加圖書、刪除圖書、借閱圖書、歸還圖書、顯示圖書信息、查詢圖書等功能。實(shí)驗(yàn)中應(yīng)掌握繼承結(jié)構(gòu),并掌握對(duì)象、類、鏈表的使用和成員函數(shù)、構(gòu)造函數(shù)的定義及調(diào)用,并掌握使用實(shí)驗(yàn)設(shè)備的技能技巧和程序的調(diào)試方法。

三、實(shí)驗(yàn)平臺(tái)

運(yùn)行環(huán)境:VC++6.0

四、問(wèn)題分析

圖書館管理系統(tǒng)模擬程序可劃分為7個(gè)模塊:退出模塊、增加圖書模塊、刪除圖書模塊、借閱圖書模塊、歸還圖書模塊、顯示圖書信息模塊、查詢圖書模塊。各模塊之間均有著或多或少的聯(lián)系,比如: 借閱圖書模塊、顯示圖書信息模塊、查詢圖書模塊都需要在進(jìn)行增加圖書模塊后進(jìn)行。理解了各模塊之間的主要關(guān)系有利于程序的設(shè)計(jì)與完成,使程序的層次結(jié)構(gòu)清晰,便于程序的編寫、閱讀和調(diào)試。以下為本次試驗(yàn)的項(xiàng)目構(gòu)架圖:

本次實(shí)驗(yàn)定義了三個(gè)類:Item類、Person類、Library類

Item類中有public函數(shù): name、item_type、bool Register(bool函數(shù)輸出值只有ture和force,用來(lái)判斷是否注冊(cè))。

Person類中public函數(shù):Name ()、Adress ()、Regist_items。

Library類中public函數(shù):addBook()向圖書館里加書籍、deleteBook()刪除無(wú)用書籍、brrowBook()借書,之前先判斷書籍是否存在、returnBook()還書、getReader()查詢某編號(hào)的書是誰(shuí)借了、indexOfNum(string num) 根據(jù)編號(hào)得到書在數(shù)組中的下標(biāo);
private函數(shù):vector books所有書籍、map<string, int> readers存儲(chǔ)讀者及其所借的書籍?dāng)?shù)目、currentNum庫(kù)存書籍?dāng)?shù)目、brrowNum借出書籍?dāng)?shù)目。

附錄:

程序源代碼:

#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include <list>
using namespace std;


class item
{
?? ?public:
?? ?string name;
?? ?string item_type;

?? ?bool Register;


};

//雜志類
class magazine :public item
{
?? ?string Type;
?? ?string Writer;
};
//MusicCd類
class MusicCd :public item
{
?? ?string Singer;
};
//電影類
class Movie :public item
{
?? ?string Type;
?? ?string Director;
?? ?string Actor;
};

//書籍類
class Book : public item
{
public:
?? ?Book() { borrow_flag = false; } ? //無(wú)參構(gòu)造函數(shù)
?? ?Book(string name, string num, string auther)
?? ??? ?:name(name), num(num), auther(auther) {
?? ??? ?borrow_flag = false;
?? ?} ?//有參構(gòu)造函數(shù)
?? ?void setReader(string reader, int lcn, string data); //設(shè)置讀者
?? ?void setInfo(string name, string num, string auther); //設(shè)置書籍信息
?? ?string getName() {
?? ??? ?return name;
?? ?}
?? ?string getNum() { return num; }
?? ?string getAuther() {
?? ??? ?return auther;
?? ?}
?? ?bool getBorrow_flag() {
?? ??? ?return borrow_flag;
?? ?}
?? ?string getReader() {
?? ??? ?return reader;
?? ?}
?? ?int getLcn() {
?? ??? ?return lcn;
?? ?}
?? ?string getData() {
?? ??? ?return data;
?? ?}
?? ?bool isBorrow() { return borrow_flag; } ? ? ? ?//判斷書籍是否借出
?? ?void setBorrow_flag(bool b) { borrow_flag = b; }
?? ?void showInfo(); ? ? ? ?//顯示數(shù)據(jù)信息
private:
?? ?string name; ?//書名
?? ?string num; ? //編號(hào)(唯一標(biāo)示)
?? ?string auther; //作者

?? ?bool borrow_flag;
?? ?string reader; //讀者
?? ?int lcn; ? ? ? //借書證號(hào)
?? ?string data; ? //借書日期
};
//DVD電影類
class DVD :public Movie
{

};
//藍(lán)光電影類
class Blue_ligh :public Movie
{

};

//用戶
class Person
{
public:
?? ?string Name;
?? ?string Adress;
?? ?list<item> Regist_items;
};

void Book::setReader(string reader, int lcn, string data)
{
?? ?borrow_flag = true;
?? ?this->reader.assign(reader);
?? ?this->lcn = lcn;
?? ?this->data.assign(data);
}
void Book::setInfo(string name, string num, string auther)
{
?? ?this->name.assign(name);
?? ?this->num.assign(num);
?? ?this->auther.assign(auther);
}
void Book::showInfo()
{
?? ?cout << "書籍名稱:" << setiosflags(ios_base::left) << setw(56) << name << endl
?? ??? ? << "書籍編號(hào):" << setw(56) << num<< endl
?? ??? ? << "書籍作者:" << setw(56) << auther ?<< endl;
?? ?if (borrow_flag)
?? ?{
?? ? ? cout << "書籍被借出。 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\n"
?? ??? ??? ?<< "讀者姓名:" << setw(56) << reader<< endl
?? ??? ??? ?<< "借書證號(hào):" << setw(56) << lcn << endl
?? ??? ??? ?<< "借書日期:" << setw(56) << data << endl;
?? ?}
?? ?else {
?? ??? ?cout << "書籍未被借出。 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\n";
?? ?}
}
class Library
{
public:
?? ?//書籍庫(kù)
?? ?list<item> itemList;
?? ?Library() { currentNum = 0; brrowNum = 0; }
?? ?void addBook(); ? ? ? ? ? ? ? ?//向圖書館里加書籍
?? ?void addBook(string name, string num, string auther);
?? ?void deleteBook(); ? //刪除無(wú)用書籍
?? ?void brrowBook(); ? //借書,之前先判斷書籍是否存在
?? ?void returnBook(); ? //還書
?? ?void getReader(); ?//查詢某編號(hào)的書是誰(shuí)借了
?? ?int indexOfNum(string num); //根據(jù)編號(hào)得到書在數(shù)組中的下標(biāo)
?? ?vector<Book> getBooks() {
?? ??? ?return books;
?? ?}
?? ?void showInfo();
?? ?int getTotalBooks() { return currentNum + brrowNum; }
private:
?? ?vector<Book> books;//所有書籍
?? ?map<string, int> readers; ?//存儲(chǔ)讀者及其所借的書籍?dāng)?shù)目?
?? ?int currentNum; ? //庫(kù)存書籍?dāng)?shù)目(不包括借出的)
?? ?int brrowNum; ? ? //借出書籍?dāng)?shù)目
};
void Library::showInfo()
{
?? ?cout << " ?***************************所有圖書信息***************************\n\n";
?? ?for (int i = 0; i < books.size(); i++)
?? ?{
?? ??? ?cout << "第" << i + 1 << "本書籍的信息。" << endl;
?? ??? ?books[i].showInfo();
?? ?}
?? ?system("pause");
?? ?system("cls");
}
int Library::indexOfNum(string num)
{
?? ?int i;
?? ?for (i = 0; i < books.size(); i++)
?? ?{
?? ??? ?if (books[i].getNum() == num)
?? ??? ??? ?return i;
?? ?}
?? ?return -1;
}
void Library::addBook()
{
?? ?Book b;
?? ?int temp;
?? ?string name, num, auther;
?? ?cout << " ?*****************************增加界面*****************************\n\n";
?? ?do {
?? ??? ?cout << "輸入書籍名稱,編號(hào),作者:";
?? ??? ?cin >> name >> num >> auther;
?? ??? ?b.setInfo(name, num, auther);
?? ??? ?if (indexOfNum(num) == -1) {
?? ??? ??? ?books.push_back(b);
?? ??? ??? ?currentNum++;
?? ??? ??? ?cout << "\n添加成功。" << endl;
?? ??? ??? ?cout << "輸入1繼續(xù)增加,返回上一層輸入2:";
?? ??? ??? ?cin >> temp;
?? ??? ?}
?? ??? ?else {
?? ??? ??? ?cout << "已存在該編號(hào)的書籍,添加失敗。" << endl;
?? ??? ??? ?cout << "輸入1繼續(xù)重新增加,返回上一層輸入2:";
?? ??? ??? ?cin >> temp;
?? ??? ?}
?? ?} while (temp == 1);
?? ?system("pause");
?? ?system("cls");
}
void Library::addBook(string name, string num, string auther)
{
?? ?Book b;
?? ?b.setInfo(name, num, auther);
?? ?books.push_back(b);
}
void Library::deleteBook()
{
?? ?int index, temp;
?? ?string num;
?? ?cout << " ?*****************************刪除界面*****************************\n\n";
?? ?do {
?? ??? ?cout << "輸入要?jiǎng)h除的書籍的編號(hào):";
?? ??? ?cin >> num;
?? ??? ?index = indexOfNum(num);
?? ??? ?if (index != -1) {
?? ??? ??? ?if (!books[index].getBorrow_flag()) {
?? ??? ??? ??? ?cout << "刪除的書籍的信息:\n";
?? ??? ??? ??? ?books[index].showInfo();
?? ??? ??? ??? ?books.erase(books.begin() + index);
?? ??? ??? ??? ?currentNum--;
?? ??? ??? ??? ?cout << "刪除成功。" << endl;
?? ??? ??? ??? ?cout << "輸入1繼續(xù)繼續(xù)刪除,返回上一層輸入2:";
?? ??? ??? ??? ?cin >> temp;
?? ??? ??? ?}
?? ??? ??? ?else {
?? ??? ??? ??? ?cout << "刪除失敗!書籍已經(jīng)被借出。" << endl;
?? ??? ??? ??? ?cout << "輸入1繼續(xù)繼續(xù)刪除,返回上一層輸入2:";
?? ??? ??? ??? ?cin >> temp;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout << "刪除失敗。未找到編號(hào)為" << num << "的書籍。\n";
?? ??? ??? ?cout << "輸入1繼續(xù)繼續(xù)刪除,返回上一層輸入2:";
?? ??? ??? ?cin >> temp;
?? ??? ?}
?? ?} while (temp == 1);
?? ?system("pause");
?? ?system("cls");
}
void Library::brrowBook()
{
?? ?string num;
?? ?int index;
?? ?cout << " ?*****************************借閱界面*****************************\n\n";
?? ?cout << "輸入要借閱的書籍的編號(hào):";
?? ?cin >> num;
?? ?index = indexOfNum(num);
?? ?if (index != -1) {
?? ??? ?if (books[index].isBorrow()) {
?? ??? ??? ?cout << "借閱失敗,書籍以及被借出。\n";
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout << "要借的書籍的信息:\n";
?? ??? ??? ?books[index].showInfo();
?? ??? ??? ?string reader, data;
?? ??? ??? ?int lcn;
?? ??? ??? ?cout << "輸入讀者姓名,借書證號(hào),借書日期:";
?? ??? ??? ?cin >> reader >> lcn >> data;
?? ??? ??? ?if (readers[reader] != 2) {
?? ??? ??? ??? ?books[index].setReader(reader, lcn, data);
?? ??? ??? ??? ?cout << "借書完成。\n";
?? ??? ??? ??? ?currentNum--;
?? ??? ??? ??? ?brrowNum++;
?? ??? ??? ??? ?readers[reader]++;
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?system("cls");
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?cout << "借書失敗,該讀者以借超過(guò)兩本書籍。\n";
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?system("cls");
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "借書失敗。未找到編號(hào)為" << num << "的書籍.\n";
?? ??? ?system("pause");
?? ??? ?system("cls");
?? ?}

}
void Library::returnBook()
{
?? ?string num;
?? ?cout << " ?*****************************還書界面*****************************\n\n";
?? ?cout << "輸入要還的書籍的編號(hào):";
?? ?cin >> num;
?? ?int index;
?? ?index = indexOfNum(num);
?? ?if (index != -1)
?? ?{
?? ??? ?cout << "要還的書籍的信息為:\n";
?? ??? ?books[index].showInfo();
?? ??? ?books[index].setBorrow_flag(false);
?? ??? ?readers[books[index].getReader()]--;
?? ??? ?cout << "還書成功。\n";
?? ??? ?system("pause");
?? ??? ?system("cls");
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "還書失敗,請(qǐng)檢查書籍編號(hào)是否輸入錯(cuò)誤!\n";
?? ??? ?system("pause");
?? ??? ?system("cls");
?? ?}
}
void Library::getReader()
{
?? ?string num;
?? ?cout << " ?*****************************查詢界面*****************************\n\n";
?? ?cout << "輸入要查找的書籍編號(hào):";
?? ?cin >> num;
?? ?int index;
?? ?index = indexOfNum(num);
?? ?if (index != -1)
?? ?{
?? ??? ?if (books[index].getBorrow_flag())
?? ??? ??? ?cout << "讀者為:" << books[index].getReader() << endl;
?? ??? ?else {
?? ??? ??? ?cout << "無(wú)讀者。" << endl;
?? ??? ?}
?? ??? ?system("pause");
?? ??? ?system("cls");
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "查詢失敗,請(qǐng)檢查書籍編號(hào)是否輸入錯(cuò)誤!\n";
?? ??? ?system("pause");
?? ??? ?system("cls");
?? ?}
}
Library l;

void menu()
{
?? ?int temp;
?? ?
?? ?while (1)
?? ?{
?? ??? ?cout << "___________________________ 圖書館管理系統(tǒng)____________________________\n";
?? ? ? ?cout << " ? ? ? ? ? ? ? ? ?┏━━━━━━━━━━━━━┓ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [0]退出系統(tǒng)。 ? ? ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [1]增加圖書。 ? ? ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [2]刪除圖書。 ? ? ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [3]借閱圖書。 ? ? ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [4]歸還圖書。 ? ? ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [5]顯示圖書信息。 ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┃ [6]查詢圖書。 ? ? ? ? ? ?┃ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << " ? ? ? ? ? ? ? ? ?┗━━━━━━━━━━━━━┛ ? ? ? ? ? ? ? ? ? ? ?\n";
?? ??? ?cout << "輸入要進(jìn)行的操作:";
?? ??? ?cin >> temp;
?? ??? ?switch (temp) {
?? ??? ?case 1:
?? ??? ??? ?system("cls");
?? ??? ??? ?l.addBook();?
?? ??? ??? ?break;
?? ??? ?case 2:system("cls");
?? ??? ??? ?l.deleteBook();?
?? ??? ??? ?break;
?? ??? ?case 3:system("cls");
?? ??? ??? ?l.brrowBook();?
?? ??? ??? ?break;
?? ??? ?case 4:system("cls");
?? ??? ??? ?l.returnBook();?
?? ??? ??? ?break;
?? ??? ?case 5:system("cls");
?? ??? ??? ?l.showInfo();
?? ??? ??? ?break;
?? ??? ?case 6:system("cls");
?? ??? ??? ?l.getReader();
?? ??? ??? ?break;
?? ??? ?case 0:
?? ??? ??? ?
?? ??? ??? ?exit(1);
?? ??? ??? ?break;
?? ??? ?default:
?? ??? ??? ?cout << "輸入錯(cuò)誤!" << endl;
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");
?? ??? ?}
?? ?}
}
int main()
{
?? ?menu();
?? ?return 0;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論