图书管理系统
#include <iostream> #include <fstream> #include <map> using namespace std; struct book{ string type1; string bookname; float money; int zt = 1; string cbs; int id; }Book; struct books{ string type; string bookname1[1000]; map<string,book> a1; }Books; void MIAN(){ cout<<"欢迎使用图书管理系统"<<endl <<"***1.输出所有图书***"<<endl <<"***2.输出可借图书***"<<endl <<"***3.添加新的图书***"<<endl <<"***4.删除指定图书***"<<endl <<"***5.查找图书信息***"<<endl <<"***6.借阅指定图书***"<<endl <<"***7.归还指定图书***"<<endl <<"***8.关闭管理系统***"<<endl; } void _MIAN(){ cout<<"请选择您的查询方式"<<endl <<"**1.按照书名查询**"<<endl <<"**2.按照类型查询**"<<endl; } int main(){ map<string,books> a; int I,number = 0; ifstream file; file.open("1.txt"); string data; while(getline(file,data)){ Books.type = data.substr(0,data.find("|")); data = data.substr(data.find("|")+1); Book.bookname = data.substr(0,data.find("|")); data = data.substr(data.find("|")+1); Book.money = stof(data.substr(0,data.find("|"))); data = data.substr(data.find("|")+1); Book.cbs = data.substr(0,data.find("|")); Book.type1 = Books.type; Books.bookname1[number+1] = Book.bookname; Book.id = ++number; Books.a1[Book.bookname] = Book; a[Books.type] = Books; } while(1){ MIAN(); cin>>I; string _name; switch(I){ case 1:{ for(int i = 1;i<=number;i++){ string name = Books.a1[Books.bookname1[i]].bookname; string _type = Books.a1[name].type1; cout<<_type<<":" <<a[_type].a1[name].bookname<<"|" <<a[_type].a1[name].money<<"|" <<a[_type].a1[name].cbs<<endl; } break; } case 2:{ for(int i = 1;i<=number;i++){ string name = Books.a1[Books.bookname1[i]].bookname; string _type = Books.a1[name].type1; if(Books.a1[name].zt){ cout<<_type<<":" <<a[_type].a1[name].bookname<<"|" <<a[_type].a1[name].money<<"|" <<a[_type].a1[name].cbs<<endl; } } break; } case 6:{ cout<<"输入您要借阅的图书:"; cin>>_name; if(Books.a1[_name].zt){ cout<<"您已成功借阅!!!"<<endl; } break; } case 8:{ cout<<"欢迎下次使用!"<<endl; return 0; } } ofstream outfile; outfile.open("1.txt"); for(int i = 1;i<=number;i++){ string name = Books.a1[Books.bookname1[i]].bookname; string _type = Books.a1[name].type1; outfile<<_type<<"|" <<a[_type].a1[name].bookname<<"|" <<a[_type].a1[name].money<<"|" <<a[_type].a1[name].cbs<<"\n"; } cout<<endl; system("pause"); system("cls"); } return 0; } /* 人文|语文|5.8|人民出版社 人文|历史|6.8|历史出版社 数理|数学|7.8|江苏出版社 数理|物理|8.8|南京出版社 */
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】