#include <iostream> #include <cstdio> #include <cstdlib> #include <iomanip> #include <string> #include<stdio.h> using namespace std; void display(int);//输出信息 int size=0; class Book { public: void welcome();//欢迎界面 void welcome1(); void addbook();//1.增加图书 void findbook(); void findbookbyNo();//2.查找图书 void findbookbyName();//2.查找图书 void findbookbyBName();//2.查找图书 void findbookbyAddress();//2.查找图书 //void findall();//3.查找全部 double setNo() { return No; } string setaccName() { return accName; } string setbookName() { return bookName; } string setaddress() { return address; } double setprice() { return price; } private: int No; string accName; string bookName; string address; double price; }; Book book[10000]; int main() { Book b; b.welcome();//欢迎界面 return 0; } void Book::welcome() { int order; cout<<"欢迎使用图书馆管理系统"<<endl; cout<<"|--------------------------------------------|"<<endl; cout<<"| |"<<endl; cout<<"|----- 图书管理系统 ------|"<<endl; cout<<"| |"<<endl; cout<<"|--------------------------------------------|"<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<"|--------------------------------------------|"<<endl; cout<<"|---------------1.增加图书-------------------|"<<endl; cout<<"|---------------2.查找图书-------------------|"<<endl; cout<<"|---------------3.查找全部-------------------|"<<endl; cout<<"|---------------0.退出系统-------------------|"<<endl; cout<<"|--------------------------------------------|"<<endl; cout<<"请选择业务:"; cin>>order; switch(order) { case 0: exit (0); break; case 1: Book::addbook(); break; case 2: Book: findbook(); break; /*case 3: findall(); break;*/ } } void display(int i)//输出信息 { cout<<"_____________________________________________________________________"<<endl; cout<<setiosflags(ios::left)<<setw(12)<<"图书编号"<<setw(20)<<"图书名称"<<setw(12)<<"作者"<<setw(20)<<"出版社"<<setw(20)<<"价格"<<endl; cout<<setiosflags(ios::left)<<setw(12)<<book[i].setNo()<<setw(20)<<book[i].setbookName()<<setw(12)<<book[i].setaccName()<<setw(20)<<book[i].setaddress()<<setw(20)<<book[i].setprice()<<endl; cout<<"_____________________________________________________________________"<<endl; } void Book::addbook() { char c; cout<<"图书编号:"; cin>>book[size].No; cout<<"图书名称:"; cin>>book[size].bookName; cout<<"作者:"; cin>>book[size].accName; cout<<"出版社:"; cin>>book[size].address; cout<<"价格:"; cin>>book[size].price; cout<<"添加图书成功。"<<endl; display(size); size++; cout<<"是否继续添加图书?是(y)否(n)"<<endl; cin>>c; if(c=='y') Book::addbook(); if(c=='n') Book::welcome(); } void Book::findbook() { int order,c; cout<<"|------------------------------------------------|"<<endl; cout<<"|---------------1.根据图书编号-------------------|"<<endl; cout<<"|---------------2.根据图书名称-------------------|"<<endl; cout<<"|---------------3.根 据 作 者-------------------|"<<endl; cout<<"|---------------4.根 据出版 社-------------------|"<<endl; cout<<"|---------------5.返 回主菜 单-------------------|"<<endl; cout<<"|------------------------------------------------|"<<endl; cout<<"请选择业务:"; cin>>order; switch(order) { case 1: cout<<"请输入图书编号:"<<endl; Book::findbookbyNo();//2.查找图书 fflush(stdin); getchar(); Book::findbook(); break; case 2: cout<<"请输入图书名称:"<<endl; Book::findbookbyBName(); fflush(stdin); getchar(); Book::findbook(); break; case 3: cout<<"请输入作者姓名:"<<endl; Book::findbookbyName();//2.查找图书 fflush(stdin); getchar(); Book::findbook(); break; case 4: cout<<"请输入出版社:"<<endl; Book::findbookbyAddress();//2.查找图书 fflush(stdin); getchar(); Book::findbook(); break; case 5: Book::welcome(); break; } } void Book::findbookbyNo() { int No; cin>>No; bool flag=false; int n; for(n=0; n<=size; n++) if(No==book[n].No) { flag=true; break; } if(flag) display(n); else cout<<"查无此书!"<<endl; } void Book::findbookbyBName() { string bname; cin>>bname; bool flag=false; int n; for(n=0; n<=size; n++) if(bname==book[n].bookName) { flag=true; break; } if(flag) display(n); else cout<<"查无此书!"<<endl; } void Book::findbookbyName() { string name; cin>>name; bool flag=false; int n; for(n=0; n<=size; n++) if(name==book[n].accName) { flag=true; break; } if(flag) display(n); else cout<<"查无此书"<<endl; } void Book::findbookbyAddress() { string address; cin>>address; bool flag; int n; for(n=0; n<=size; n++) if(address==book[n].address) { flag=true; break; } if(flag) display(n); else cout<<"查无此书"<<endl; } //void findall() //{ // //}
成果展示:
心得体会:library,图书管理系统!有意义,从开始的四十多个错误一点点改到没有错。不容易啊......
唯一不足的是不理解菜单的选项3 ,什么叫查找全部?该功能并未实现...一大遗憾,请教一下- -...
原文地址:http://blog.csdn.net/u012370431/article/details/26728341