温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何实现C++版图书管理系统

发布时间:2022-03-14 09:13:33 来源:亿速云 阅读:134 作者:小新 栏目:开发技术

这篇文章主要介绍了如何实现C++版图书管理系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

具体内容如下

使用介绍

图书管理系统源码由两部分组成,第一部分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;    //指针
};

//图书结点类
class Node
{
public:
    int num;        //图书编号
    string bookName;  //书名
    string author;    //作者
    string press;    //出版社
    Node *next;        //指针
};
VIP vip[100];
Node book[100];

void add();    //增加图书函数
void Output(Node p);    //输出图书信息函数
int LookupBook();    //通过书名查找
void LookupAuthor();    //通过作者名查找
int LookupNum();        //通过编号查找
void LookupPress();    //通过出版社查找
void addVIP();        //增加会员函数
void OutputVIP(VIP s);        //输出会员信息函数
int LookupNumVIP();        //按编号查询会员
void LookupNameVIP();        //按会员姓名查找会员
void DeleteVIPbook();        //删除会员借书信息
void Delete();        //删除会员函数
void Query();        //根据会员编号查询借书信息
void Return();        //还书函数
void Borrow();        //图书借阅函数
void Index();        //首页
void BookInterface();        //图书管理界面
void VIPInterface();        //会员管理界面
void DeleteBook();    //删除图书函数
void LookupBookIn();    //图书查询页面
void LookupVIPIn();//会员查询页面

book.cpp源文件

#include"book.h"
    
int main()
{
    Index();   //首页函数
    return 0;
}

//增加图书函数
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;
}

//删除图书函数
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;
}

//输出图书信息函数
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;
    }
}

//增加会员函数
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;
        }
    }
}

//输出会员信息函数
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';
}

//删除会员函数
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;
}

//根据会员编号查询借书信息
void Query(){
    LookupNumVIP();
}

//还书函数
void Return(){
        DeleteVIPbook();
        cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"图书归还成功"<<"\n"<<endl;
}

//图书借阅函数
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"<<"****           图书管理系统         ****"<<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"<<"****          图书管理系统          ****"<<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();    //增加图书函数
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 2:
                LookupBookIn();    //图书查询页面
                break;
            case 3:
                Borrow();        //图书借阅函数
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 4:
                Return();        //还书函数
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                BookInterface();
                break;
            case 5:
                DeleteBook();    //删除图书函数
                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"<<"****           图书管理系统         ****"<<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();        //增加会员函数
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                VIPInterface();
                break;
            case 2:
                LookupVIPIn();  //会员查询页面
                break;
            case 3:
                Query();        //根据会员编号查询借书信息
                cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
                system("pause");
                VIPInterface();
                break;
            case 4:
                Delete();        //删除会员函数
                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"<<"****               图书管理系统               ****"<<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"<<"****           图书管理系统         ****"<<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();
          }
}

感谢你能够认真阅读完这篇文章,希望小编分享的“如何实现C++版图书管理系统”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

c++
AI