-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathordered_books.cpp
More file actions
33 lines (28 loc) · 854 Bytes
/
ordered_books.cpp
File metadata and controls
33 lines (28 loc) · 854 Bytes
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
#include <iostream>
#include "ordered_books.h"
#include <map>
#include <sstream>
using namespace std;
ostream& operator<<(ostream& os, const OrderedBooks& basket) {
os << basket.to_string();
return os;
}
double OrderedBooks::get_total_price() const {
double sum = 0;
map<unsigned int, Book>::const_iterator it;
for(it = books.cbegin(); it != books.cend(); it++) {
sum += (it->second.get_price())*(it->second.get_number());
}
return sum;
}
string OrderedBooks::to_string() const {
stringstream ss;
ss << "\nOrdered books: "<<endl;
map<unsigned int, Book> books = get_books();
map<unsigned int, Book>::const_iterator it;
for(it = books.cbegin(); it != books.cend(); it++) {
ss << it->second<<endl;
}
ss << "Total price: " << get_total_price()<<" zl"<<endl;
return ss.str();
}