-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer15_11_Limit_quote.h
33 lines (33 loc) · 1.06 KB
/
Exer15_11_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
#ifndef LIMIT_QUOTE_H
#define LIMIT_QUOTE_H
#include <cstddef>
#include "Exer15_11_Quote.h"
class Limit_quote : public Quote {
public:
Limit_quote() = default;
Limit_quote(const std::string&, double, std::size_t, double);
// overrides the base version in order to implement the bulk purchase discount policy
double net_price(std::size_t) const override;
void debug() const override;
private:
std::size_t max_qty = 0; // maximum purchase for the discount to apply
double discount = 0.0; // fraction discount to apply
};
inline Limit_quote::Limit_quote(const std::string &book, double p, std::size_t qty, double disc) :
Quote(book, p), max_qty(qty), discount(disc) {}
double Limit_quote::net_price(std::size_t cnt) const
{
if(cnt <= max_qty)
return cnt * (1 - discount) * price;
else
return cnt * price;
}
inline void Limit_quote::debug() const
{
std::cout << "std::string bookNo\n"
<< "double price\n"
<< "std::size_t max_qty\n"
<< "double discount\n"
<< std::endl;
}
#endif