-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNormalcommodity.cpp
36 lines (29 loc) · 1.03 KB
/
Normalcommodity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include "normalcommodity.h"
using namespace std;
#include <sstream>
int NormalCommodity::getType()const{
return 0; //0 表示普通商品
}
string NormalCommodity::getInfo()const{
ostringstream ostr;
ostr<<getType()<<" "; //先输出类型编码
ostr<<Commodity::getInfo(); //输出基类的信息
ostr<<discount<<endl; //输出子类信息
return ostr.str();
}
NormalCommodity::NormalCommodity(long id,std::string name,
double p,int n,double d)
:Commodity(id,name,p,n),discount(d){}
NormalCommodity::NormalCommodity(std::string name,double p,
int n,double d)
:Commodity(name,p,n),discount(d){}
double NormalCommodity::getNetPrice()const{
return Commodity::getNetPrice()*discount;
}
void NormalCommodity::output()const{
Commodity::output();
cout<<" 商品总价:"<<getNetPrice()<<" (价格:"
<<getPrice()<<", 数量:"<<getNum()<<", 折扣:"
<<discount<<" )\n";
}