//图书订购系统#include<iostream>#include<string>using namespace std;#include"buy.h"#include"book.h"const int x=20;class order{public:order();void setbuyid(int b_id);void buy_one_book(string b_id);void display();private:static int ordercount;int orderID;int buyerID;int listcount;string orderlist[20];};order::order(){buyerID=0;ordercount++;orderID=ordercount;listcount=0;}void order::setbuyid(int b_id){buyerID=b_id;}void order::buy_one_book(string b_id){orderlist[listcount]=b_id;listcount++;}void order::display(){cout<<"\n订单信息\n\n"<<"订单号:"<<orderID<<endl<<"购书人编号:"<<buyerID<<endl<<"购买图书编号:"<<endl;for(int i=0;i<listcount;i++)cout<<"\t"<<orderlist[i]<<endl;cout<<endl;}int order::ordercount=0;int main(){int buyerid,flag,j=0;book* c[2];common b1("黄潮州",1,"宁都",0);vip b2("肖心远",2,"南昌",0.6,0);member b3("谢小汶",3,"于都",5,0);order ol[20];buyer* b[3]={&b1,&b2,&b3};book c1("C1","C++ programe","谭浩强","清华",35);book c2("C2","data structure","徐天风","北大",20);c[0]=&c1;c[1]=&c2;cout<<"购书人信息:\n\n";for(int i=0;i<2;i++)b[i]->display();cout<<"\n图书信息:\n\n";for(i=0;i<3;i++)c[i]->display();while(j<2){cout<<"\n\n"<<"请输入购书编号:";cin>>buyerid;flag=0;for(i=0;i<3;i++)if(b[i]->getid()==buyerid){flag=1;break;}if(!flag)cout<<"编号不存在!"<<endl;else{b[i]->setpay(c[0]->getprice());b[i]->setpay(c[1]->getprice());cout<<endl<<"购书人需要付费:"<<b[i]->getpay()<<"\n\n";ol[j].setbuyid(b[i]->getid());ol[j].buy_one_book(c[0]->getbook_ID());ol[j].buy_one_book(c[1]->getbook_ID());ol[j].display();j++;}}return 0;}//book.hclass book{protected:string book_ID;string book_name;string author;string publish;double price;public:book();book(string b_id,string b_n,string au,string pu,double pr);void display();string getbook_ID();string getbook_name();string getauthor();string getpublish();double getprice();};book::book(string b_id,string b_n,string au,string pu,double pr){ book_ID=b_id;book_name=b_n;author=au;publish=pu;price=pr;}book::book(){book_ID="";book_name="";author="";publish="";price=0;}void book::display(){cout<<"书名:"<<book_name<<endl<<"书号:"<<book_ID<<endl<<"作者:"<<author<<endl<<"出版社:"<<publish<<endl<<"定价:"<<price<<endl;}string book::getbook_ID(){return book_ID;}string book::getbook_name(){return book_name;}string book::getauthor(){return author;}string book::getpublish(){return publish;}double book::getprice(){return price;}//buy.hclass buyer{protected:string name;int buyerID;string addr;double pay;public:buyer();buyer(string n,int b,string a,double p);string getbuyername();string getaddr();double getpay();int getid();virtual void display();virtual void setpay(double=0)=0;};class member:public buyer{int leaguer_grade;public:member(string n,int b,string a,double p,int l):buyer(n,b,a,p){ leaguer_grade=l;}void display();void setpay(double p);};class vip:public buyer{double discount_rate;public:vip(string n,int b,string a,double p,double d):buyer(n,b,a,p){ discount_rate=d;}void display();void setpay(double p);};class common:public buyer{public:common(string n,int b,string a,double p):buyer(n,b,a,p){}void display();void setpay(double p);};buyer::buyer(string n,int b,string a,double p){name=n;buyerID=b;addr=a;pay=p;}double buyer::getpay(){return pay;}string buyer::getaddr(){return addr;}string buyer::getbuyername(){return name;}int buyer::getid(){return buyerID;}void member::display(){cout<<"购书人姓名:"<<name<<"\t"<<"购书人编号:"<<buyerID<<"\t"<<"购书人会员级别:"<<leaguer_grade<<"\n"<<"地址:"<<addr<<"\n\n";}void member::setpay(double p){if(leaguer_grade==1)pay=0.95*p+pay;else if(leaguer_grade==2)pay=0.90*p+pay;else if(leaguer_grade==3)pay=0.85*p+pay;else if(leaguer_grade==4)pay=0.8*p+pay;else if(leaguer_grade==5)pay=0.75*p+pay;elsecout<<"级别错误"<<endl;}void vip::display(){cout<<"购书人姓名:"<<name<<"\t"<<"购书人编号:"<<buyerID<<"\t"<<"VIP折扣率:"<<discount_rate*100<<"%\n"<<"地址:"<<addr<<"\n\n";}void vip::setpay(double p){//pay=pay+pay(1-discount_rate)*p;}void common::display(){cout<<"购书人姓名:"<<name<<"\t"<<"购书人编号:"<<buyerID<<"\t"<<"购书人为普通人!"<<"\n"<<"地址:"<<addr<<"\n\n";}void common::setpay(double p){//pay=pay+p;}。