#include <iostream> #include <string> #include <cstdio> #include <cstdlib> #include <iomanip> using namespace std; struct Library { long number;//编号 string bookname;//书名 string author;//作者 string press;//出版社 int price;//价格 }; Library book[10000000];// int size=0; int count=0; void welcome(); void increase();//添加图书 void find(); void find_1();//查找图书 void find_2(); void find_3(); void find_4(); void find_all();//查找所有图书 void display(int i); int main() { welcome(); return 0; } void welcome() { int n; cout<<"*---------------------------*"<<endl; cout<<"|--------图书管理系统-------|"<<endl; cout<<"|---------------------------|"<<endl; cout<<endl; cout<<"|---------------------------|"<<endl; cout<<"|--------1.添加图书---------|"<<endl; cout<<"|--------2.查找图书---------|"<<endl; cout<<"|--------3.查找所有图书-----|"<<endl; cout<<"|--------4.退出系统---------|"<<endl; cout<<"*---------------------------*"<<endl; cout<<"请输入指令:"; cin>>n; switch(n) { case 1: increase(); cout<<endl; welcome(); break; case 2: find(); welcome(); break; case 3: find_all(); welcome(); break; default: break; } } void increase() { char m,n,y; cout<<"输入图书编号:"; cin>>book[size].number; cout<<"输入书名:"; cin>>book[size].bookname; cout<<"输入作者姓名:"; cin>>book[size].author; cout<<"输入出版社:"; cin>>book[size].press; cout<<"输入价格:"; cin>>book[size].price; cout<<"加入成功!"<<endl; display(size); size++; count+=1; cout<<"是否继续加入图书(是y,否n)"<<endl; cin>>m; if(m=='y') increase(); if(m=='n') welcome(); } void display(int i) { cout<<"+-----------------------------------------------------------------------+"<<endl; cout<<setiosflags(ios::left)<<"+"<<setw(10)<<"图书编号"<<setw(1)<<'|'<<setw(10)<<"书名"<<setw(1)<<'|'<<setw(20)<<"作者"<<setw(1)<<'|'<<setw(15)<<"出版社"<<setw(1)<<'|'<<setw(10)<<"价格"<<setw(1)<<'|'<<endl; cout<<"+-----------------------------------------------------------------------------+"<<endl; cout<<setiosflags(ios::left)<<"+"<<setw(10)<<book[i].number<<setw(1)<<'|'<<setw(10)<<book[i].bookname<<setw(1)<<'|'<<setw(20)<<book[i].author<<setw(1)<<'|' <<setw(15)<<setiosflags(ios::fixed)<<setprecision(2)<<book[i].press<<setw(9)<<setw(1)<<'|'<<setw(10)<<book[i].price<<setw(1)<<'|'<<endl; cout<<"+-----------------------------------------------------------------------+"<<endl; } void find() { int n; cout<<"*---------------------------------*"<<endl; cout<<"|--------1.以图书编号查找---------|"<<endl; cout<<"|--------2.以图书名查找-----------|"<<endl; cout<<"|--------3.以作者名查找-----------|"<<endl; cout<<"|--------4.以出版社查找-----------|"<<endl; cout<<"|--------5.回到主菜单-------------|"<<endl; cout<<"*---------------------------------*"<<endl; cout<<"请输入指令:"; cin>>n; switch(n) { case 1: find_1(); break; case 2: find_2(); break; case 3: find_3(); break; case 4: find_4(); break; default: welcome(); break; } } void find_1() { long num; cout<<"输入要查找的图书编号:"<<endl; cin>>num; bool flag=false; int n; for(n=0; n<=size; n++) { if(num==book[n].number) { flag=true; break; } } if(flag) display(n); else cout<<"没有查询结果。或该书不存在!"<<endl; } void find_2() { string name; cout<<"输入要查找的图书名:"<<endl; cin>>name; bool flag=false; int n; for(n=0; n<=size; n++) { if(name==book[n].bookname) { flag=true; break; } } if(flag) display(n); else cout<<"没有查询结果,或该书不存在。"<<endl; } void find_3() { string zuozhe; cout<<"输入要查找的作者名:"<<endl; cin>>zuozhe; bool flag=false; int n; for(n=0; n<=size; n++) { if(zuozhe==book[n].author) { flag=true; break; } } if(flag) display(n); else cout<<"没有查询结果。或该书不存在!"<<endl; } void find_4() { string chuban; cout<<"输入要查找的出版社名:"<<endl; cin>>chuban; bool flag=false; int n; for(n=0; n<=size; n++) { if(chuban==book[n].press) { flag=true; break; } } if(flag) display(n); else cout<<"没有查询结果,或该书不存在!"<<endl; } void find_all() { for(int n=0; n<size; n++) { display(n); } }
感悟:唉!
!
。!
。。