forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex15_11_Bulk_quote.h
45 lines (33 loc) · 1.12 KB
/
ex15_11_Bulk_quote.h
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
/*
=================================================================================
C++ Primer 5th Exercise Answer Source Code
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer
Bulk_quote class
added debug() function
If you have questions, try to connect with me: pezy<[email protected]>
=================================================================================
*/
#ifndef CP5_EX15_11_BULK_QUOTE_H_
#define CP5_EX15_11_BULK_QUOTE_H_
#include "ex15_11_Quote.h"
#include <string>
namespace EX11 {
using std::string;
class Bulk_quote : public Quote {
public:
Bulk_quote() = default;
Bulk_quote(string const& book, double p, size_t qty, double disc) : Quote(book, p), min_qty(qty), discount(disc) {}
virtual double net_price(size_t cnt) const override {
if (cnt >= min_qty) return cnt * (1 - discount) * price;
else return cnt * price;
}
virtual void debug() const override {
Quote::debug();
cout << "\tminqty: " << min_qty << "\tdiscount: " << discount << endl;
}
protected:
size_t min_qty = 0;
double discount = 0.0;
};
}
#endif // CP5_EX15_11_BULK_QUOTE_H_