溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何實現(xiàn)C++版圖書管理系統(tǒng)

發(fā)布時間:2022-03-14 09:13:33 來源:億速云 閱讀:127 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹了如何實現(xiàn)C++版圖書管理系統(tǒng),具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

具體內(nèi)容如下

使用介紹

圖書管理系統(tǒng)源碼由兩部分組成,第一部分book.h頭文件,第二部分book.cpp源文件。時需注意將book.h文件的源碼單獨放在一個一個文件里,文件名必須為book.h。源碼文件也需放在一個單獨的.cpp文件里。

book.h頭文件

#include<iostream>
#include<string>
#include<stdlib.h>
#include<conio.h>
using namespace std;

//會員類
class VIP
{
public:
    int vnum;    //會員號
    string name;    //會員姓名
    int num;        //圖書編號
    string bookName;  //書名
    string author;    //作者
    string press;    //出版社
    VIP *next;    //指針
};

//圖書結(jié)點類
class Node
{
public:
    int num;        //圖書編號
    string bookName;  //書名
    string author;    //作者
    string press;    //出版社
    Node *next;        //指針
};
VIP vip[100];
Node book[100];

void add();    //增加圖書函數(shù)
void Output(Node p);    //輸出圖書信息函數(shù)
int LookupBook();    //通過書名查找
void LookupAuthor();    //通過作者名查找
int LookupNum();        //通過編號查找
void LookupPress();    //通過出版社查找
void addVIP();        //增加會員函數(shù)
void OutputVIP(VIP s);        //輸出會員信息函數(shù)
int LookupNumVIP();        //按編號查詢會員
void LookupNameVIP();        //按會員姓名查找會員
void DeleteVIPbook();        //刪除會員借書信息
void Delete();        //刪除會員函數(shù)
void Query();        //根據(jù)會員編號查詢借書信息
void Return();        //還書函數(shù)
void Borrow();        //圖書借閱函數(shù)
void Index();        //首頁
void BookInterface();        //圖書管理界面
void VIPInterface();        //會員管理界面
void DeleteBook();    //刪除圖書函數(shù)
void LookupBookIn();    //圖書查詢頁面
void LookupVIPIn();//會員查詢頁面

book.cpp源文件

#include"book.h"
    
int main()
{
    Index();   //首頁函數(shù)
    return 0;
}

//增加圖書函數(shù)
void add()
{
    for(int i=0;i<100;i++){
        if(book[i].num==0){
            cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入圖書編號:";
            cin>>book[i].num;
            cout<<endl;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入書名:";
            cin>>book[i].bookName;
            cout<<endl;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入作者:";
            cin>>book[i].author;
            cout<<endl;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入出版社:";
            cin>>book[i].press;
            cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"圖書添加成功"<<"\n"<<endl;
            break;
        }
    }
    return;
}

//刪除圖書函數(shù)
void DeleteBook(){
    int b=LookupNum();
    book[b].author='\0';
    book[b].bookName='\0';
    book[b].num=0;
    book[b].press='\0';
    cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"圖書刪除成功"<<endl;
}

//輸出圖書信息函數(shù)
void Output(int b){
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"圖書編號:"<<book[b].num<<"    書名:"<<book[b].bookName<<"    作者:"<<book[b].author<<"    出版社:"<<book[b].press<<"\n"<<endl;
}

//通過書名查找
int LookupBook(){
    int j=0;
    string bookname;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入書名:";
    cin>>bookname;
    for(int i=0;i<100;i++){
        if(book[i].bookName==bookname){
            j=1;
            Output(i);
            return i;
        }
    }
    if(j==0){
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"沒有該圖書"<<"\n"<<endl;
    }
    return 1000;
}

//通過作者名查找
void LookupAuthor(){
    int j=0;
    string author;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入作者姓名:";
    cin>>author;
    for(int i=0;i<100;i++){
        if(book[i].author==author){
            j=1;
            Output(i);
        }
    }
    if(j==0){
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"沒有該圖書"<<"\n"<<endl;
    }
}

//通過編號查找
int LookupNum(){
    int j=0;
    int num;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入圖書編號:";
    cin>>num;
    for(int i=0;i<100;i++){
        if(book[i].num==num){
            j=1;
            Output(i);
            return i;
        }
    }
    if(j==0){
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"沒有該圖書"<<"\n"<<endl;
    }
    return 1000;
}

//通過出版社查找
void LookupPress(){
    int j=0;
    string press;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入圖書出版社:";
    cin>>press;
    for(int i=0;i<100;i++){
        if(book[i].press==press){
            j=1;
            Output(i);
            break;
        }
    }
    if(j==0){
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"沒有該圖書"<<"\n"<<endl;
    }
}

//增加會員函數(shù)
void addVIP(){
    for(int i=0;i<100;i++){
        if(vip[i].vnum==0){
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入會員編號:";
            cin>>vip[i].vnum;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入會員名:";
            cin>>vip[i].name;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"會員添加成功"<<"\n"<<endl;
            break;
        }
    }
}

//輸出會員信息函數(shù)
void OutputVIP(int s){
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"會員編號:"<<vip[s].vnum<<"    會員姓名:"<<vip[s].name<<"\n"<<endl;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"圖書編號:"<<vip[s].num<<"    書名:"<<vip[s].bookName<<"    作者:"<<vip[s].author<<"    出版社:"<<vip[s].press<<endl;
}
//按編號查詢會員
int LookupNumVIP(){
    int j=0;
    int num;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入會員編號:";
    cin>>num;
    for(int i=0;i<100;i++){
        if(vip[i].vnum==num){
            OutputVIP(i);
            j=1;
            return i;
        }
    }
    if(j==0){
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"沒有該會員"<<"\n"<<endl;
    }
    return 1000;
}

//按會員姓名查找會員
void LookupNameVIP(){
    int j=0;
    string name;
    cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入會員姓名:";
    cin>>name;
    for(int i=0;i<100;i++){
        if(vip[i].name==name){
            j=1;
            OutputVIP(i);
            break;
        }
    }
    if(j==0){
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"沒有該會員"<<"\n"<<endl;
    }
}

//刪除會員借書信息
void DeleteVIPbook(){
    int s=LookupNumVIP();
    vip[s].author='\0';
    vip[s].bookName='\0';
    vip[s].num=0;
    vip[s].press='\0';
}

//刪除會員函數(shù)
void Delete(){
    int s=LookupNumVIP();
    vip[s].name='\0';
    vip[s].vnum=0;
    vip[s].author='\0';
    vip[s].bookName='\0';
    vip[s].num=0;
    vip[s].press='\0';
    cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"會員刪除成功"<<endl;
}

//根據(jù)會員編號查詢借書信息
void Query(){
    LookupNumVIP();
}

//還書函數(shù)
void Return(){
        DeleteVIPbook();
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"圖書歸還成功"<<"\n"<<endl;
}

//圖書借閱函數(shù)
void Borrow(){
    int b=LookupBook();
    int s=LookupNumVIP();
        vip[s].bookName=book[b].bookName;
        vip[s].author=book[b].author;
        vip[s].num=book[b].num;
        vip[s].press=book[b].press;
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"借書成功"<<"\n"<<endl;
}

//首頁
void Index(){
    int i;
    system("cls");
    cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****           圖書管理系統(tǒng)         ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、圖書管理      2、會員管理  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請選擇:";
          cin>>i;
          switch(i){
            case 1:
                BookInterface();
                break;
            case 2:
                VIPInterface();
                break;
            default:
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入1或2"<<"\n"<<endl;
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                Index();
          }
}

//圖書管理界面
void BookInterface(){
    system("cls");
    int i;
    cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****          圖書管理系統(tǒng)          ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、增加圖書      2、查詢圖書  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  3、圖書借閱      4、圖書歸還  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  5、刪除圖書      6、返回首頁  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請選擇:";
          cin>>i;
          switch(i){
            case 1:
                add();    //增加圖書函數(shù)
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 2:
                LookupBookIn();    //圖書查詢頁面
                break;
            case 3:
                Borrow();        //圖書借閱函數(shù)
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 4:
                Return();        //還書函數(shù)
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 5:
                DeleteBook();    //刪除圖書函數(shù)
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 6:
                Index();
            default:
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入對應編號"<<"\n"<<endl;
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
          }
}

//會員管理界面
void VIPInterface(){
    system("cls");
    int i;
    cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****           圖書管理系統(tǒng)         ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、增加會員      2、查詢會員  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  3、借書信息      4、刪除會員  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****          5、返回首頁           ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請選擇:";
          cin>>i;
          switch(i){
            case 1:
                addVIP();        //增加會員函數(shù)
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                VIPInterface();
                break;
            case 2:
                LookupVIPIn();  //會員查詢頁面
                break;
            case 3:
                Query();        //根據(jù)會員編號查詢借書信息
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                VIPInterface();
                break;
            case 4:
                Delete();        //刪除會員函數(shù)
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                VIPInterface();
                break;
            case 5:
                Index();
                break;
            default:
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入對應編號"<<"\n"<<endl;
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                VIPInterface();
          }
}

//圖書查詢頁面
void LookupBookIn(){
    system("cls");
    int i;
    cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"**************************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****               圖書管理系統(tǒng)               ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"**************************************************"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、圖書編號查詢      2、書名查詢        ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  3、圖書作者查詢      4、圖書出版社查詢  ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  5、返回上一頁        6、返回首頁        ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"**************************************************"<<"\n"<<endl;
          cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請選擇:";
          cin>>i;
          switch(i){
            case 1:
                LookupNum();    //通過編號查找
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                LookupBookIn();
                break;
            case 2:
                LookupBook();    //通過書名查找
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                LookupBookIn();
                break;
            case 3:
                LookupAuthor();    //通過作者名查找
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                LookupBookIn();
                break;
            case 4:
                LookupPress();    //通過出版社查找
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                LookupBookIn();
                break;
            case 5:
                BookInterface();    //圖書管理界面
                break;
            case 6:
                Index();
                break;
            default:
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入對應編號"<<"\n"<<endl;
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                LookupBookIn();
          }
}

//會員查詢頁面
void LookupVIPIn(){
        int i;
        system("cls");
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****           圖書管理系統(tǒng)         ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      1、通過編號查找會員       ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      2、通過姓名查找會員       ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      3、返回上一頁             ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      4、返回首頁               ****"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
              cout<<"\t"<<"\t"<<"\t"<<"\t"<<"請選擇:";
              cin>>i;
               switch(i){
                    case 1:
                        LookupNumVIP();        //按編號查詢會員
                        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                        system("pause");
                        LookupVIPIn();
                        break;
                    case 2:
                        LookupNameVIP();        //按會員姓名查找會員
                        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                        system("pause");
                        LookupVIPIn();
                        break;
                    case 3:
                        VIPInterface();    //會員管理界面
                        break;
                    case 4:
                        Index();
                        break;
                    default:
                        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"請輸入對應編號"<<"\n"<<endl;
                        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                        system("pause");
                        LookupVIPIn();
          }
}

感謝你能夠認真閱讀完這篇文章,希望小編分享的“如何實現(xiàn)C++版圖書管理系統(tǒng)”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

c++
AI