圖書系統

fushuxuan1發表於2024-03-17
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
struct book{
    string name;
    float money;
    string cbs;
    string writer;
    int kc;
    string type;
    int id;
};
int main(){
    while(1){
    	system("cls");
        cout<<"****圖書管理****"<<endl;
        cout<<"1.書名"<<endl<<"2.型別"<<endl<<"3.借書"<<endl<<"4.退出系統"<<endl;
        map<string,book> books;
        map<string,string> types;
        map<string,string> logs;
        int startid=1000;
    	int number=0;
    	book x[100];
        book b;
        string data,name_,cbs_,writer_,type_;
        int money_,kc_;
        ifstream a;
        a.open("book.txt");
        while(getline(a,data)){
            if(data.length()>5){
                int length=data.find("|");
                name_=data.substr(0,length);
                data=data.substr(length+1);
                length=data.find("|");
                cbs_=data.substr(0,length);
                data=data.substr(length+1);
                length=data.find("|");
                money_=stoi(data.substr(0,length));
                data=data.substr(length+1);
                length=data.find("|");
                writer_=data.substr(0,length);
                data=data.substr(length+1);
                length=data.find("|");
                kc_=stoi(data.substr(0,length));
                data=data.substr(length+1);
                length=data.find("|");
                type_=data.substr(0,length);
                x[number].name=name_;
                x[number].cbs=cbs_;
                x[number].money=money_;
                x[number].writer=writer_;
                x[number].kc=kc_;
                x[number].type=type_;
                number++;
            }
            if(a.eof()){
                cout<<"end"<<endl;
                break;   
            }
        }
        a.close();
//        books.insert(pair<string,book>("駱駝祥子",b));
//        books.insert(pair<string,book>("朝花夕拾",b));
//        books.insert(pair<string,book>("昆蟲記",b));
        int n;
        cin>>n; 
        string name,_type;
        if(n==4){
            system("cls");
            break;
        }
        switch(n){
            case 1:
            	system("cls");
                cout<<"請輸入書名"<<endl;
                cin>>name;
                for(int i=0;i<=number;i++){
                    if(name==x[i].name){
                    	cout<<"資訊如下"<<endl;
                        cout<<"書名:"<<x[i].name<<endl;
                        cout<<"出版社:"<<x[i].cbs<<endl;
                        cout<<"價格:"<<x[i].money<<endl;
                        cout<<"作者:"<<x[i].writer<<endl;
                        cout<<"剩餘本數:"<<x[i].kc<<endl;
                        cout<<"型別:"<<x[i].type<<endl;
                        cout<<"_________________________"<<endl;  
                    }
            	}
                Sleep(5000);
				break;
           	case 2:
			   	system("cls");
                cout<<"請輸入型別"<<endl;
                cin>>_type;
                cout<<"此型別書籍如下:"<<endl;
				for(int i=0;i<=number;i++){
                    if(x[i].type==_type){
                    	cout<<x[i].name<<endl;
					}
            	}
            	Sleep(5000);
				break;
			case 3:
				system("cls");
                cout<<"請輸入你想借的書名"<<endl;
                cin>>name;
				for(int i=0;i<=number;i++){
                    if(x[i].kc==0){
                    	cout<<"此書已經被借走"<<endl;
					}
            	}
            	Sleep(5000);
				break;				    
    	}
    }
    return 0;
}

  

相關文章