图书管理系统

#include<map>
#include<windows.h>
#include<fstream>
#include<iostream>
using namespace std;
int i=0,j=0,change;
struct book{
    string name;
    string zhu;
    string clas;
    string cbs;
    string money;
    int num;
    int bianhao;
    int jie;
};
map<int,book> a;
book b[100];
void jm(){
	cout<<"图书管理系统:"<<endl;
	cout<<"1.修改图书信息"<<endl;
	cout<<"2.输出可借图书信息"<<endl;
	cout<<"3.查询图书信息"<<endl;
	cout<<"4.退出"<<endl;
}
//void one(){
//	cout<<"你要修改哪个类别(1.人文 , 2.数理)"<<endl;
//    cin>>change;
//    case 1:
//    	
//    	break;
//    case 2:
//    	cout<<"你要修改哪个属性(1.名称,2.作者,3.类别,4.出版社,5.售价,6.数量)"<<endl;
//    	break;
//}
void two(){
	j=0;
	system("cls");
	for(j=0;j<i;j++){
		if(a[j].jie==1){
			cout<<a[j].name<<" ";
			cout<<a[j].zhu<<" ";
			cout<<a[j].clas<<" ";
			cout<<a[j].cbs<<" ";
			cout<<a[j].money<<" ";
			cout<<a[j].num<<" ";
			cout<<a[j].bianhao<<" "<<endl;
		}
	}
	system("pause");
}
void three(){
	system("cls");
	while(1){
		cout<<"请输入:"<<endl;
		cout<<"1.你要查找书的编号"<<endl;
//    	cout<<"2.你要查找书的名称"<<endl;
		cout<<"2.退出"<<endl;
		cin>>change;
		if(change==2){
			break;
		}else{
			cout<<"编号:";
			cin>>change;
			cout<<a[change].name<<" ";
			cout<<a[change].zhu<<" ";
			cout<<a[change].clas<<" ";
			cout<<a[change].cbs<<" ";
			cout<<a[change].money<<" ";
			cout<<a[change].num<<" ";
			cout<<a[change].bianhao<<" ";
			cout<<a[change].jie<<" "<<endl;
			cout<<"----------------"<<endl;
		}
	}
}
int main(){
    string d[100];
    ifstream c;
    c.open("1.txt");
    while(getline(c,d[i])){
        i++;
    }
    c.close();
    while(j<i){
        if(d[j].length()>=3){
            b[j].name=d[j].substr(0,d[j].find("|"));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].zhu=d[j].substr(0,d[j].find("|"));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].clas=d[j].substr(0,d[j].find("|"));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].cbs=d[j].substr(0,d[j].find("|"));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].money=d[j].substr(0,d[j].find("|"));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].num=stoi(d[j].substr(0,d[j].find("|")));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].bianhao=stoi(d[j].substr(0,d[j].find("|")));
            d[j]=d[j].substr(d[j].find("|")+1);
            b[j].jie=stoi(d[j].substr(0,d[j].find("|")));
        }
        j++;
    }
    j=0;
    while(j<i){
    	a.insert(pair<int,book>(j,b[j]));
    	j++;
	}
    while(1){
    	system("cls");
    	jm();
    	cin>>change;
    	switch(change){
    		case 1:
//    			one();
    			break;
    		case 2:
    			two();
    			break;
    		case 3:
    			three();
    			break;
    		case 4:
    			return 0;
		}
	}
//    ofstream e;
//	b.name="数学";
//	b.zhu="哈哈";
//	b.clas="人文";
//	b.cbs="人民大学出版社";
//	b.money="9.9";
//	b.num=1;
//    e.open("1.txt",ios::app);
//    e<<b.name<<"|"<<b.zhu<<"|"<<b.clas<<"|"<<b.cbs<<"|"<<b.money<<"|"<<b.num<<endl;
//    e.close();
    return 0;
}

  

posted @ 2024-03-16 10:00  陈若麟  阅读(16)  评论(0编辑  收藏  举报