forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex15_03_Quote.h
48 lines (34 loc) · 1.1 KB
/
ex15_03_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
/*
=================================================================================
C++ Primer 5th Exercise Answer Source Code
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer
Quote class and print_total function
If you have questions, try to connect with me: pezy<[email protected]>
=================================================================================
*/
#ifndef CP5_EX15_03_QUOTE_H_
#define CP5_EX15_03_QUOTE_H_
#include <string>
#include <iostream>
inline namespace EX03 {
using std::string;
using std::ostream; using std::endl;
class Quote {
public:
Quote() = default;
Quote(string const& b, double p) : bookNo(b), price(p) { }
string isbn() const { return bookNo; }
virtual double net_price(size_t n) const { return n * price; }
virtual ~Quote() = default;
private:
string bookNo;
protected:
double price = 0.0;
};
double print_total(ostream& os, Quote const& item, size_t n) {
double ret = item.net_price(n);
os << "ISBN: " << item.isbn() << " # sold: " << n << " total due: " << ret << endl;
return ret;
}
}
#endif // CP5_EX15_03_QUOTE_H_