-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha5_library.cpp
More file actions
94 lines (77 loc) · 2.39 KB
/
Copy patha5_library.cpp
File metadata and controls
94 lines (77 loc) · 2.39 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
87
88
89
90
91
92
93
94
#include <iostream>
#include <vector>
#include "a5_library.hpp"
using namespace std;
// PURPOSE: Class that models a library
/*
CONSTRUCTORS
*/
// Default construcor that initializes the vector attribute implicitly
Library::Library() {}
// Parametric construcor that takes a vector of Books and stores the values
Library::Library(vector <Book> my_library) :
my_books(my_library) {}
/*
GETTERS
*/
// Outputs all the books stored in the Library instance
void Library::print() {
for (int i = 0; i < my_books.size(); ++i) {
my_books[i].print();
}
}
/*
SETTERS
*/
/*insert FOR STRINGS*/
bool Library::insert(string new_title, string new_authors, string new_dop)
{
for (int index = 0; index < my_books.size(); index++)
{
if (new_title == my_books[index].get_title() && new_authors == my_books[index].get_authors() && new_authors == my_books[index].get_authors())
{
return false;
}
}
Book new_book(new_title, new_authors, new_dop);
my_books.push_back(new_book);
return true;
}
/*insert FOR OBJECTS*/
bool Library::insert(Book new_book) {
for (int index = 0; index < my_books.size(); index++)
{
if (new_book.get_title() == my_books[index].get_title() &&
new_book.get_authors() == my_books[index].get_authors() &&
new_book.get_dop() == my_books[index].get_dop())
{
return false;
}
}
my_books.push_back(new_book);
return true;
}
/*removal FOR STRINGS*/
bool Library::remove(string new_title, string new_authors, string new_dop) {
for (int index = 0; index < my_books.size(); index++)
{
if (new_title == my_books[index].get_title() && new_authors == my_books[index].get_authors() && new_dop == my_books[index].get_dop())
{
my_books.erase(my_books.begin() + index);
return true;
}
}
return false;
}
/*removal FOR OBJECTS*/
bool Library::remove(Book new_book) {
for (int index = 0; index < my_books.size(); index++)
{
if (new_book.get_title() == my_books[index].get_title() && new_book.get_authors() == my_books[index].get_authors() && new_book.get_dop() == my_books[index].get_dop())
{
my_books.erase(my_books.begin() + index);
return true;
}
}
return false;
}