-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.h
62 lines (47 loc) · 1.4 KB
/
Book.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
52
53
54
55
56
57
58
59
60
61
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Book.h
* Author: sam
*
* Created on April 20, 2020, 1:45 PM
*/
#ifndef BOOK_H
#define BOOK_H
#include <string>
#include "BookCategory.h"
#include <set>
#include <map>
#include <memory>
class Book {
public:
Book();
Book(std::string title) :
title(title){
}
Book(std::string title, std::map<shared_ptr<BookCategory>,double> categories) :
title(title), categoryRates(categories) {
}
void addCategories(const std::shared_ptr<BookCategory> & bookCategory, const double rate);
Book(const Book& orig);
virtual ~Book();
std::string const & getTitle() const;
std::map<shared_ptr<BookCategory>,double> const & getCategoryRates() const;
friend std::ostream& operator<<(std::ostream& os, const Book& obj) {
os << obj.title << endl;
for(const auto& cat : obj.categoryRates){
os << *cat.first << " " << cat.second <<endl;
}
return os;
}
bool operator<(const Book& right) const {
return right.getTitle() > this->getTitle(); // Reuse greater than operator
}
private:
std::map<shared_ptr<BookCategory>,double> categoryRates;
std::string title;
};
#endif /* BOOK_H */