千家信息网

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

发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,这篇文章给大家分享的是有关C++如何实现小型图书管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。具体内容如下因为课程设计的原因,需要实现一个小型图书管理系统包含功能:
千家信息网最后更新 2025年11月07日C++如何实现小型图书管理系统

这篇文章给大家分享的是有关C++如何实现小型图书管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体内容如下

因为课程设计的原因,需要实现一个小型图书管理系统

包含功能:

问题描述:

设计一个系统,对图书信息进行管理,信息描述:有关该系统基本信息的描述,如:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等。

基本要求:

基本功能:

1、新进图书基本信息的输入。
2、图书基本信息的查询。
3、对撤消图书信息的删除。
4、为借书人办理注册。
5、办理借书手续(非注册会员不能借书)。
6、办理还书手续。
7、统计图书库存、已借出图书数量。

需要创建三个文本文件:record.txt book.txt reader.txt

operating.h的头文件:

#include #include #include #include  #include#include#include  using namespace std;  int all_stock = 0;int out_stock = 0;int times=0;void outData(vector res,int n)  // n为txt中 每行数据个数{    for(int i=0;i>bookname;    cout<<"请输入书籍作者"<>writer;    cout<<"请输入书籍价格"<>price)  || price <= 0 )    {        cin.clear();        cin.ignore(100,'\n');        cout<<"请输入正确的价格"< res;    string temp; //暂存字符串        in.open("book.txt",ios::in);    if(!in)    {        cerr<<"打开文件失败!"<>temp)        {                        res.push_back(temp);        }    }    // 0 书籍编号 1 书籍名称 2作者 3价格 4书籍状态    //输出res     cout<res;    string temp;    bool flag=false;      fstream in;    in.open("book.txt",ios::in);    if(!in)    {        cerr<<"打开错误文件"<>del_book;            while(getline(in,line))    {        //cout<>temp)        {            if(del_book == temp && times==0)            {                                for(int i=0;i<3;i++)  //因为一共五个 第一个temp已经是del_book 所以这里取得是四个                {                    input>>temp;                }                input>>temp;                if(temp != "0")                {                    cout<<"书籍状态不对";                    in.close();                    return ;                }                flag=true;                cout<<"\n找到了喔,应该删除成功了\n";                continue;            }            res.push_back(temp);            times++;                    }    }        //outData(res,5);    in.close();        if(!flag)    {        cout<<"\n错误的书籍ID\n";        return ;    }    fstream out;      out.open("book.txt",ios::out);    if(!out)    {        cerr<<"打开文件失败!"<>readername;        do    {        cout<<"请输入读者性别:0为女,1为男"<>sex) )        {            cin.clear();            cin.ignore(100,'\n');            cout<<"请输入正确的0或1"< res;    string temp; //暂存字符串    in.open("reader.txt",ios::in);    if(!in)    {        cerr<<"打开文件失败!"<>temp)        res.push_back(temp);    }    // 0读者学号 1读者姓名 2读者性别    //输出res     cout<res; //取书籍状况,并且更新      string temp;    bool flag_book = false; //用于判断书籍是否存在  读者是否存在    bool flag_reader = false;      /* 取book的图书情况,并判断是否在馆*/    fstream in;    in.open("book.txt",ios::in);    if(!in)    {        cerr<<"打开错误文件"<>book[0];        while(getline(in,line))    {        //cout<>temp)        {            if(book[0] == temp && times ==0)            {                res.push_back(temp);                for(int i=0;i<3;i++)  //从书籍名称开始取,一直取到价钱                {                    input>>temp; //读取了书籍编号,要及时写入res,以后要写进文本                    book[1+i]=temp;                    res.push_back(temp);                }                input>>temp;  //取书籍状态,如果0在馆 如果1不在馆                if(temp == "0")                {                    book[4]="1";                    temp="1";                    res.push_back(temp);                    flag_book=true;                }else{                    cout<<"\n书籍不在馆\n";                    in.close();                    return ;                }                continue;  //继续取            }            res.push_back(temp);            times++;                    }    }    in.close();    if(!flag_book)    {        cout<<"错误的书籍ID"<>readerid;      while(getline(in,line))    {        //cout<>temp)        {            if(readerid == temp && times==0)            {                input>>temp;                readername=temp;                flag_reader=true;                break;              }            times++;                    }    }    if(!flag_reader)    {        cout<<"错误的读者ID"< res;    string temp; //暂存字符串    in.open("record.txt",ios::in);    if(!in)    {        cerr<<"打开文件失败!"<>temp)        res.push_back(temp);    }    // 0书籍编号 1书籍名称 2读者姓名    //输出res     cout<res;    string temp;    bool flag=false;      fstream in;    in.open("record.txt",ios::in);  //先打开record 查看是否有借这本书    if(!in)    {        cerr<<"打开错误文件"<> rtn_book;            while(getline(in,line))    {        //cout<>temp)        {            if(rtn_book == temp && times==0) //如果有的话            {                flag=true;                                for(int i=0;i<2;i++)  //因为一共三个 第一个temp已经是del_book 所以这里取得是两个                {                    input>>temp;// 将删除的东西不输出到向量中                }                continue;            }            res.push_back(temp);            times++;                    }    }        //outData(res,3);    in.close();    if(!flag)    {        cout<<"该图书不存在或者没有被外借"<res_book;    in.open("book.txt",ios::in); //开始取 被修改的书籍    if(!in)    {        cerr<<"打开错误文件"<>temp)        {            if(rtn_book == temp && times==0)            {                res_book.push_back(temp);                for(int i=0;i<3;i++)  //因为一共五个 第一个temp已经是rtn_book 所以这里取得是四个                {                    input>>temp;                    res_book.push_back(temp);                }                input>>temp;//最后一个取得是书籍状态,需要修改书籍状态                temp = "0";                res_book.push_back(temp);                continue;            }            res_book.push_back(temp);            times++;        }    }        //outData(res,5);    in.close();        out.open("book.txt",ios::out); //再存入文本中;    if(!out)    {        cerr<<"打开文件失败!"<

main.cpp的主函数

#include "operating.h" int main(){    int order;    do    {        order = -1;        cout<<"\n";        cout<<"----------------------------------------------------------\n";        cout<<"| 1. 图书信息录入    2. 图书信息查询    3. 图书信息删除  |\n";        cout<<"| 4. 读者办理注册    5. 读者信息查询    6. 办理借书手续  |\n";        cout<<"| 7. 办理还书手续    8  已借出图书      9.统计图书库存  |\n";        cout<<"|                                        按 \"0\"退出    |\n";        cout<<"----------------------------------------------------------\n";        cout<<"  请输入相应序号进行相应操作:";        cin>>order;        cin.clear();//清除缓冲区中后面的字符        cin.ignore(100,'\n');         switch(order)        {        case 1:            BookEntry();            break;        case 2:            BookMes();            break;        case 3:            DelBook();            break;        case 4:            ReaderEntry();            break;        case 5:            ReaderMes();            break;        case 6:            BorrowBook();            break;        case 7:            RtnBook();            break;        case 8:            BorrowMes();            break;        case 9:            CountBook();            break;        case 0:            break;        default:            cout<<"错误的命令行"<

感谢各位的阅读!关于"C++如何实现小型图书管理系统"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

0