-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ex15_07_Limit_quote.h
40 lines (29 loc) · 1.05 KB
/
ex15_07_Limit_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
/*
=================================================================================
C++ Primer 5th Exercise Answer Source Code
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer
Limit_quote class
If you have questions, try to connect with me: pezy<urbancpz@gmail.com>
=================================================================================
*/
#ifndef CP5_EX15_07_LIMIT_QUOTE_H_
#define CP5_EX15_07_LIMIT_QUOTE_H_
#include "ex15_05_Bulk_quote.h"
#include <string>
namespace EX07 {
using namespace EX05;
using std::string;
class Limit_quote : public Bulk_quote {
public:
Limit_quote() = default;
Limit_quote(string const& book, double p, size_t min, size_t max, double dist) : Bulk_quote(book, p, min, dist), max_qty(max) {}
double net_price(size_t cnt) const override {
if (cnt > max_qty) return max_qty * (1 - discount) * price + (cnt - max_qty) * price;
else if (cnt >= min_qty) return cnt * (1 - discount) * price;
else return cnt * price;
}
private:
size_t max_qty = 0;
};
}
#endif // LIMIT_QUOTE_H_