-
Notifications
You must be signed in to change notification settings - Fork 0
/
book.cpp
executable file
·65 lines (37 loc) · 1.43 KB
/
book.cpp
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
62
#include <iomanip>
#include <sstream>
#include "book.h"
#include "util.h"
using namespace std;
Book::Book(const string category, const string name, const string isbn, const string author, double price, int qty) : Product (category, name, price, qty)
/*
Inherits data members from Product class via initialization list because those data members are initialized first when Product constructor is called
*/
{
isbn_ = isbn;
author_ = author;
}
/**
* default implementation...can be overriden in a future
* assignment
*/
set<string> Book::keywords() const {
set<string> title = parseStringToWords(name_);
set<string> writer = parseStringToWords(author_);
set<string> search_terms = setUnion(title, writer); //Returns a combined set of both the book title and author to be used as keywords
search_terms.insert(isbn_); //ISBN is given in product_parser.cpp so can be used verbatim
return search_terms;
}
string Book::displayString() const {
stringstream ss;
ss << price_;
string cost = ss.str(); //Converts double to string
stringstream ss2;
ss2 << qty_;
string quantity = ss2.str(); //Converts int to string
string output = name_ + "\n" + "Author: " + author_ + " " + "ISBN: " + isbn_ + "\n" + cost + " " + quantity + " left." + "\n";
return output;
}
void Book::dump(ostream& os) const {
os << category_ << "\n" << name_ << "\n" << price_ << "\n" << qty_ << "\n" << isbn_ << "\n" << author_ << endl;
}