C++实现简易图书管理系统

运行效果图

  1. 启动界面
    在这里插入图片描述
  2. 登录界面
    在这里插入图片描述
  3. 超级管理员界面

在这里插入图片描述

程序介绍

  1. 系统采用文件操作方式,通过更改文件格式名保护系统及用户隐私。
  2. 提供三种登录模式,根据用户名和密码自动确认登录模式。
  3. 用户权限:
    ●高级管理员:修改用户信息、修改图书信息、添加图书、添加用户、删除图书、删除用户、全局浏览、查找用户或图书、调戏系统。
    ●普通管理员:全局浏览、查找用户或图书。
    ●读者:借还图书,修改自己信息,注销自己。

程序框架(H图)

在这里插入图片描述

程序框图

主函数

在这里插入图片描述

超级管理函数

在这里插入图片描述

显示函数

在这里插入图片描述

登录函数

在这里插入图片描述

读者函数

在这里插入图片描述

程序代码

打开文件函数

//打开文件
void open()
{
    rename("BOOKSCCJ", "books.txt");
ifstream fcin;   //定义读文件流fcin
fcin.open("books.txt", ios::in | ios::out);   //in 是读文件 ,out是写文件

int linnum = 1;//行数
while (getline(fcin, line))  //读取fcin一行到s
{
    istringstream ss(line);   //ss绑定一行字符串,然后以空格为分隔符把该行分隔开来
    ss >> name >> num >> bian >>maker>> author;    //ss分割开两个string类型
    NameMap.insert(pair<string, int>(name, num));
    btemp.na = name;
    btemp.nu = num;
    btemp.bian = bian;
    btemp.maker = maker;
    btemp.author = author;
    bookVector.push_back(btemp);
    len++;
    linnum++;
}

fcin.close();
rename( "books.txt","BOOKSCCJ");
rename("READERCCJ", "reader.txt");
ifstream mcin;   //定义读文件流fcin
color(15);
mcin.open("reader.txt", ios::in | ios::out);   //in 是读文件 ,out是写文件
color(6);

while (getline(mcin, line))  //读取fcin一行到s
{
    istringstream ss(line);   //ss绑定一行字符串,然后以空格为分隔符把该行分隔开来
    ss >> rname >> bnum >> hist >> passwd >> books;    //ss分割开两个string类型
    temp.na = rname;
    temp.his = hist;
    temp.nu = bnum;
    temp.books = books;
    temp.passwd = passwd;
    readerVector.push_back(temp);
    len++;
}
mcin.close();
rename( "reader.txt","READERCCJ");
}

显示函数

//显示程序
void display(int sele,int mb,int mr) { 
    color(3);
    int tl,t2;
    int linnum = 1;//行数
    if (mr == 0) {
        if (mb == 0) {
            cout << "╔═══════════════════════╦═══════════════════════╦═══════════════════════╦═══════════════════════╗" << endl;
            for (auto kk = 0; kk != 50; kk++)
            {
                if (linnum % 4 != 0)
                {
                    cout << "║" << left << setw(19) << bookVector[kk].na << "" << left << setw(2) << bookVector[kk].nu << "\t";
                }
                else
                {
                    cout << "║" << left << setw(21) << bookVector[kk].na << "" << left << setw(2) << bookVector[kk].nu << "║" << endl;
                    cout << "╠═══════════════════════╬═══════════════════════╬═══════════════════════╬═══════════════════════╣" << endl;
                }

                len++;
                linnum++;
            }
            while (linnum % 4 != 1) {
                cout << "║" << left << setw(20) << "更多: " << " \t";
                if (linnum % 4 == 0)
                    cout << "║" << left << setw(23) << " " << endl;
                linnum++;
            }
            cout << "╚═══════════════════════╩═══════════════════════╩═══════════════════════╩═══════════════════════╝" << endl;
        }

        else {
            cout << "╔═════════════════════╦═══════════════════╦═══════════════════╦═════════════════════╦═════════════════╗" << endl;
            cout << "║" << left << setw(21) << "书名"<< "║" << left << setw(19) << "在馆数量" << "║" << left << setw(19) << "书籍编号" << "║" << left << setw(21) << "出版社" << "║" << left << setw(17) << "作者" << "║" << endl;
            cout << "╠═════════════════════╬═══════════════════╬═══════════════════╬═════════════════════╬═════════════════╣" << endl;

            for (auto kk = 0; kk != bookVector.size(); kk++)
            {


                cout << "║" << left << setw(21) << bookVector[kk].na << "║" << left << setw(19) << bookVector[kk].nu << "║" << left << setw(19) << bookVector[kk].bian << "║" << left << setw(21) << bookVector[kk].maker << "║" << left << setw(17) << bookVector[kk].author << "║" << endl;

                cout << "╠═════════════════════╬═══════════════════╬═══════════════════╬═════════════════════╬═════════════════╣" << endl;


                len++;
                linnum++;
            }

            cout << "╚═════════════════════╩═══════════════════╩═══════════════════╩═════════════════════╩═════════════════╝" << endl;

        }
    }
    
    
    color(6);
    if (mb == 0) {
        if (sele == 0) {
            cout << left << setw(10) << "姓名" << left << setw(5) << "在借" << left << setw(5) << "共计" << left << setw(10) << "密码" << left << setw(40) << "在借列表" << endl;
        }
        if (mr == 0) t2 = 10;
        else t2 = readerVector.size();
        for (auto kk = 0; kk != t2; kk++)
        {
            if (sele == 0) {
                cout << left << setw(10) << readerVector[kk].na << left << setw(5) << readerVector[kk].nu << left << setw(5) << readerVector[kk].his << left << setw(10) << readerVector[kk].passwd << left << setw(40) << readerVector[kk].books << endl;
            }
        }
    }


}

普通管理员函数

//一般管理员函数
void BOOKREADER::search()
{
    display(0,0,0);
    int flag = 1;
    while(flag){
    color(4);

    cout << "【1.查找书名】  【 2.查找读者名】  【 0.退出】 " << endl;
    cout << "【3.查看所有图书】         【 4.查看所有读者】 " << endl;
    cin >> flag;
    if (flag == 4) {
        system("cls");
        display(0, 0, 1);
        color(4);
        cout << "###################################################" << endl;
        cout << "###################################################" << endl;
        cout << "【                   15.返回                     】" << endl;
        cout << "【                   0.退出                     】" << endl;
        color(15);
        cin >> flag;

        if (flag == 15)
        {
            system("cls");
            display(0, 0, 0);
        }
    }
    if (flag == 3) {
        system("cls");
        display(0, 1, 0);
        color(4);
        cout << "###################################################" << endl;
        cout << "###################################################" << endl;
        cout << "【                   15.返回                     】" << endl;
        cout << "【                   0.退出                      】" << endl;
        color(15);
        cin >> flag;
        if (flag == 15)
        {
            system("cls");
            display(0, 0, 0);
        }
    }
    if(flag==2)
    {
        color(15);
        cout << "你要找谁?" << endl;
        cin >> srname;
        vector <Point2>::iterator iElement = find(readerVector.begin(), readerVector.end(), srname);
        if (iElement != readerVector.end())
        {
            int nPosition = distance(readerVector.begin(), iElement);

            cout << "  find in the vector at position: " << nPosition + 1 << endl;

            cout << srname << "共借了;" << readerVector[nPosition].his << "本  在借;" << readerVector[nPosition].nu << "本,分别是:" << readerVector[nPosition].books << endl;
        }
        else cout << "抱歉,查无此人" << endl;

    }
    if (flag == 1)
    {
        color(15);
        cout << "你要找什么书?" << endl;
        cin >> sname; 
        if (NameMap.count(sname) > 0) {
            vector <Point1>::iterator bElement = find(bookVector.begin(), bookVector.end(), sname);
                if (bElement != bookVector.end())
                {
                    int bPosition = distance(bookVector.begin(), bElement);

                    cout << "  find in the vector at position: " << bPosition + 1 << endl;

                    cout << "书名;" << bookVector[bPosition].na << "   在馆;" << bookVector[bPosition].nu << "本,  编号:" << bookVector[bPosition].bian << "   作者:" << bookVector[bPosition].author << endl;
                }
        }
        else cout << "抱歉,我们暂时没有这本书哦" << endl;
    }



    }
}

高级管理员函数

//高级管理员函数
void BOOKREADER::edit() {
    display(0,0,0);
    int flag = 10;
    while(flag!=0){
    color(4);
    cout << "##########################################################################" << endl;
    cout << "###########################   请开始你的操作    ##########################" << endl;
    cout << "##########################################################################" << endl;
    cout << "【    1.查找书名    】 【     2.查找读者名    】  【     3.删除图书     】" << endl;
    cout << "【    4.删除读者    】 【    5.修改读者信息   】  【   6.修改图书信息   】" << endl;
    cout << "【    7.添加图书    】 【     8.添加读者      】  【 9.我就看看,不进去 】" << endl;
    cout << "【 10.显示更多图书  】 【    11.显示更多读者  】  【        0.退出      】 " << endl;
    cin >> flag;
    if (flag == 11) {
        system("cls");
        display(0, 0, 1);
        color(4);
        cout << "###################################################" << endl;
        cout << "###################################################" << endl;
        cout << "【                   15.返回                     】" << endl;
        cout << "【                   0.退出                     】" << endl;
        color(15);
        cin >> flag;

        if (flag == 15)
        {
            system("cls");
            display(0, 0, 0);
        }
    }
    if (flag == 10) {
        system("cls");
        display(0, 1, 0);
        color(4);
        cout << "###################################################" << endl;
        cout << "###################################################" << endl;
        cout << "【                   15.返回                     】" << endl;
        cout << "【                   0.退出                      】" << endl;
        color(15);
        cin >> flag;
        if (flag == 15)
        {
            system("cls");
            display(0, 0, 0);
        }
    }
    if (flag == 2)
    {
        color(15);
        cout << "你要找谁?" << endl;
        cin >> srname;
        //auto itr = BNameMap.find(srname);
        //cout << itr->first << "借了;" << itr->second << "本" << endl;
        vector <Point2>::iterator iElement = find(readerVector.begin(),readerVector.end(), srname);
        if (iElement != readerVector.end())
        {
            int nPosition = distance(readerVector.begin(), iElement);

            cout << "  find in the vector at position: " << nPosition + 1 << endl;

            cout << srname << "共借了;"<< readerVector[nPosition].his << "本  在借;" << readerVector[nPosition] .nu<< "本,分别是:"<< readerVector[nPosition].books<< endl;
        }
    }
    if (flag == 1)
    {
        color(15);
        cout << "你要找什么书?" << endl;
        cin >> sname;
        if (NameMap.count(sname) > 0) {
            vector <Point1>::iterator bElement = find(bookVector.begin(),bookVector.end(), sname);
            if (bElement != bookVector.end())
            {
                int bPosition = distance(bookVector.begin(), bElement);

                cout << "  find in the vector at position: " << bPosition + 1 << endl;

                cout << "书名;" << bookVector[bPosition].na << "   在馆;" << bookVector[bPosition].nu << "本,  编号:" << bookVector[bPosition].bian<< "   作者:" << bookVector[bPosition].author << endl;
            }
        }
        else cout <<"抱歉,我们暂时没有这本书哦" << endl;

    }
    if (flag == 3)
    {
        color(15);
        cout << "你要删除什么书?" << endl;
        cin >> sname;
        vector <Point1>::iterator bElement = find(bookVector.begin(), bookVector.end(), sname);
        if (bElement != bookVector.end())
        {
            int bPosition = distance(bookVector.begin(), bElement);

            cout << "  find in the vector at position: " << bPosition + 1 << endl;

            bookVector.erase(bElement);
        }
        cout << "已删除" << endl;
    }
    if (flag == 4)
    {
        color(15);
        cout << "你要删除谁?" << endl;
        cin >> srname;
        vector <Point2>::iterator iElement = find(readerVector.begin(), readerVector.end(), srname);
        if (iElement != readerVector.end())
        {
            int nPosition = distance(readerVector.begin(), iElement);

            cout << "  find in the vector at position: " << nPosition + 1 << endl;
            readerVector.erase(iElement);
 
        }
        cout << "已删除" << endl;
    }
    if (flag == 5)
    {
        color(15);
        cout << "你要修改谁的信息?" << endl;
        cin >> srname;
        vector <Point2>::iterator iElement = find(readerVector.begin(), readerVector.end(), srname);
        if (iElement != readerVector.end())
        {
            int nPosition = distance(readerVector.begin(), iElement);

            cout << "  find in the vector at position: " << nPosition + 1 << endl;

            cout << srname << "共借了;" << readerVector[nPosition].his << "本  在借;" << readerVector[nPosition].nu << "本,分别是:" << readerVector[nPosition].books << endl;
        }
        cout << "你要修那一项?" << endl;
        color(4);
        cout << "【   1.姓名   】 【  2.借书现量 】  【  3.借书名称  】 【  4.用户密码  】" << endl;
        color(15);
        cin >> what;
        if (what == 4)
        {
            cout << "你要修改为多少?" << endl;
            cin >> newpass;
            //BNameMap[srname] = newr;
            int nPosition = distance(readerVector.begin(), iElement);
            readerVector[nPosition].passwd = newpass;

        }
        if(what==2)
        {
             cout << "你要修改为多少?" << endl;
             cin >> newr;
        //BNameMap[srname] = newr;
             int nPosition = distance(readerVector.begin(), iElement);
             readerVector[nPosition].nu=newr;

        }
        
        if (what == 1)
        {
            cout << "你要修改为多少?" << endl;
            cin >> newn;
            int nPosition = distance(readerVector.begin(), iElement);
                readerVector[nPosition].na = newn;

        }
        if (what == 3)
        {
            cout << "你要修改为多少?" << endl;
            cin >> newn;
            int nPosition = distance(readerVector.begin(), iElement);
                readerVector[nPosition].books = readerVector[nPosition].books+newn;
                readerVector[nPosition].nu = readerVector[nPosition].nu + 1;
                readerVector[nPosition].his = readerVector[nPosition].his + 1;

        }
        cout << "已修改" << endl;
    }
    if (flag == 6)
    {
        color(15);
        cout << "你要修改什么书的信息?" << endl;
        cin >> sname;
        //cout << "你要修改为多少?" << endl;
        //cin >> newb;
        //NameMap[sname]= newb;
        //cout << "已修改" << endl;
        vector <Point1>::iterator bElement = find(bookVector.begin(), bookVector.end(), sname);
        if (NameMap.count(sname) > 0) {
            if (bElement != bookVector.end())
            {
                int bPosition = distance(bookVector.begin(), bElement);

                cout << "  find in the vector at position: " << bPosition + 1 << endl;

                cout << "书名;" << bookVector[bPosition].na << "   在馆;" << bookVector[bPosition].nu << "本,  编号:" << bookVector[bPosition].bian << "   作者:" << bookVector[bPosition].author << endl;
            }
            what = 1;
            while (what) {
                cout << "你要修那一项?" << endl;
                color(4);
                cout << "【   1.书名   】 【  2.库存现量 】  【  3.编号  】 【  4.作者  】【  0.退出并保存修改 】" << endl;
                color(15);
                cin >> what;
                if (what == 4)
                {
                    cout << "你要修改为多少?" << endl;
                    cin >> newau;
                    //BNameMap[srname] = newr;
                    int bPosition = distance(bookVector.begin(), bElement);
                    bookVector[bPosition].author = newau;

                }
                if (what == 2)
                {
                    cout << "你要修改为多少?" << endl;
                    cin >> newbnu;
                    //BNameMap[srname] = newr;
                    int bPosition = distance(bookVector.begin(), bElement);
                    bookVector[bPosition].nu = newbnu;

                }

                if (what == 1)
                {
                    cout << "你要修改为多少?" << endl;
                    cin >> newbna;
                    int bPosition = distance(bookVector.begin(), bElement);
                    bookVector[bPosition].na = newbna;

                }
                if (what == 3)
                {
                    cout << "你要修改为多少?" << endl;
                    cin >> newbbian;
                    int bPosition = distance(bookVector.begin(), bElement);
                    bookVector[bPosition].bian = newbbian;


                }
            }
        }
        else cout << "抱歉,我们暂时没有这本书哦" << endl;
    }
    if (flag == 7)
    {
        int keep = 1;
        color(15);
        while(keep){
        cout << "请输入书名:" << endl;
        cin >> name;
        vector <Point1>::iterator bElement = find(bookVector.begin(), bookVector.end(), name);
       
            if (bElement != bookVector.end())
            {
                cout << "书籍已存在,请重新出入" << endl;
                
            }
            else {
                cout << "请输入数目" << endl;
                cin >> num;
                cout << "请输入编号:" << endl;
                cin >> bian;
                cout << "请输入作者" << endl;
                cin >> author;
                cout << "请输入出版商" << endl;
                cin >> maker;
                btemp.na = name;
                btemp.nu = num;
                btemp.bian = bian;
                btemp.author = author;
                btemp.maker = maker;
                bookVector.push_back(btemp);
                cout << "已添加" << endl;
                keep = 0;
            }
            
        }
    }
    if (flag == 8)
    {
        color(15);
        cout << "请输入读者姓名:" << endl;
        cin >> rname;
        cout << "请输入初始密码" << endl;
        cin >> bnum;
        //BNameMap.insert(pair<string, int>(rname, bnum));
        temp.na = rname;
        temp.passwd = bnum;
        temp.nu = 0;
        temp.his = 0;
        temp.books = "无";
        readerVector.push_back(temp);
        cout << "已添加" << endl;
    }
    if (flag == 9){
        system("cls");
        color(4);
            for (int ti = 0; ti < 4; ti++)
            {
                cout << endl;

            }
        cout << "                                                你好坏坏~~~~~。~~~~~" << endl;}
        for (int ti = 0; ti < 4; ti++)
        {
            cout << endl;

        }
}
    rename("BOOKSCCJ", "books.txt");
    ofstream fcout;   //定义写文件流fcout
    fcout.open("books.txt");
    color(10);
    cout << "\n写入文件books.txt··············" << endl;

    for (auto kk = 0;  kk != bookVector.size(); kk++)
    {
        fcout << bookVector[kk].na << " " << bookVector[kk].nu << " " << bookVector[kk].bian << " " << bookVector[kk].maker<<" " << bookVector[kk].author << endl;

    }
    fcout.close();
    rename("books.txt","BOOKSCCJ");
    ofstream bcout;   //定义写文件流fcout
    rename("READERCCj", "reader.txt");
    bcout.open("reader.txt");
    color(10);
    cout << "\n写入文件reader.txt··············" << endl;

    for (auto kk = 0; kk != readerVector.size(); kk++)
    {  
        bcout << readerVector[kk].na << " " << readerVector[kk].nu << " " << readerVector[kk].his << " " << readerVector[kk].passwd << " " << readerVector[kk].books << endl;
    }
    bcout.close();
    rename("reader.txt", "READERCCJ");
}

登录函数

//登录
int login() {
    system("color F0");
    rename("USERCCJ","user.txt");
    int b, c = 0, pass[8], i = 0, p;
    ifstream fcin;
    fcin.open("user.txt", ios::in | ios::out);   //in 是读文件 ,out是写文
    string line, name, rname, books;
    int len = 0, num, bnum, flag = 10, m = 1, hist,passwd;
    map<string, int> NameMap;
    while (getline(fcin, line))  //读取fcin一行到s
    {
        istringstream ss(line);   //ss绑定一行字符串,然后以空格为分隔符把该行分隔开来
        //cout << line << endl;
        ss >> name >> num;    //ss分割开两个string类型
        NameMap.insert(pair<string, int>(name, num));
        len++;

    }
    fcin.close();
   
    rename("user.txt","USERCCJ" );
    ifstream mcin;   //定义读文件流fcin
    rename("READERCCJ", "reader.txt");
    mcin.open("reader.txt", ios::in | ios::out);   //in 是读文件 ,out是写文件
    cout << endl;

    //map<string, int> BNameMap;
    vector<Point2>readerVector2;
    Point2 temp2;
    while (getline(mcin, line))  //读取fcin一行到s
    {
        istringstream ss(line);   //ss绑定一行字符串,然后以空格为分隔符把该行分隔开来
       // cout << line << endl;
        ss >> rname >> bnum >> hist >> passwd >> books;    //ss分割开两个string类型
        //BNameMap.insert(pair<string, int>(rname, bnum));
        temp2.na = rname;
        temp2.his = hist;
        temp2.nu = bnum;
        temp2.passwd = passwd;
        temp2.books = books;

        readerVector2.push_back(temp2);
        len++;
    }
    mcin.close();
    rename("reader.txt", "READERCCJ");
    cout << endl;

    //map<string, int> BNameMap;

    if (swich == 1) {
        for (int ti = 0; ti < 8; ti++)
        {
            cout << endl;

        }
        cout << "                                                       正在启动" << endl;
        cout << endl;
        cout << endl;
        cout << "                                " << " ";
        for (int n = 0; n < 50; n++) {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 1 | 0 | 128);
            cout << " " << "";
            Sleep(50);
        }
        
        
        
        
        for (int ti = 0; ti < 8; ti++)
        {
            cout << endl;

        }
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 16 | 128 | 112);
        cout << "                                                <- 系统初始化完成 ->" << endl;
        Sleep(1000);
        system("cls");
        swich++;
        system("color F0");
    }
    system("cls");
    for (int ti = 0; ti < 8; ti++)
    {
        cout << endl;

    }

    cout << "                                 ═════════════════════════════════════════════════════════════" << endl;
    cout << "                                                   欢迎使用庆国淡泊书局系统                         " << endl;
    cout << "                                 ═════════════════════════════════════════════════════════════" << endl;
    cout << endl;

    cout << "                                                    请输入用户名:" << " ";
    cin >> a;
    cout << endl;
    cout << "                                                    请输入密码:" << " ";
    //密码隐藏
    c = 0;
    for (i = 0; i < 8; i++)
    {
        b = _getch();
        if (b >= '0' && b <= '9')
        {
            pass[i] = b;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 15 | 0 | 0);
            cout << "*";
            m = b - 48;
            for (int t = 0; t < 7 - i; t++) {

                m = m * 10;
            }
            c = c + m;
        }
    }
    cout << endl;
    if (NameMap.count(a) > 0)//检验key值存在
    {
        auto itb = NameMap.find(a);
        system("color F0");
        if (itb->second == c) {
            for (int ti = 0; ti < 4; ti++)
            {
                cout << endl;

            }
            cout << "                                                       " << " ";
            for (int n = 0; n < 4; n++) {

                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 16 | 128 | 112);
                cout << "●" << "";
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 15 | 127 | 128);
                cout << "  " << "";
                Sleep(500);
            }
            return 1;
        }
        else return 0;
    }
    else {
        vector <Point2>::iterator iElement = find(readerVector2.begin(), readerVector2.end(), a);
        if (iElement != readerVector2.end())
        {
            int nPosition = distance(readerVector2.begin(), iElement);
            system("color F0");
            if (readerVector2[nPosition].passwd== c) {
                for (int ti = 0; ti < 4; ti++)
                {
                    cout << endl;

                }
                cout << "                                                       " << " ";
                for (int n = 0; n < 3; n++) {

                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 16 | 128 | 112);
                    cout << "●" << "";
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 15 | 127 | 128);
                    cout << "  " << "";
                    Sleep(500);
                }
                return 1;
            }
            else return 0;

           
        }
    }
}

读者借阅函数

//借阅
void borrow(string username)
{
    display(1,0,0);
    vector <Point2>::iterator iElement = find(readerVector.begin(), readerVector.end(), username);
        if (iElement != readerVector.end())
        {
            int nPosition = distance(readerVector.begin(), iElement);

            cout << "  find in the vector at position: " << nPosition + 1 << endl;

            cout << username << "共借了;" << readerVector[nPosition].his << "本  在借;" << readerVector[nPosition].nu << "本,分别是:" << readerVector[nPosition].books << endl;
        }
        int state = 1;
    while(state)
    {

    cout << "本店《红楼》新上架章节,快来看看吧!" << endl;
    cout << "你要选择那一项?" << endl;
    color(4);
    cout << "【   1.借书   】 【   2.归还   】  【  3.注销账户  】 【  4.更改密码  】【  0.退出  】" << endl;
    color(15);
    cin >> state;
    if (state == 1)
    {
        string bookname;
        cout << "请输入书名(回车确定):" << endl;
        cin >> bookname;
        if (NameMap.count(bookname) > 0) {

         vector <Point1>::iterator bElement = find(bookVector.begin(), bookVector.end(), bookname);
         if (NameMap.count(bookname) > 0) {
             if (bElement != bookVector.end())
             {
                 int bPosition = distance(bookVector.begin(), bElement);
                 bookVector[bPosition].nu = bookVector[bPosition].nu - 1;

             }
         }
        //NameMap[bookname] = NameMap[bookname] - 1;
        int nPosition = distance(readerVector.begin(), iElement);

        readerVector[nPosition].nu = readerVector[nPosition].nu + 1;
        readerVector[nPosition].his = readerVector[nPosition].his + 1;
        if (readerVector[nPosition].nu == 1)
        clean_str(&readerVector[nPosition].books, "无");
        readerVector[nPosition].books = readerVector[nPosition].books + bookname;
        }
        else cout << "抱歉,我们暂时没有这本书哦" << endl;

    }
    if (state == 2)
    {
        string bookname;
        cout << "请输入书名(回车确定):" << endl;
        cin >> bookname;

        vector <Point1>::iterator bElement = find(bookVector.begin(), bookVector.end(), bookname);
        if (NameMap.count(bookname) > 0) {
            if (bElement != bookVector.end())
            {
                int bPosition = distance(bookVector.begin(), bElement);
                bookVector[bPosition].nu = bookVector[bPosition].nu + 1;

            }
        }
       // NameMap[bookname] = NameMap[bookname] + 1;
        int nPosition = distance(readerVector.begin(), iElement);
        readerVector[nPosition].nu = readerVector[nPosition].nu-1;
        clean_str(&readerVector[nPosition].books,bookname);
        cout << "处理后:" << readerVector[nPosition].books;
        if (readerVector[nPosition].nu == 0)
           readerVector[nPosition].books= "无";

    }
    if (state == 3)
    {
        int sure = 1;
        while (sure)
        {
        cout << "确认注销?该操作无法撤销!:" << endl;
        cout << "【1.我已确认】 【2.你再挽留一下,看看我心情好不好】  【0.算了算了】" << endl;
        cin >> sure;
        if(sure==1){
        readerVector.erase(iElement);
        state = 0;
        sure = 0;
        cout << "期待再见!:" << endl;
        }
        if (sure == 2) {
            cout << "再您妈的见!告辞!" << endl;
            cout << "哈哈哈哈,开个玩笑,亲爱的在考虑下哟:" << endl;
        }
        }
        }
    if (state == 4)
        {
            int passn;
            cout << "请输入密码:" << endl;
            cin >> passn;
            int nPosition = distance(readerVector.begin(), iElement);
            readerVector[nPosition].passwd =passn;
        }
    }
    rename("BOOKSCCJ", "books.txt");
    ofstream fcout;   //定义写文件流fcout
    fcout.open("books.txt");
    color(10);
    cout << "\n写入文件books.txt··············" << endl;

    for (auto kk = 0; kk != bookVector.size(); kk++)
    {
        fcout << bookVector[kk].na << " " << bookVector[kk].nu << " " << bookVector[kk].bian << " " << bookVector[kk].maker << " " << bookVector[kk].author << endl;

    }
    fcout.close();
    rename("books.txt", "BOOKSCCJ");
    ofstream bcout;   //定义写文件流fcout
    rename("READERCCj", "reader.txt");
    bcout.open("reader.txt");
    color(10);
    cout << "\n写入文件reader.txt··············" << endl;

    for (auto kk = 0; kk != readerVector.size(); kk++)
    {
        bcout << readerVector[kk].na << " " << readerVector[kk].nu << " " << readerVector[kk].his << " " << readerVector[kk].passwd << " " << readerVector[kk].books << endl;
    }
    bcout.close();
    rename("reader.txt", "READERCCJ");
}

主函数

int main()
{
    
    int b=4;
    open();
    while (1) {
        
        b=login();
        if (b == 1) {

            //登录提示,模式控制
            if (a == "范思辙")
            {
                system("color 0F");
                system("cls");
                color(15);
                for (int ti = 0; ti < 8; ti++)
                {
                    cout << endl;

                }
                cout << endl;
                cout << "                                                   欢迎~ 亲爱的!" << a<<endl;
                Sleep(1000);
                system("cls");
                BOOKREADER sadmin;
                ADMIN admin;
                admin.ADMINin(sadmin);
            }
            else if(a=="大学士甲"|| a=="大学士乙"|| a=="大学士丙")
            {
                system("color 0F");
                system("cls");
                color(15);
                for (int ti = 0; ti < 8; ti++)
                {
                    cout << endl;

                }
                cout << endl;
                cout << "                                                   欢迎~ 亲爱的" <<a<< endl;
                Sleep(1000);
                system("cls");
                BOOKREADER sadmin;
                sadmin.search();

            }
            else
            {
                system("color 0F");
                system("cls");
                color(15);
                for (int ti = 0; ti < 8; ti++)
                {
                    cout << endl;

                }
                cout << endl;
                cout << "                                           寂寞宫廷春欲晚,与君相约醉《红楼》!" << endl;
                cout << endl;
                Sleep(1500);
                cout << "                                                   欢迎~ 亲爱的!" << a << endl;
                Sleep(800);
                system("cls");
                cout << endl;
                borrow(a);

            }
        }
        else
        {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0 | 16 | 128 | 112);
            for (int ti = 0; ti < 4; ti++)
            {
                cout << endl;

            }
            cout << "                                                    用户名或密码错误" << " ";
            cout << " 请重试!" << " ";
        }

        Sleep(1000);
    }
}

程序工程源文件下载

具体功能要求 1、图书维护 (1)设置管理员账号和密码; (2)图书信息录入:图书编号、书名、作者名、分类、图书数量; (3)图书信息更改; (4)图书信息删除; (5)图书信息查询:按图书编号查询、按书名查询、按作者名查询; (6)图书信息全部显示; (7)图书信息全部删除; (8)退出图书维护界面。 2、读者维护 (1)设置管理员账号和密码; (2)读者信息录入:读者姓名、学号; (3)读者信息更改; (4)读者信息删除; (5)读者信息查询:按读者编号查询、按读者姓名查询; (6)读者信息全部显示; (7)读者信息全部删除; (8)退出读者维护界面。 3、借书 (1)设置借书的范围(如5本); (2)图书数量随着借书的数量减少; (3)输入读者编号与图书编号后借书成功。 4、还书 (1)图书数量随着还书的数量增加; (2)输入读者编号与图书编号后还书成功。 5、添加功能 (1)添加一本图书的基本信息,包括书名、图书编号、作者名、类别、图书数量。 (2)添加读者信息: 添加图书借阅的基本信息,包括书名、学号。 6、更改功能 对图书和读者的信息进行修改。 7、查找功能 (1)图书信息查找; (2)读者信息查找。 8、显示功能 (1)显示所有图书信息; (2)显示所有借阅信息。 9、删除功能 (1)删除图书的基本信息; (2)删除读者的基本信息; (3)删除图书借阅基本信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值