-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
163 lines (127 loc) · 6.85 KB
/
main.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "library.hpp"
#include "book.hpp"
#include "libraryuser.hpp"
#include "student.hpp"
#include "teacher.hpp"
#include <iostream>
using namespace std;
int main(){
//testing a constructor and print method for Book object
Book b1("Harry Potter", "J.K. Rowling", "Fantasy");
cout << "Printing Book information: " << endl;
b1.print();
//create a vector of book pointers
vector <Book*> book_ptr;
book_ptr.push_back(new Book(b1));
book_ptr.push_back(new Book("Happy Days", "J.Frank"));
book_ptr.push_back(new Book("Live Life", "Annie", "Romance", "2012"));
book_ptr.push_back(new Book("Babies Born"));
//pass the created books into a Library and test two constructors for Library
Library library(book_ptr);
Library library2;
//testing printing methods on both libraries
cout << "Printing Library information: " << endl;
cout << "Library 2: " << endl;
library2.print(); //testing print method on empty library, should say it is empty
cout << "Library 1: " << endl;
library.print(); //testing print method on initialized library, should print out all book details
//tests for successful insertion by inserting books not yet in library
cout << "Lets add some books to the library!" << endl;
library.insert_books(new Book("Lively"));
library.insert_books(new Book("Physics", "Thomas Willet", "Science", "2020"));
library.insert_books(new Book("Math", "Speziale", "Calculus", "2000"));
library.insert_books(new Book("Work Balance", "Robert", "Science"));
library.insert_books(new Book("Lively", "Marcus"));
library.insert_books("Holidays", "Johnny", "Romance", "1994");
library.insert_books("Coding", "Fani", "Education", "2024");
cout << endl;
cout << endl;
//test for unsuccessful insertion
cout << "Lets try to add books already existing in Library!" << endl;
library.insert_books("Physics", "Thomas Willet", "Science", "2020");
library.insert_books(new Book("Live Life", "Annie", "Romance", "2012"));
cout << endl;
cout << endl;
//successful removal
cout << "Lets remove some books!" << endl;
library.remove_books("Work Balance", "Robert", "Science");
library.remove_books(new Book("Math", "Speziale", "Calculus", "2000"));
cout << endl;
cout << endl;
//unsuccessful removal
cout << "Lets try removing nonexistent books from Library!" << endl;
library.remove_books("Make Cookies");
library.remove_books(new Book("Divergent", "John Legend", "Action", "2009"));
cout << endl;
cout << endl;
//declare a student and a teacher
cout << "Lets create some students and teachers!" << endl;
Student arwa("Arwa", 21143658, 0, 1, 5);
arwa.print();
cout << endl;
Student salma("Salma", 21123164, 0, 2, 1);
salma.print();
cout << endl;
Teacher fani("Professor Fani", 123456, 0, 10);
fani.print();
cout << endl;
cout << endl;
//testing for student 1 (arwa)
cout << "Arwa is testing some methods in the Library!\n" << endl;
cout << "Arwa is trying to borrow Coding." << endl;
library.borrow_book(arwa, "Coding", "Education"); //borrowing a book that student is not allowed to borrow
cout << "Now, Arwa is trying to borrow Holidays." << endl;
library.borrow_book(arwa, "Holidays", "Romance"); //borrowing a valid book
cout << arwa.get_name() << "'s borrowed count: " << arwa.get_borrowed_count() << endl; //checking to see if student's borrowed count increased by 1
library.return_book(arwa, "Holidays");
cout << arwa.get_name() << "'s new borrowed count: " << arwa.get_borrowed_count() << endl; //checking to see if student's borrowed count decreased by 1
cout << endl;
cout << endl;
//testing for student 2 (salma)
cout << "Salma is also testing some methods in the Library!\n" << endl;
cout << "Salma is trying to borrow Live Life." << endl;
library.borrow_book(salma, "Live Life", "Romance"); //borrowing an acceptable book for student
cout << salma.get_name() << "'s borrowed count: " << salma.get_borrowed_count() << endl; // should print 1
cout << "Salma is trying to also borrow Harry Potter." << endl;
library.borrow_book(salma, "Harry Potter", "Fantasy"); //should throw error since borrow limit is already met
//now try to make borrow limit 1 again by returning a book.
library.return_book(salma, "Live Life");
cout << salma.get_name() << "'s new borrowed count: " << salma.get_borrowed_count() << endl; //should now print 0
cout << "Now Salma can borrow Harry Pottter!" << endl;
library.borrow_book(salma, "Harry Potter", "Fantasy"); //should work
cout << endl;
cout << endl;
//testing for teacher 1 (fani)
cout << "Professor Fani is testing out some methods!\n" << endl;
cout << "Professor is trying to borrow Coding" << endl;
library.borrow_book(fani, "Coding", "Education"); //borrowing acceptable book for teacher
cout << "Now the professor is trying to borrow Holidays" << endl;
library.borrow_book(fani, "Holidays", "Romance"); //borrowing a book teacher is not allowed to borrow
cout << fani.get_name() << "'s borrowed count: " << fani.get_borrowed_count() << endl; //checking to see if teacher's borrowed count increased by 1
library.return_book(fani, "Coding");
cout << fani.get_name() << "'s new borrowed count: " << fani.get_borrowed_count() << endl; //checking to see if teacher's borrowed count decreased by 1 again
cout << endl;
//testing successful teacher adding book to library
cout << "Professor Fani is editing the Library!\n" << endl;
cout << "Professor is adding a book to the library." << endl;
fani.add_book_to_library(library, new Book("Twinkle Twinkle Little Star", "Arwa", "Lullaby", "1980"));
//testing unsuccessful teacher adding book to library
cout << "Professor is adding an already existing book to the library." << endl;
fani.add_book_to_library(library, new Book("Physics", "Thomas Willet", "Science", "2020"));
//testing successful teacher updating book details
cout << "Professor is updating a book in the library." << endl;
fani.update_book_details(library, "Twinkle Twinkle Little Star", "Da Vinci", "Nursery", "1999");
//testing unsuccessful teacher updating book details
cout << "Professor is updating a nonexistent book in the library." << endl;
fani.update_book_details(library, "My boy", "Rob", "Nursery", "1999");
cout << endl;
cout << endl;
//Test advanced search
cout << "Lets search for some books in the Library!\n" << endl;
library.advanced_search("Lively", "Marcus");
library.advanced_search("Physics");
library.advanced_search("Twinkle Twinkle Little Star", "Arwa", "Lullaby");
library.advanced_search("Twinkle Twinkle Little Star", "Da Vinci", "Nursery");
library.advanced_search("Salma's Diary", "", "2012");
return 0;
}