#include<iostream>
#include<fstream>
#include<map>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
class Goods{ //商品类
protected:
string Id;
string Name;
string Brand;
double BuyingPrice;
double RetailPrice;
int Stock;
int Sales;
public:
Goods(string id,string n,string b,double bp,double rp,int st=0,int sa=0);
void setBPrice(double bp);
void setRPrice(double rp);
string getId();
string getName();
double getBPrice();
double getRPrice();
int getStock();
int getSales();
void setStock(int s);
void setSales(int s);
virtual void showInfo()=0;
};
Goods::Goods(string id,string n,string b,double bp,double rp,int st,int sa)
:Id(id),Name(n),Brand(b),BuyingPrice(bp),RetailPrice(rp),Stock(st),Sales(sa){}
void Goods::setBPrice(double bp){
BuyingPrice=bp;
}
void Goods::setRPrice(double rp){
RetailPrice=rp;
}
string Goods::getId(){
return Id;
}
string Goods::getName(){
return Name;
}
double Goods::getBPrice(){
return BuyingPrice;
}
double Goods::getRPrice(){
return RetailPrice;
}
int Goods::getStock(){
return Stock;
}
int Goods::getSales(){
return Sales;
}
void Goods::setStock(int s){
Stock=s;
}
void Goods::setSales(int s){
Sales=s;
}
class Sparepart:public Goods{ //零配件类
protected:
string Source; //来源 (原厂配件、第三方配件)
char Quality; //品质 (A、B、C三级)
int Guarantee; //保修期 (年)
public:
Sparepart(string id,string n,string b,double bp,double rp,int st,int sa,string sou,char qua,int gua);
virtual void showInfo(); //虚函数
friend ostream& operator<<(ostream& os,Sparepart &s);
};
Sparepart::Sparepart(string id,string n,string b,double bp,double rp,int st,int sa,string sou,char qua,int gua)
:Goods(id,n,b,bp,rp,st,sa),Source(sou),Quality(qua),Guarantee(gua){}
void Sparepart::showInfo(){
cout<<"编号:"<<Id<<"\t";
cout<<"名称:"<<Name<<"\t";
cout<<"品牌:"<<Brand<<endl;
cout<<"进价:¥"<<BuyingPrice<<"\t";
cout<<"售价:¥"<<RetailPrice<<endl;
cout<<"库存:"<<Stock<<"\t";
cout<<"销量:"<<Sales<<endl;
cout<<"来源:"<<Source<<"\t";
cout<<"品质:"<<Quality<<"\t\t";
cout<<"保修:"<<Guarantee<<" 年"<<endl;
}
ostream& operator<<(ostream& os,Sparepart &s){
os<<s.Id<<" "<<s.Name<<" "<<s.Brand<<" "<<s.BuyingPrice<<" "<<s.RetailPrice<<" "
<<s.Stock<<" "<<s.Sales<<" "<<s.Source<<" "<<s.Quality<<" "<<s.Guarantee<<endl;
return os;
}
class Car:public Goods{ //车类
protected:
string Energy; //能源类型 (汽油,电动,天然气,太阳能)
double Speed; //最高时速 km/h
char Safety; //安全性 (A、B、C三级)
public:
Car(string id,string n,string b,double bp,double rp,int st,int sa,string e,double sp,char safe);
virtual void showInfo();
friend ostream& operator<<(ostream& os,Car &c);
};
Car::Car(string id,string n,string b,double bp,double rp,int st,int sa,string e,double sp,char safe)
:Goods(id,n,b,bp,rp,st,sa),Energy(e),Speed(sp),Safety(safe){}
void Car::showInfo(){
cout<<"编号:"<<Id<<"\t\t";
cout<<"名称:"<<Name<<endl;
cout<<"品牌:"<<Brand<<endl;
cout<<"进价:¥"<<BuyingPrice<<"\t\t";
cout<<"售价:¥"<<RetailPrice<<endl;
cout<<"库存:"<<Stock<<"\t\t";
cout<<"销量:"<<Sales<<endl;
cout<<"能源类型:"<<Energy<<"\t";
cout<<"最高时速:"<<Speed<<" km/h"<<endl;
cout<<"安全性:"<<Safety<<endl;
}
ostream& operator<<(ostream& os,Car