-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer15_30_Bulk_quote.h
51 lines (51 loc) · 1.64 KB
/
Exer15_30_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
46
47
48
49
50
51
#ifndef BULK_QUOTE_H
#define BULK_QUOTE_H
#include <cstddef>
#include <iostream>
#include <string>
#include "Exer15_30_Disc_quote.h"
class Bulk_quote : public Disc_quote { // Bulk_quote inherits from Quote
public:
// inherited constructor
using Disc_quote::Disc_quote;
Bulk_quote()=default;
// 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;
// copy-control members
Bulk_quote(const Bulk_quote &bq) : Disc_quote(bq) {}
Bulk_quote(Bulk_quote &&bq) noexcept : Disc_quote(std::move(bq)) {}
Bulk_quote& operator=(const Bulk_quote&);
Bulk_quote& operator=(Bulk_quote&&) noexcept;
~Bulk_quote()=default; // virtual by inheritance
virtual Bulk_quote* clone() const & { return new Bulk_quote(*this); }
virtual Bulk_quote* clone() && { return new Bulk_quote(std::move(*this)); }
};
// if the specified number of items are purchased, use the discounted price
double Bulk_quote::net_price(std::size_t cnt) const
{
if (cnt >= quantity)
return cnt * (1 - discount) * price;
else
return cnt * price;
}
inline void Bulk_quote::debug() const
{
std::cout << "std::string bookNo\n"
<< "double price\n"
<< "std::size_t min_qty\n"
<< "double discount\n"
<< std::endl;
}
inline Bulk_quote& Bulk_quote::operator=(const Bulk_quote &rhs)
{
Disc_quote::operator=(rhs);
return *this;
}
inline Bulk_quote& Bulk_quote::operator=(Bulk_quote &&rhs) noexcept
{
if(this != &rhs)
Disc_quote::operator=(std::move(rhs));
return *this;
}
#endif