-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategory.cpp
More file actions
86 lines (70 loc) · 1.75 KB
/
Copy pathCategory.cpp
File metadata and controls
86 lines (70 loc) · 1.75 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Category.h"
#include <iostream>
Category::Category() : Media() {}
Category::Category(string title) : Media(title) {}
Category::~Category() {
for (int i = 0; i < this->list.size(); i++)
delete this->list[i];
}
void Category::print() {
std::cout << "Category: " << this->getTitle() << std::endl;
}
void Category::printBooks() {
for (Book* book : this->list)
book->print();
}
int Category::bookCount() {
return this->list.size();
}
vector<Book*> Category::getBooks() {
return this->list;
}
Book* Category::findBook(string title) {
for (Book* book : this->list)
if (title == book->getTitle())
return book;
// If no book is found, return an empty one
Book* noneFound = new Book("BookNotFound");
return noneFound;
}
Book* Category::findBook(uint64_t isbn13) {
for (Book* book : this->list)
if (isbn13 == book->getISBN13())
return book;
// If no book is found, return an empty one
Book* noneFound = new Book("BookNotFound");
return noneFound;
}
void Category::add(Book* book) {
this->list.push_back(book);
}
void Category::remove(Book* book) {
for (int i = 0; i < this->list.size(); i++)
if (this->list.at(i)->compare(book))
{
delete this->list[i];
this->list.erase(this->list.begin() + i);
break;
}
}
void Category::remove(string title) {
for (int i = 0; i < this->list.size(); i++)
if (title == this->list.at(i)->getTitle())
{
delete this->list[i];
this->list.erase(this->list.begin() + i);
break;
}
}
void Category::removeAt(int index) {
delete this->list[index];
this->list.erase(this->list.begin() + index);
}
void Category::remove(uint64_t isbn13) {
for (int i = 0; i < this->list.size(); i++)
if (isbn13 == this->list.at(i)->getISBN13())
{
this->list.erase(this->list.begin() + i);
break;
}
}