-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.cpp
More file actions
68 lines (55 loc) · 1.43 KB
/
book.cpp
File metadata and controls
68 lines (55 loc) · 1.43 KB
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
63
64
65
66
67
68
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include "book.h"
Book::Book(string title, string author, string genre, unsigned int id, double price, unsigned int number) {
this->title = std::move(title);
this->author = std::move(author);
this->genre = std::move(genre);
this->id = id;
this->price = price;
this->number = number;
}
string Book::to_string() const {
stringstream ss;
ss << "Id: " << id << " Title: " << title << " - " << author << " Price: " << price << " zl "
<< " Number of books: " << number;
return ss.str();
}
Book &Book::operator=(const Book &b) {
if (this != &b) {
title = b.title;
author = b.author;
genre = b.genre;
id = b.id;
price = b.price;
number = b.number;
}
return *this;
}
bool operator==(const Book &b1, const Book &b2) {
return (b1.id == b2.id);
}
ostream &operator<<(ostream &os, const Book &b) {
os << b.to_string();
return os;
}
void Book::set_title(string new_title) {
title = std::move(new_title);
}
void Book::set_genre(string new_genre) {
genre = std::move(new_genre);
}
void Book::set_author(string new_author) {
author = std::move(new_author);
}
void Book::set_id(unsigned int new_Id) {
id = new_Id;
}
void Book::set_price(double new_price) {
price = new_price;
}
void Book::set_number(unsigned int new_number) {
number = new_number;
}