-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
208 lines (162 loc) · 5.1 KB
/
main.cpp
File metadata and controls
208 lines (162 loc) · 5.1 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// ConsoleApplication21.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <iostream>
#include <list>
#include <string>
#include "books_linked_list.h"
#include "book_issued.h"
#include "customer.h"
using namespace std;
int main()
{
char choice;
int id;
int book_id;
string temp_name;
string search_book_title_2 = "", author = "";
books book_listing;
borrowed_books issued_books;
user user_database;
// starter books
book_listing.Add("Harry Potter", "jk rowling");
book_listing.Add("Lord of the Rings", "JRR");
book_listing.Add("Great Gatsby", "F.Scott Fitzgerald");
book_listing.Add("Tenki no ko", "Makoto Shinkai");
book_listing.Add("Kimi No Nawa", "Makoto Shinkai");
while (true)
{
std::cout << "<!-- Welcome to advanced library management systems --!> \n";
std::cout << "[1] to search for a book\n" <<
"[2] to borrow a book\n" <<
"[3] to return a book\n" <<
"[4] to add to book.\n" <<
"[5] to display all books.\n" <<
"[6] to add a user.\n" <<
"[7] to remove a user.\n" <<
"[8] to display all user.\n";
std::cout << "Please enter a function: ";
std::cin >> choice;
std::cin.ignore();
switch (choice)
{
case'1': // searching for a book
cout << "====================\n";
std::cout << "Please enter a book title to search for: ";
std::getline(cin, search_book_title_2);
book_listing.searchtitle(search_book_title_2);
break;
case '2': // borrowing a book
cout << "====================\n";
cout << "Please enter user id: ";
cin >> id;
// try catch block if string is entered for user id
while (cin.fail()) {
cout << "Please enter a valid user id: ";
cin.clear();
std::cin.ignore(256, '\n');
cin >> id;
}
cin.ignore();
std::cout << "Please enter the book ID to borrow: ";
cin >> book_id;
// try catch block for if string is entered for book id
while (cin.fail()) {
cout << "Please enter a valid book id: ";
cin.clear();
std::cin.ignore(256, '\n');
cin >> book_id;
}
// searches for the book in the book link list based on book id
// if book is found then set search_book_title_2 and author based on the book found in the book linked list
book_listing.search(search_book_title_2, author, book_id);
// only executes if id is NOT null
if (book_id != NULL) {
// searchUser() method returns a boolean value
// if can find user only then remove the book and add to borrowed books
if (user_database.searchUser(id, search_book_title_2)) {
issued_books.Insert(search_book_title_2, author, book_id);
book_listing.DeleteNode(book_id);
}
}
break;
case '3':// returning/ inserting a book
cout << "====================\n";
// entering user id
cout << "Please enter user id: ";
cin >> id;
// try catch block if string is entered for user id
while (cin.fail()) {
cout << "Please enter a valid user id: ";
cin.clear();
std::cin.ignore(256, '\n');
cin >> id;
}
cin.ignore();
// entering book id
std::cout << "Please enter the book ID to return: ";
cin >> book_id;
// try catch block for if string is entered for book id
while (cin.fail()) {
cout << "Please enter a valid book id: ";
cin.clear();
std::cin.ignore(256, '\n');
cin >> book_id;
}
// this checks whether the book exist within the user's list of borrowed books otherwise return "this book has not been loaned"
issued_books.search(search_book_title_2, author, book_id);
// only executes if user got enter book id
if (book_id != NULL) {
if (user_database.searchUserReturnBook(id, issued_books.getBookTitle(book_id))) {
// inserts a book into book listing
book_listing.Insert(issued_books.getBookTitle(book_id), issued_books.getBookAuthor(book_id), book_id);
// deletes a book from the list of borrowed books
issued_books.DeleteNode(book_id);
}
}
break;
case '4': // adding a book
cout << "====================\n";
std::cout << "Please enter title for book: ";
getline(cin, search_book_title_2);
std::cout << "Please enter author: ";
getline(cin, author);
book_listing.Add(search_book_title_2, author);
break;
case '5': // display all books in library
cout << "====================\n";
book_listing.printList();
break;
case '6': // add users
cout << "====================\n";
cout << "Please enter user name: ";
getline(cin, temp_name);
user_database.insert(temp_name);
break;
case '7': // removes user
cout << "====================\n";
cout << "Please enter user id: ";
cin >> id;
while (cin.fail()) {
cout << "Please enter a valid user id: ";
cin.clear();
std::cin.ignore(256, '\n');
cin >> id;
}
user_database.removeUser(id);
break;
case '8': // prints all user
cout << "====================\n";
user_database.printUsers();
break;
default:
cout << "====================\n";
std::cout << "Sorry, that option does not exist.\n";
break;
}
search_book_title_2 = "";
author = "";
book_id = NULL;
id = NULL;
}
}