文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

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

2023-06-29 11:55

关注

这篇文章主要介绍了如何实现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++版图书管理系统”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网行业资讯频道,更多相关知识等着你来学习!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯