Libray

  1 #include <iostream>
  2 #include <fstream>
  3 #include <map>
  4 using namespace std;
  5 struct book{
  6     string name;
  7     float moeny;
  8     string cbs;
  9     string type;
 10 };
 11 void _main(){
 12     //system("cls");
 13     cout<<"Hello,welcome to the library!"<<endl;
 14     cout<<"   What can I do for you?"<<endl;
 15     cout<<"         1.借阅"<<endl;
 16     cout<<"         2.增书"<<endl;
 17     cout<<"         3.查书"<<endl;
 18     cout<<"         4.还书"<<endl;
 19     cout<<"     5.输出所有书"<<endl;
 20     cout<<"         6.关闭"<<endl;
 21 }
 22 void _main3(){
 23     system("cls");
 24     cout<<"Hello,welcome to the library!"<<endl;
 25     cout<<"   What do I do for you?"<<endl;
 26     cout<<"        1.按书号"<<endl;
 27     cout<<"  2.按书名字(模糊查询)"<<endl;
 28     cout<<"   3.按分类(模糊查询)"<<endl;
 29     cout<<"  4.按出版社(模糊查询)"<<endl;
 30 }
 31 int main(int argc, char** argv) {
 32     string data,k;
 33     int bookid=1;
 34     map<int,book> my_main;
 35     map<int,string> my_fl;
 36     map<int,int> my_ren;
 37     book sx;
 38     ifstream file;
 39     file.open("1.txt");
 40     book c;
 41     while(getline(file,data)){
 42         if(data.length()>4){
 43             c.name = data.substr(0,data.find("|"));
 44             data = data.substr(data.find("|")+1);
 45             c.moeny=stof(data.substr(0,data.find("|")));
 46             data = data.substr(data.find("|")+1);
 47             c.cbs = data.substr(0,data.find("|"));
 48             data = data.substr(data.find("|")+1);
 49             c.type =data.substr(0,data.find("|"));
 50             my_fl.insert(pair<int,string>(bookid,data.substr(0,data.find("|"))));
 51             my_main.insert(pair<int,book>(bookid,c));
 52             data = data.substr(data.find("|")+1);
 53             my_ren.insert(pair<int,int>(bookid,stoi(data.substr(0,data.find("|")))));
 54         }
 55         if(file.eof()){
 56             break;
 57         }
 58         bookid++;
 59     }
 60     file.close();
 61     int i;
 62     int ls;
 63     while(1){
 64         _main();
 65         cin>>i;
 66         switch(i){
 67             case 1:{
 68                 cout<<"未开发此应用,请敬请期待.....";
 69                 system("pause");
 70                 break;
 71             }
 72             case 2:{
 73                 cout<<"未开发此应用,请敬请期待.....";
 74                 system("pause");
 75                 break;
 76             }
 77             case 3:{
 78                 _main3();
 79 //                cin>>ls;
 80 //                switch(ls){
 81 //                    
 82 //                }
 83                 system("pause");
 84                 break;
 85             }
 86             case 4:{
 87                 cout<<"未开发此应用,请敬请期待.....";
 88                 system("pause");
 89                 break;
 90             }
 91             case 5:{
 92                 cout<<"编号   书名  价格  出版社   类别"<<endl;
 93                 for(int j=1;j<=bookid;j++){
 94                     cout<<j<<" "<<my_main[j].name<<" "<<my_main[j].moeny<<" "<<my_main[j].cbs<<" "<<my_main[j].type<<endl;
 95                     
 96                 }
 97                 system("pause");
 98                 break;
 99             }
100             case 6:{
101                 return 0;
102                 break;
103             }
104             system("pause");
105         }
106     }
107     return 0;
108 }

文本:

王者农药攻略|1145.14|青华大学出版社|學习类|10000000|
和平鸡鸡攻略|541.88|季基大学出版社|助學类|10000000|
母牛屎界攻略|145.24|哈佛大学出版社|劝退类|0|

posted @ 2024-03-16 09:59  -刘-j-x-  阅读(44)  评论(0)    收藏  举报