图书馆信息管理系统——》你说这是你的大作业?>>>C++项目实战
2022-01-04 00:44
1211 查看
前言:你说这是你的大作业?>>>虽然看起来很简单,很普通,但它确实是大作业
,你可以从中发现无限乐趣…
ヾ(◍°∇°◍)ノ゙——
目录:
【1】客户需求描述(题目描述):
【2】难点分析:
难点1️⃣(题目本身)
-
最开始看到这个作业时,我是很不以为然的,毕竟都是提前自学过的了( •̀ ω •́ )✧,可——
-
我还是太弱小了ಥ_ಥ
-
看看这变态需求
-
1:支持大数据,比如书籍记录突破百万,用户数量突破万级规 20000 模
-
2:搜索时性能考察,调查、思考、设计加强搜索性能的方式
-
3.样本数据
难点2️⃣(卷神同学)
- 同学A😎:我要用Qt,做一个。
很多同学不知道Qt是什么,这里简单地介绍一下。
> < 这是Qt的软件
这:你可以在Codeblock看到它
》这是简单的界面,他教我写的
还有…
- 同学B😼:我要创个桌面程序!!!
可能还有朋友不知道C++怎么弄桌面应用
看这里——
`
- 同学C😈:你们都在编程,我整个网页
他自学了前端,学了HTML,还参加过网页设计比赛
这是他发给我的软件
- 同学D👻:mySQL选手
这个是我猜的≡(▔﹏▔)≡
学院那么大,来个学完数据库的同学,不过分吧》》》》
我都来不及装软件ヽ(≧□≦)ノ
【3】开始——
世界纵已内卷,编程不容躺平
编程必须强!!!💥🐉
【4】代码实现:
注:使用CB编写,VS需要重写时间函数
Libray(图书馆),Labray属拼写错误
1️⃣Labray.h
#ifndef LABRAY_H #define LABRAY_H #include<iostream> #include<string> #include<cstring> #include<windows.h> #include<functional> #include<algorithm> using namespace std; #include<vector> #include<ctime> #include<unordered_map> //----------------------------------引用的库 //界面美化 void toxy(int x, int y); //将光标移动到X,Y坐标处 void SetColorAndBackground(int ForgC, int BackC); //设置颜色 //---------------------- //-------图书类,管理员类,读者类的设定 class Book { public: string Book_name; string IBSN; string writer; string classify; int cur_num; Book() {} Book(string n,string i,string w,string c,int num):Book_name(n),IBSN(i),writer(w),classify(c),cur_num(num){} }; class Administrator { friend class Labray; public: string a_account; string a_code; Administrator() {}; Administrator(string account, string code) :a_account(account), a_code(code) {} }; class User { friend class Labray; public: string u_account; string u_code; unordered_map<string,int>u_memo; unordered_map<string,int>u_back_memo; User(){}; User(string account, string code) :u_account(account), u_code(code) {} }; //------- //------------------------------ class Labray { private: unordered_map<string, Administrator>Admins;//用哈希表查找,更加快 unordered_map<string, User>Users; vector<Book>tmbook; vector<string>Borrow_memo; vector<string>Back_memo; string Landed_accout="0";//C++11标准,可直接这样初始化用,这里使用是为了后面的部分操作 //--------------------------- void init_book(); void init_Admin(); void init_User(); void init_Borrow_memo(); void init_Back_memo(); void Save_Book(); void Save_Admins(); void Save_Users(); void Save_Borrow_memo(); void Save_Back_memo(); //---------------------- void Search_thebook(); void myover(); //强制退出 //--------------------- void AdminStart(); void UserStart(); string getCur_time(); public: Labray(); void Landing(); }; #endif // LABRAY_H
2️⃣Labray.cpp
#include "Labray.h" #include<windows.h> #include<fstream> constexpr auto Bookfile = "H_books.txt"; constexpr auto Adminfile = "Admins.txt"; constexpr auto Usersfile = "users.txt"; constexpr auto Borrowfile="Borrow_memo.txt"; constexpr auto Backfile="Back_memo.txt"; //----------------------------------辅助函数,帮助查找 class help_find{//,辅助find_if查找,无需泛型编程,就不用写模板 private: string name; //你可以用适配器,只要你能正确匹配函数即可 public: help_find(string t_name):name(t_name){}; bool operator()(const Book& book) { if (book.Book_name == name)return true; else return false; } }; int str_to_num(string str){ int jie=0; for(int i=0;i<str.size();i++){ jie=jie*10+(str[i]-'0'); } return jie; } //-----------------------------------------------------设置 void SetColorAndBackground(int ForgC, int BackC) { WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor); } void toxy(int x, int y) //将光标移动到X,Y坐标处 { COORD pos = { x , y }; HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(Out, pos); return ; } //对界面设置函数的定义,这两个函数,记住就行了,现阶段不要求理解 //---------------------------------------------------- //--获取时间 string Labray::getCur_time(){ time_t t; //typedef long time_t; time(&t); //获取系统时间 char* str = ctime(&t); //将时间t转换为字符串 return str; } //-------------------关键的构造函数,初始化 Labray::Labray(){ ifstream ifs1; ifs1.open(Bookfile, ios::in); if (!ifs1.is_open()) {//情况一:文件未创建,即文件不存在 //初始化属性 cout << "-----------------------------------------------------" << endl; cout << "提示:--!!!图书信息文件未创建,运行系统可自动生成文件!!! --" << endl; cout << "-----------------------------------------------------" << endl; ifs1.close(); return; } //2.文件存在,但数据为空 char ch; ifs1 >> ch; if (ifs1.eof()) { cout << "--------------------------------------------------------" << endl; cout << "提示:--!!!图书馆尚无存书,等待管理员添加图书!!!--" << endl; cout << "--------------------------------------------------------" << endl; ifs1.close(); return; } //图书馆有图书,我们需要把文件中的图书信息读到程序中 ifs1.close(); this->init_book(); this->init_Admin(); this->init_User(); this->init_Borrow_memo(); this->init_Back_memo(); SetColorAndBackground(1,0); cout << "------------------------- " << endl; cout << "[H]系统现有【用户人数】为:" << this->Users.size() << endl; cout << "[H]系统现有【管理员人数】为:" << this->Admins.size() << endl; cout << "[H]系统现有【图书种类】为:" << this->tmbook.size() << endl; cout << "------------------------- " << endl; SetColorAndBackground(7,0); cout << endl; } //--------------------- void Labray:: Save_Book() { //保存图书文件 ofstream ofs; ofs.open(Bookfile, ios::out);//写文件 //将每个人的数据写入文件中 for (int i = 0; i < this->tmbook.size(); i++) { ofs << this->tmbook[i].Book_name << ' ' << this->tmbook[i].IBSN << ' ' << this->tmbook[i].writer<<' '<< this->tmbook[i].classify <<' '<<this->tmbook[i].cur_num<<endl; } ofs.close(); return; } void Labray::Save_Admins() { ofstream ofs; ofs.open(Adminfile, ios::out);//写文件 //将每个人的数据写入文件中 for (pair<string,Administrator> it:this->Admins) { ofs << it.second.a_account << ' ' << it.second.a_code<< endl; } ofs.close(); return; } void Labray::Save_Users() { ofstream ofs; ofs.open(Usersfile, ios::out);//写文件 //将每个人的数据写入文件中 for (pair<string, User> it : this->Users) { ofs << it.second.u_account << ' ' << it.second.u_code << endl; } ofs.close(); return; } void Labray::Save_Borrow_memo(){ ofstream ofs; ofs.open(Borrowfile,ios::out); //写入借阅记录 for(string it:this->Borrow_memo){ ofs<<it<<endl; } ofs.close(); return; } void Labray::Save_Back_memo(){ ofstream ofs; ofs.open(Backfile,ios::out); //写入借阅记录 for(string it:this->Back_memo){ ofs<<it<<endl; } ofs.close(); return; } void Labray::init_book() { ifstream ifs; ifs.open(Bookfile, ios::in); string name; string IBSN; string writer; string classify; string tmp_cur_num; while (ifs >>name && ifs >>IBSN && ifs >>writer && ifs >>classify && ifs >>tmp_cur_num) { int cur_num=str_to_num(tmp_cur_num); Book tmp(name,IBSN,writer,classify,cur_num); this->tmbook.push_back(tmp); } ifs.close(); return; } void Labray::init_Admin() { ifstream ifs; ifs.open(Adminfile, ios::in); string account, code; while (ifs >> account && ifs >>code) { Administrator tmp(account,code); this->Admins[tmp.a_account]=tmp; } ifs.close(); if(this->Admins.empty()){ Administrator tmp("20220101","123456"); this->Admins["20220101"]=tmp;//添加默认管理员 this->Save_Admins(); } return; } void Labray::init_User() { ifstream ifs; ifs.open(Usersfile, ios::in); string account; string code; while (ifs >> account && ifs >> code) { User tmp(account,code); this->Users[tmp.u_account] = tmp; } ifs.close(); return; } void Labray::init_Borrow_memo() { ifstream ifs; ifs.open(Borrowfile, ios::in); string informantion; while (getline(ifs,informantion)) { this->Borrow_memo.push_back(informantion); } ifs.close(); return; } void Labray::init_Back_memo() { ifstream ifs; ifs.open(Backfile, ios::in); string informantion; while (getline(ifs,informantion)) { this->Back_memo.push_back(informantion); } ifs.close(); return; } //以上实现文件交互 //-------------------------------------------------- //--------- void Labray::myover(){ Sleep(500); float x,y,a; for(y=1.5;y>-1.5;y-=0.1){ for(x=-1.35;x<1.5;x+=0.05){ a=x*x+y*y-1; putchar(a*a*a-x*x*y*y*y<0.0?'*':' '); } system("color 0c"); putchar('\n'); } cout << "欢迎下次使用!!!" << endl; exit(0); } void Labray::Landing() { cout << "-----------------------------------------------------" << endl; cout << "-------------欢迎使用《H_de图书馆系统》---------------" << endl; cout << "-----------------------------------------------------" << endl; cout << "请选择--登陆模式:" << endl; SetColorAndBackground(6,4); cout << endl; cout << "》】-------------------【《" << endl;//画个小老虎 cout << "| 王 |" << endl; cout << "| ---- ----- |" << endl; cout << "| |0 0| |" << endl; cout << "| [][] |" << endl; cout << "|---------vvvvvv----------|" << endl; cout << "|-------------------------|" << endl; cout<<endl; SetColorAndBackground(7,0); BigFlag:cout << "请输入你的登陆模式——pleace input you choice!!!" << endl; cout<<"******************************"<<endl; cout <<"-[0]------管理员登陆--/;"<<endl; cout<<"-[1]---------读者登陆/;"<<endl; cout<<"-[2]--------注册用户账号/;" << endl; cout<<"******************************"<<endl; char flag = '0'; cin >> flag;//登陆分流的标识 string you_account; string you_code; //---------管理员身份 if (flag=='0') { Flag0: SetColorAndBackground(9,0); cout << " ------------------------------------------------" << endl; cout << " 》》》管理员登陆《《《 " << endl; cout << " ------------------------------------------------" << endl; SetColorAndBackground(7,0); string jd="0"; cout<<"选项..."<<endl; cout<<"退出程序——【输0】"<<endl; cout<<"继续程序——【非0】"<<endl; cout<<"输入选项..."<<endl; cin>>jd; if(jd=="0")this->myover(); cout << " 请输入你的账号(教师编号/学生学号):...." << endl; cout << " ------------------------------------------------" << endl; cin >> you_account; Sleep(500); cout << " ------------------------------------------------" << endl; cout << " 请输入你的密码(用户默认密码为123456)...." << endl; cout << " ------------------------------------------------" << endl; cin >> you_code; cout << " ------------------------------------------------" << endl; if (!this->Admins.count(you_account)) { SetColorAndBackground(7,4); cout << " 没有该账户存在!!!" << endl; SetColorAndBackground(7,0); system("pause"); system("cls"); goto Flag0; } else { if (this->Admins[you_account].a_code != you_code) { SetColorAndBackground(7,4); cout << "》》账号存在,但密码错误《《" << endl; SetColorAndBackground(7,0); system("pause"); system("cls"); goto Flag0; } else { SetColorAndBackground(4,0); cout << "!!欢迎使用管理员身份登陆系统!!" << endl; this->Landed_accout = you_account; this->AdminStart(); } } } //---------读者身份 else if(flag=='1') { Flag1: SetColorAndBackground(9,0); cout << " -----------------------------------------------------" << endl; cout << " 》》》读者登陆《《《 " << endl; cout << " -----------------------------------------------------" << endl; SetColorAndBackground(7,0); string jd="0"; cout<<"选项..."<<endl; cout<<"退出程序——【输0】"<<endl; cout<<"继续程序——【非0】"<<endl; cout<<"输入选项..."<<endl; cin>>jd; if(jd=="0")this->myover(); Sleep(500); cout << " 请输入你的账号(教师编号/学生学号):...." << endl; cout << " -----------------------------------------------------" << endl; cin >> you_account; Sleep(500); cout << " -----------------------------------------------------" << endl; cout << " 请输入你的密码(用户默认密码为123456)...." << endl; cout << " -----------------------------------------------------" << endl; cin >> you_code; cout << " -----------------------------------------------------" << endl; if (!this->Users.count(you_account)) { cout << "没有该账户存在!!!" << endl; system("pause"); system("cls"); goto Flag1; } else { if (this->Users[you_account].u_code != you_code) { cout << "》》账号存在,但密码错误《《" << endl; system("pause"); system("cls"); goto Flag1; } else { SetColorAndBackground(4,0); cout << "!!欢迎使用学生身份登陆系统!!" << endl; this->Landed_accout = you_account; this->UserStart(); } } } else if(flag=='2') { SetColorAndBackground(4,6); cout << "=================================" << endl; cout << "提示:欢迎您注册HNU图书馆系统账号" << endl; cout << "=================================" << endl; SetColorAndBackground(7,0); string jd="0"; cout<<"选项..."<<endl; cout<<"退出程序——【输0】"<<endl; cout<<"继续程序——【非0】"<<endl; cout<<"输入选项..."<<endl; cin>>jd; if(jd=="0")this->myover(); string you_U_account; cout << "请输入您的账号....." << endl; cin >> you_U_account; if(this->Users.count(you_U_account)){ cout<<"已有该账号存在,本次操作自动撤销!"<<endl; }else{ cout << "请输入您的密码....." << endl; string you_U_code; cin >> you_U_code; User tmp(you_U_account, you_U_code); this->Users[you_U_account] = tmp; this->Save_Users(); cout << "注册成功!请重新登陆系统." << endl; flag = '1'; } system("pause"); system("cls"); goto Flag1; } else { SetColorAndBackground(0,6); cout << "警告!!!选项输入错误!请重新输入" << endl; SetColorAndBackground(7,0); system("pause"); system("cls"); goto BigFlag; } } //---------------------------------------------------------------------------------------------------- //难点图书查找 void Labray::Search_thebook() { Flag: cout << "检索方式:::::::[A].书名(匹配检索) [B].作者名(匹配检索) "<<endl; cout<<"[C].IBSN/ISSN(精确检索) [D].分类号(精确检索) [E]信息精确搜索 [F]分类号(模糊检索) " << endl; cout << "输入检索选项......" << endl; char ch; cin >> ch; if (ch == 'A') { string Bname; cout << "请输入您要检索的图书名称..." << endl; cin >> Bname; bool flag=0; for (Book it : tmbook) { if (it.Book_name.find(Bname)!=string::npos) { if(!flag)cout << "检索结果如下>>>>" << endl; flag = 1; cout <<"《"<< it.Book_name<<"》" << ' ' << it.IBSN << ' ' << it.writer << ' ' << it.classify<<' '<<"现有数量:" <<it.cur_num<< endl; } } if (!flag) { cout << "未找到相关图书!" << endl; } } //------------------------------------------------------ else if (ch == 'B') { string writer_name; cout << "请输入您要检索的图书的作者/编者/译者名称..." << endl; cin >> writer_name; bool flag = 0; for (Book it : tmbook) { if (it.writer.find(writer_name)!=string::npos) { if (!flag)cout << "检索结果如下>>>>" << endl; flag = 1; cout <<"《"<< it.Book_name<<"》" << ' ' << it.IBSN << ' ' << it.writer << ' ' << it.classify<<' '<<"现有数量:" <<it.cur_num<< endl; } } if (!flag) { cout << "未找到相关作者对应的图书!" << endl; } } else if (ch == 'C') { string the_IBSN; cout << "请输入对应的IBSN/ISSN编号..." << endl; cin >> the_IBSN; bool flag = 0; for (Book it : tmbook) { if (it.IBSN ==the_IBSN) { if (!flag)cout << "检索结果如下>>>>" << endl; flag = 1; cout <<"《"<< it.Book_name<<"》" << ' ' << it.IBSN << ' ' << it.writer << ' ' << it.classify<<' '<<"现有数量:" <<it.cur_num<< endl; } } if (!flag) { cout << "未找到相关IBSN/ISSN对应的图书!" << endl; } } else if (ch == 'D') { string the_classify; cout << "请输入对应的分类号!!!" << endl; cin >> the_classify; bool flag = 0; for (Book it : tmbook) { if (it.classify == the_classify) { if (!flag)cout << "检索结果如下>>>>" << endl; flag = 1; cout <<"《"<< it.Book_name<<"》" << ' ' << it.IBSN << ' ' << it.writer << ' ' << it.classify<<' '<<"现有数量:" <<it.cur_num<< endl; } } if (!flag) { cout << "未找到相关分类号对应的图书" << endl; } } else if(ch=='E'){ cout<<"1s后启用信息精确搜索。输入一条您已知的关于该图书的信息(作者/书名/ISBN...)。系统自动为您搜索相关结果"<<endl; Sleep(1000); system("cls"); SetColorAndBackground(8,0); string information; toxy(0, 8); printf("请输入您要查询图书的信息:"); cin >> information;; toxy(0, 10); printf("正在查询...."); Sleep(500); int i=12; toxy(10, 5); printf("***********************************************图书总览******************************************************"); toxy(10, 8); printf("-------------------------------------------------------------------------------------------------------------"); toxy(10, 9); printf(" 书名 ISSN/IBSN 作者名 分类号 现有数量 "); toxy(10, 10); printf("-------------------------------------------------------------------------------------------------------------"); bool flag=0; cout<<endl; for(Book& it:this->tmbook){ if(it.Book_name==information|| it.IBSN==information || it.writer==information||it.classify==information){ toxy(10, i); flag=1; cout<<"《"<<it.Book_name<<"》"<<" "<<it.IBSN<<" "<<it.writer<<" "<<it.classify<<"num:"<<it.cur_num<<endl; } } if(!flag){ cout<<"空空如也的查找结果"<<endl; } system("pause"); system("cls"); goto Flag; } else if(ch='F'){ SetColorAndBackground(4,0); cout<<"使用分类号模糊搜索,自动匹配出符合分类条件的书籍。"<<endl; SetColorAndBackground(7,0); cout<<"分类规则如下:"<<endl; cout<<"示例:MA001-AD01-E01,代表 [数学001]-[高等数学01]-[教材01],所代表的图书是《高等数学教材第1版》"<<endl; cout<<"简要描述:"<<endl; cout<<"[1]:每个分类号有三级,其中的[字母]代表[种类],[数字]代表[编号]"<<endl; cout<<"[2]:(0,1)字符代表第一个分类号,(6,7)字符代表第二个分类号,(11)字符代表第三个分类号"<<endl; cout<<"[3]:数字属于系统自动编排,不必详细了解其规则。"<<endl; cout<<"开始分类号模糊搜索..."<<endl; cout<<"分类号模糊检索将分三次,依次输入各级分类,每次输入一个子分类"<<endl; string jd="0"; cout<<"选项..."<<endl; cout<<"终止程序——【输0】"<<endl; cout<<"继续程序——【非0】"<<endl; cout<<"输入选项..."<<endl; cin>>jd; if(jd=="0"){ system("pause"); system("cls"); goto Flag; } string nums_class_1; cout<<"请输入第一级分类号。至少两位字母+至多位数字.如CD111,正确;AB11111错误"<<endl; cin>>nums_class_1; while(nums_class_1.size()>5){ cout<<"请重新输入"<<endl; cin>>nums_class_1; } vector<Book>jie_1; for(Book it:this->tmbook){ string tmp=it.classify.substr(0,5); if(tmp.find(nums_class_1)!=string::npos){ jie_1.push_back(it); cout<<"《"<<it.Book_name<<"》"<<it.IBSN<<" "<<it.writer<<" "<<it.classify<<" num:"<<it.cur_num<<endl; } } cout<<"是否需要进入第二级搜索。"<<endl; cout<<"选项..."<<endl; cout<<"终止程序——【输0】"<<endl; cout<<"继续程序——【非0】"<<endl; cout<<"输入选项..."<<endl; cin>>jd; if(jd=="0"){ system("pause"); system("cls"); goto Flag; } cout<<"进入第二级搜索..."<<endl; string nums_class_2; cout<<"请输入第二级分类号。至少两位字母+至多两位数字.如AB11,正确;A11111错误"<<endl; cin>>nums_class_2; while(nums_class_2.size()>4){ cout<<"请重新输入"<<endl; cin>>nums_class_2; } vector<Book>jie_2; for(Book it:jie_1){ string tmp=it.classify.substr(6,4); if(tmp.find(nums_class_2)!=string::npos){ jie_2.push_back(it); cout<<"《"<<it.Book_name<<"》"<<it.IBSN<<" "<<it.writer<<" "<<it.classify<<" num:"<<it.cur_num<<endl; } } cout<<"是否需要进入第三级搜索。"<<endl; cout<<"选项..."<<endl; cout<<"终止程序——【输0】"<<endl; cout<<"继续程序——【非0】"<<endl; cout<<"输入选项..."<<endl; cin>>jd; if(jd=="0"){ system("pause"); system("cls"); goto Flag; } cout<<"进入第三级搜索..."<<endl; string nums_class_3; cout<<"请输入第三级分类号。至少1位字母+至多两位数字.如A1,正确;A123错误"<<endl; cin>>nums_class_3; while(true){ int size3=nums_class_3.size(); if(size3<=3)break; cout<<"请重新输入"<<endl; cin>>nums_class_3; } vector<Book>jie_3; for(Book it:jie_2){ string tmp=it.classify.substr(11,3); if(tmp.find(nums_class_3)!=string::npos){ jie_3.push_back(it); cout<<"《"<<it.Book_name<<"》"<<it.IBSN<<" "<<it.writer<<" "<<it.classify<<" num:"<<it.cur_num<<endl; } } cout<<"三级搜索完毕。系统自动退出"<<endl; Sleep(500); system("pause"); system("cls"); goto Flag; } else { cout << "输入错误!请重新输入" << endl; system("pause"); system("cls"); goto Flag; } return; } //--------------------------------------------------开始管理员的操作 void Labray:: AdminStart() { FLAGa: SetColorAndBackground(0,7); cout <<" --------------------------------- " << endl; cout <<" HUN图书管理系统——管理员模式 " << endl; cout <<" --------------------------------- " << endl; cout <<" *********管理员功能菜单********** " << endl; cout <<" 用户管理: " << endl; cout <<" 》》1:查看所有用户账号及密码 " << endl; cout <<" 》》2:修改用户账号/密码 " << endl; cout <<" 》》3:初始化用户账号/密码 " << endl; cout <<" 》》4:彻底删除用户 " << endl; cout <<" ------------------------------- " << endl; cout <<" 图书管理: " << endl; cout <<" 》》5:游览全部图书 " << endl; cout <<" 》》6:修改图书信息 " << endl; cout <<" 》》7.增添图书信息 " << endl; cout <<" 》》8.彻底删除图书 " << endl; cout <<" 》》9.搜索图书 " << endl; cout <<" 》》A.查看图书借阅记录 " << endl; cout <<" 》》B.查看图书归还记录 " << endl; cout <<" 》》C.清空图书借阅记录 " << endl; cout <<" 》》D.清空图书归还记录 " << endl; cout <<" 个人类: " << endl; cout <<" 》》E.注销账号 " << endl; cout <<" 》》F.更改密码 " << endl; cout <<" 管理员操作: " << endl; cout <<" 》》G.查看所有管理员信息 " << endl; cout <<" 》》H.添加新的管理员信息 " << endl; cout <<" 》》I.删除现存管理员信息 " << endl; cout <<" ---------------- " << endl; cout <<" 其他: " << endl; cout <<" 》》0.退出系统 " << endl; cout <<"请输入操作选项!... " << endl; SetColorAndBackground(7,0); char select; cin >> select; if (select == '1') { if (this->Users.empty()) { SetColorAndBackground(6,4); cout << "不好意思。系统暂无用户存在!" << endl; SetColorAndBackground(7,0); } else { for (pair<string, User> it : this->Users) { cout << "用户账号:" << it.second.u_account << " 用户密码:" << it.second.u_code << endl; } } system("pause"); system("cls"); goto FLAGa; } else if (select == '2') { cout << "请输入您想更改的账号(用户名)" << endl; string the_u_account; cin >> the_u_account; if (!this->Users.count(the_u_account)) { SetColorAndBackground(6,4); cout << "系统中没有该用户账号" << endl; SetColorAndBackground(7,0); } else { cout << "原密码:" << this->Users[the_u_account].u_code << endl; cout << "请输入修改后的密码!......" << endl; cin >> this->Users[the_u_account].u_code; this->Save_Users(); cout << "修改完成!!!" << endl; } system("pause"); system("cls"); goto FLAGa; } else if (select == '3') { cout << "请输入您想初始化的账号(用户名)" << endl; string the_u_account; cin >> the_u_account; if (!this->Users.count(the_u_account)) { SetColorAndBackground(6,4); cout << "系统中没有该用户账号" << endl; SetColorAndBackground(7,0); } else { SetColorAndBackground(1,0); cout << "原密码: " << this->Users[the_u_account].u_code << endl; cout << "初始化ing......" << endl; this->Users[the_u_account].u_code="123456"; this->Save_Users(); cout << "修改完成!!! " << endl; SetColorAndBackground(7,0); } system("pause"); system("cls"); goto FLAGa; } else if(select=='4'){ cout<<"请输入您要删除的用户账号..."<<endl; string t_u_account; cin>>t_u_account; if(!this->Users.count(t_u_account)){ cout<<"系统无该用户账号,本次操作自动视为取消"<<endl; system("pause"); system("cls"); goto FLAGa; } else{ this->Users.erase(t_u_account); Sleep(500); cout<<"删除成功!"<<endl; system("pause"); system("cls"); goto FLAGa; } } else if(select=='5'){ SetColorAndBackground(2,0); cout<<" ***********************************************图书总览******************************************************\n"; cout<<" -------------------------------------------------------------------------------------------------------------\n"; cout<<" 书名 ISSN/IBSN 作者名 分类号 现有数量 \n"; cout<<" -------------------------------------------------------------------------------------------------------------\n"; for (Book it : this->tmbook) { cout<<"《"<<it.Book_name<<"》"<<" "<<it.IBSN<<" "<<it.writer<<" "<<it.classify<<" num:"<<it.cur_num<<endl; } SetColorAndBackground(7,0); system("pause"); system("cls"); goto FLAGa; } else if (select == '6') { cout << "请输入图书名称" << endl; string Book_name; cin >> Book_name; //auto it = this->myFind_use_name(this->tmbook, Book_name); auto it=find_if(this->tmbook.begin(),this->tmbook.end(),help_find(Book_name)); if (it == this->tmbook.end()) { SetColorAndBackground(6,4); cout << "图书馆暂未存入该图书" << endl; SetColorAndBackground(7,0); } else { cout << "请重新输入图书信息" << endl; cout << "IBSN/ISSN...." << endl; cin >> it->IBSN; cout << "作者..." << endl; cin >> it->writer; cout << "分类号" << endl; cin >> it->classify; cout<<"现有图书数量..."<<endl; cin>>it->cur_num; this->Save_Book(); cout << "图书信息修改完成" << endl; } system("pause"); system("cls"); goto FLAGa; } else if (select == '7') { cout<<"请录入新加图书的信息...."<<endl; string t_name; string t_ISBN; string t_writer; string t_classfiy; int t_cur_num; cout << "图书书名...." << endl; cin >> t_name; auto it = find_if(this->tmbook.begin(),this->tmbook.end(),help_find(t_name)); if(it!=this->tmbook.end()){ SetColorAndBackground(1,6); cout<<"图书馆内已有同名书籍,请选择更改图书信息或者在书名后加注释"<<endl; SetColorAndBackground(7,0); }else{ cout << "ISBN/ISSN码..." << endl; cin >> t_ISBN; cout << "作者/编者/译者..." << endl; cin >> t_writer; cout << "分类号..." << endl; cin>> t_classfiy; cout<< "加入现有数目..."<<endl; cin>>t_cur_num; Book tmp(t_name, t_ISBN, t_writer, t_classfiy,t_cur_num); this->tmbook.emplace_back(tmp); this->Save_Book(); cout << "图书信息保存成功" << endl; } system("pause"); system("cls"); goto FLAGa; } else if (select == '8') { cout << "请输入您要彻底删除的图书名称!" << endl; string t_name; cin >> t_name; vector<Book>::iterator it; for (it = this->tmbook.begin(); it != this->tmbook.end(); it++) if (it->Book_name == t_name)break; if (it == this->tmbook.end()){ SetColorAndBackground(0,4); cout << "未找到该名称的图书,操作自动撤销" << endl; SetColorAndBackground(7,0); } else { this->tmbook.erase(it); this->Save_Book(); cout << "图书删除完毕" << endl; } system("pause"); system("cls"); goto FLAGa; } else if (select == '9') { this->Search_thebook(); system("pause"); system("cls"); goto FLAGa; } else if(select=='A'){ if(this->Borrow_memo.empty())cout<<"暂图书借阅记录!"<<endl; else{ cout<<"图书借阅记录如下..."<<endl; for(auto it:this->Borrow_memo) cout<<it<<endl; } system("pause"); system("cls"); goto FLAGa; } else if(select=='B'){ if(this->Back_memo.empty()){ cout<<"暂无图书归还记录!"<<endl; } else{ cout<<"图书归还记录如下..."<<endl; for(auto it:this->Back_memo) cout<<it<<endl; } system("pause"); system("cls"); goto FLAGa; } else if(select=='C'){ cout<<"确定要清空图书借阅记录吗? "<<endl; cout<<"【非0】确认 【输入0】取消"<<endl; char jd='0'; cin>>jd; Sleep(500); if(jd!='0'){ this->Borrow_memo.clear(); this->Save_Borrow_memo(); cout<<"已完成清空!"<<endl; } Sleep(500); system("pause"); system("cls"); goto FLAGa; } else if(select=='D'){ cout<<"确定要清空图书归还记录吗? "<<endl; cout<<"【非0】确认 【输入0】取消"<<endl; char jd='0'; cin>>jd; Sleep(500); if(jd!='0'){ this->Back_memo.clear(); this->Save_Back_memo(); cout<<"已完成清空!"<<endl; } Sleep(500); system("pause"); system("cls"); goto FLAGa; } else if (select == 'E') { this->Admins.erase(this->Landed_accout); this->Save_Admins(); SetColorAndBackground(1,6); cout << "账号已成功注销.稍后系统自动退出" << endl; SetColorAndBackground(0,7); Sleep(500); exit(0); } else if (select == 'F') { cout << "请输入您更改后的密码" << endl; string new_code; cin >> new_code; this->Admins[this->Landed_accout].a_code = new_code; this->Save_Admins(); cout << "修改成功!" << endl; system("pause"); system("cls"); goto FLAGa; } else if (select == '0') { this->myover(); } else if(select=='G'){ for (pair<string, Administrator> it : this->Admins) { cout << "管理员账号:" << it.second.a_account << " 管理员密码:" << it.second.a_code << endl; } system("pause"); system("cls"); goto FLAGa; } else if(select=='H'){ cout<<"*********请输入您要添加的管理员账号>>>>"<<endl; string t_a_account; cin>>t_a_account; if(this->Admins.count(t_a_account)){ cout<<"已有该账号的管理员,本次操作视为取消"<<endl; system("pause"); system("cls"); goto FLAGa; }else{ cout<<"*********请输入您要添加的管理员的密码>>>>"<<endl; string t_a_code; cin>>t_a_code; Administrator tmp(t_a_account,t_a_code); this->Admins[t_a_account]=tmp; this->Save_Admins(); cout<<"添加成功."<<endl; system("pause"); system("cls"); goto FLAGa; } } else if(select=='I'){ cout<<"*********请输入您要删除的管理员账号>>>>"<<endl; string t_a_account; cin>>t_a_account; if(!this->Admins.count(t_a_account)){ cout<<"不存在该账号的管理员,本次操作视为取消"<<endl; system("pause"); system("cls"); goto FLAGa; }else{ cout<<">>>>>开始删除....>>>>"<<endl; Sleep(500); this->Admins.erase(t_a_account); this->Save_Admins(); system("pause"); system("cls"); goto FLAGa; } } else { SetColorAndBackground(0,6); cout << "选项输入错误,请重新输入" << endl; SetColorAndBackground(0,7); system("pause"); system("cls"); goto FLAGa; } } //--------------------------------开始用户的操作 void Labray::UserStart() { FLAGu:SetColorAndBackground(0,7); cout << " H_图书管理系统——用户模式 " << endl; cout << " ----------------------------- " << endl; cout << " *******用户功能菜单********* " << endl; cout << " ---------------------------------" << endl; cout << " 图书操作: " << endl; cout << " 》》1:游览全部图书 " << endl; cout << " 》》2.借阅图书 " << endl; cout << " 》》3.搜索图书 " << endl; cout << " 》》4.查看自己的图书借阅记录 " << endl; cout << " 》》5.查看自己的图书归还记录 " << endl; cout << " 》》6.部分归还图书 " << endl; cout << " 》》7.一键全部归还 " << endl; cout << " 个人类: " << endl; cout << " 》》8.注销账号 " << endl; cout << " 》》9.更改密码 " << endl; cout << " 其他: " << endl; cout << " 》》0.退出系统 " << endl; cout << " ---------------- " << endl; SetColorAndBackground(7,0); SetColorAndBackground(7,0); cout << "请输入操作选项!... " << endl; char ch; cin >> ch; if (ch == '1') { SetColorAndBackground(2,0); cout<<" ***********************************************图书总览******************************************************\n"; cout<<" -------------------------------------------------------------------------------------------------------------\n"; cout<<" 书名 ISSN/IBSN 作者名 分类号 现有数量 \n"; cout<<" -------------------------------------------------------------------------------------------------------------\n"; for (Book it : this->tmbook) { cout<<"《"<<it.Book_name<<"》"<<" "<<it.IBSN<<" "<<it.writer<<" "<<it.classify<<" num:"<<it.cur_num<<endl; } SetColorAndBackground(7,0); system("pause"); system("cls"); goto FLAGu; } else if (ch == '2') { cout << "您想借阅的图书书名.一人一次最多借一本" << endl; string t_name; cin >> t_name; auto it = find_if(this->tmbook.begin(),this->tmbook.end(),help_find(t_name)); if (it != this->tmbook.end()) { cout<<"图书信息如下,请确认!"<<endl; cout<<"《"<<it->Book_name<<"》"<<" IBSN:"<<it->IBSN<<" 作者:"<<it->writer<<" 分类号:"<<it->classify<<" num:"<<it->cur_num<<endl; Sleep(500); if(it->cur_num==0){ cout<<"抱歉,这本书已经被借走了!"<<endl; system("pause"); system("cls"); goto FLAGu; } char jd='0'; cout<<"请确认借阅..."<<endl; cout<<"|【输0】——放弃借阅|【非0】——确认借阅"<<endl; cout<<"请输入您的选择!"<<endl; cin>>jd; if(jd=='0'){ cout<<"成功取消本次操作!"<<endl; system("pause"); system("cls"); goto FLAGu; } else{ cout << "您已成功借得本书,可在借阅记录中查看" << endl; this->Users[Landed_accout].u_memo[t_name]++; string JL_borrow_memo="用户"+Landed_accout+"于"+this->getCur_time()+"借得图书《"+t_name+"》"; this->Borrow_memo.push_back(JL_borrow_memo); it->cur_num--; this->Save_Book(); this->Save_Borrow_memo(); system("pause"); system("cls"); goto FLAGu; } } else{ SetColorAndBackground(6,4); cout << "-------------------------"<<endl; cout << "抱歉。图书馆暂未收录本书" << endl; cout << "-------------------------"<<endl; SetColorAndBackground(0,7); system("pause"); system("cls"); goto FLAGu; } } else if (ch == '3') { this->Search_thebook(); system("pause"); system("cls"); goto FLAGu; } else if (ch == '4') { if (this->Users[Landed_accout].u_memo.empty()) { cout << "您的借阅空空如也" << endl; } else { cout << "你的借阅记录如下" << endl; for (pair<string,int> it : this->Users[Landed_accout].u_memo) { cout <<"《"<<it.first<<"》" <<" "<<to_string(it.second) << endl; } } system("pause"); system("cls"); goto FLAGu; } else if(ch=='5'){ if(this->Users[Landed_accout].u_back_memo.empty()){ cout<<"您暂无归还记录!!"<<endl; } else{ cout << "你的归还记录如下,欢迎继续借阅" << endl; for (pair<string,int> it : this->Users[Landed_accout].u_back_memo) { cout <<"《"<<it.first<<"》" <<" "<<to_string(it.second) << endl; } } system("pause"); system("cls"); goto FLAGu; } else if (ch == '6'){ if (this->Users[Landed_accout].u_memo.empty()) { cout << "您的借阅还未借得书籍,无需归还" << endl; } else { cout << "你的借阅记录如下,请选择您要归还的书籍名称" << endl; for (pair<string,int> it : this->Users[Landed_accout].u_memo) { cout <<"《"<<it.first<<"》" <<" "<<to_string(it.second) << endl; } cout<<"请输入您要归还的书籍名称..."<<endl; string book_name; cin>>book_name; if(!this->Users[Landed_accout].u_memo.count(book_name)){ cout<<"您尚未借得该图书,本次操作视为取消"<<endl; system("pause"); system("cls"); goto FLAGu; } cout<<"请输入你要归还的书籍数量..."<<endl; int book_num; cin>>book_num; if(this->Users[Landed_accout].u_back_memo[book_name]>book_num){ cout<<"归还数量有误,本次操作视为取消"<<endl; system("pause"); system("cls"); goto FLAGu; } vector<Book>::iterator it =find_if(this->tmbook.begin(),this->tmbook.end(),help_find(book_name)); if(it==this->tmbook.end()){ cout<<"图书馆未存该图书的信息,输入错误,该操作视为自动撤销"<<endl; system("pause"); system("cls"); goto FLAGu; } else{ it->cur_num+=book_num; this->Users[Landed_accout].u_memo[book_name]-=book_num; string JL_back_memo="用户"+Landed_accout+"于"+this->getCur_time()+"归还图书《"+book_name+"》"+to_string(book_num)+"本"; this->Users[Landed_accout].u_back_memo[book_name]+=book_num; this->Back_memo.push_back(JL_back_memo); this->Save_Back_memo(); this->Save_Book(); cout<<"归还完毕!!!"<<endl; } } system("pause"); system("cls"); goto FLAGu; } else if(ch=='7'){ cout<<"开始一键归还..."<<endl; for(auto it: this->Users[Landed_accout].u_memo){ if(it.second>0){ vector<Book>::iterator the_book =find_if(this->tmbook.begin(),this->tmbook.end(),help_find(it.first)); if(the_book!=this->tmbook.end()){ the_book->cur_num+=it.second; string JL_back_memo="用户"+Landed_accout+"于"+this->getCur_time()+"归还图书《"+it.first+"》"+to_string(it.second)+"本"; this->Back_memo.push_back(JL_back_memo); this->Users[Landed_accout].u_back_memo[it.first]+=it.second; } } } this->Users[Landed_accout].u_memo.clear(); Sleep(500); cout<<"一键归还完毕"<<endl; this->Save_Back_memo(); this->Save_Book(); system("pause"); system("cls"); goto FLAGu; } else if (ch == '8') { this->Users.erase(this->Landed_accout); this->Save_Users(); cout << "账号已成功注销.系统自动退出" << endl; exit(0); } else if (ch == '9') { cout << "请输入您更改后的密码" << endl; string new_code; cin >> new_code; this->Users[this->Landed_accout].u_code = new_code; this->Save_Users(); cout << "修改成功!" << endl; system("pause"); system("cls"); goto FLAGu; } else if (ch == '0') { SetColorAndBackground(4,6); cout<<"-----------------------------------------------------"<<endl; cout<<"退出系统需启用一键归还,要持续借书请向管理员线下申请."<<endl; cout<<"-----------------------------------------------------"<<endl; SetColorAndBackground(0,7); cout<<"是否继续。"<<endl; cout<<"【输0】--取消操作|【非0】--继续操作"<<endl; char jd='0'; cin>>jd; Sleep(500); if(jd=='0'){ cout<<"已取消本次操作."<<endl; Sleep(500); system("pause"); system("cls"); goto FLAGu; } else{ cout<<"自动开始一键归还..."<<endl; for(auto it: this->Users[Landed_accout].u_memo){ vector<Book>::iterator the_book =find_if(this->tmbook.begin(),this->tmbook.end(),help_find(it.first)); if(the_book!=this->tmbook.end()){ the_book->cur_num+=it.second; string JL_back_memo="用户"+Landed_accout+"于"+this->getCur_time()+"归还图书《"+it.first+"》"+to_string(it.second)+"本"; this->Back_memo.push_back(JL_back_memo); } } this->Users[Landed_accout].u_memo.clear(); Sleep(500); cout<<"一键归还完毕"<<endl; this->Save_Back_memo(); this->Save_Book(); this->myover(); } } else { cout << "选项输入错误,请重新输入" << endl; system("pause"); system("cls"); goto FLAGu; } }
3️⃣main.cpp
#include "Labray.h" using namespace std; int main() { Labray H_labray; H_labray.Landing(); return 0; }
4️⃣文件总览
【5】效果展示
1️⃣:开始界面
2️⃣:注册界面
3️⃣:管理员功能
4️⃣:用户功能
5️⃣:游览全部图书
6️⃣:搜索图书
7️⃣:借阅与归还图书
借阅:>>>
借阅记录:>>>
归还》》
记录》》》
退出:
8️⃣:管理员借阅/归还记录查看
【6】后记补充
- 1.关于分类号搜索的使用,用字符串截取,做匹配就能简单完成。由于样本给的分类号没有具体标准,所以我自创了一个,用它来对样本处理应该是不合适的。
- 2.我用了很多goto语句,这样可减少循环或者函数调用,对我自己看,是很方便的。【快乐自己,麻烦他人👻,大家还是老老实实用循环或者函数跳转】
- 3.我用了STL,主要是因为,高阶算法编不出我想多多了解一下STL,
- 4.在学习路上,免不了会遇到各种各样的诱惑——
没错,我打游戏去了,发现了一款名叫《饥荒》的游戏,就… - 5.欠下的功课是要慢慢补的~%?…,# *'☆&℃$︿★?,要成为{技术大神},还要更加加油
- 虽然我还会受到各种诱惑勾引
相关文章推荐
- ASP.NET Core 打造一个简单的图书馆管理系统(五)初始化书籍信息
- 关于虚函数的作业中对学校信息管理系统的实现要求和编程要点
- ASP.NET Core 打造一个简单的图书馆管理系统 (修正版)(三)图书信息的增删改查
- 2019 信息与计算科学-C语言大作业之学生信息管理系统
- 图书馆管理系统 C语言链表 详细注释 期末作业
- ASP.NET Core MVC 打造一个简单的图书馆管理系统 (修正版)(七) 学生信息增删
- 我的作品-图书馆信息管理系统
- 图书馆信息管理系统文档
- 2019/1/9 学习linuxC第八天 作业:结构体编写学生信息管理系统(答案外加自己做的)
- 学生信息管理系统-顺序表&&链表(数据结构第一次作业)
- ASP.NET Core 打造一个简单的图书馆管理系统(七)外借/阅览图书信息的增删改查
- ASP.NET Core 打造一个简单的图书馆管理系统(修正版)(四)外借/阅览图书信息的增删改查
- 图书馆信息管理系统(顺序表)
- OC作业- 图书馆管理系统
- 二期 , 第二章 数据库的实现---- 课后作业--- 创建图书馆管理系统数据库
- c++课设作业之课程信息管理系统
- 图书馆信息管理系统
- 数据结构第一次作业(学生信息管理系统-顺序表&&链表)
- 图书馆信息管理系统
- ThinkPHP5作业管理系统中处理学生未交作业与已交作业信息