-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo28.cpp
79 lines (66 loc) · 1.3 KB
/
demo28.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>
using namespace std;
class Animal
{
};
class Dog: public Animal
{
};
class Cat: public Animal
{
};
class Item_base
{
public:
int x;
Item_base(int _x, const string _isbn, double _price): x(_x),isbn(_isbn),price(_price) {}
string book() const
{ return isbn; }
virtual double net_price() const
{ return x * price; }
private:
string isbn;
protected:
double price;
};
class Bulk_item : public Item_base
{
public:
Bulk_item(const int _x,const string _isbn, const double _price, const size_t _min_qty, const double _discount)
:Item_base(_x, _isbn, _price),min_qty(_min_qty),discount(_discount) {}
void test()
{
cout << x << endl;
cout << price << endl;
}
void test2(const Bulk_item& bi, const Item_base& ib)
{
cout << bi.x << endl;
cout << bi.price << endl;
cout << ib.x << endl;
// cout << ib.price << endl;
}
double net_price() const
{
if(x >= min_qty)
return x * discount * price;
else
return x * price;
}
private:
size_t min_qty;
double discount;
};
int main()
{
Animal a;
Dog d;
Cat c;
Item_base item(10,"X-0123-456-7",9.9);
cout << item.book() << "\t" << item.net_price() << endl;
Bulk_item item2(10, "X-0123-456-7", 9.9, 10, 0.8);
// item2.test2(item2, item);
cout << item2.book() << '\t' << item2.net_price() << endl;
return 0;
}