-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
282 lines (230 loc) · 8.23 KB
/
main.cpp
File metadata and controls
282 lines (230 loc) · 8.23 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#ifdef _WIN32
# ifdef USE_ASIO
// Set the proper SDK version before including boost/Asio
# include <SDKDDKVer.h>
// Note boost/ASIO includes Windows.h.
# include <boost/asio.hpp>
# else // USE_ASIO
# include <Windows.h>
# endif // USE_ASIO
#else // _WIN32
# ifdef USE_ASIO
# include <boost/asio.hpp>
# endif // USE_ASIO
#endif //_WIN32
// Include necessary libraries and files
#include <iostream>
#include <fstream>
#include <vector>
#include "json.h"
#include "Book.h"
#include "User.h"
#include "Loan.h"
#include "Custom_String_Class.h"
#include "Functionalities.h"
#include <thread>
using namespace std;
using json = nlohmann::json;
// Get the standard output handle
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// Function declarations
void displayLibraryName();
void playSound(const char* wavPath);
// Main function
int main() {
// Path to the sound file
const char* wavPath = "music.wav";
// Start a new thread to play the sound
std::thread soundThread(playSound, wavPath);
// Set the console size
cout << "\e[8;200;150t";
// Login label for goto statement
Login:
// Display the library name
displayLibraryName();
// Load the files
LoadFiles();
// Set the console text attribute
SetConsoleTextAttribute(hConsole, 8);
// Prompt the user to enter their ID
cout<<"Enter your ID: ";
int id;
cin>>id;
// Clear the console
system("cls");
// Login with the entered ID
Custom_String_Class type = login(id);
// Set the console text attribute
SetConsoleTextAttribute(hConsole, 3);
// If the user is a member
if(type=="member"){
// Find the member by ID
Member member = Librarian::findMemberByID(id);
// Infinite loop for the member menu
while(true){
// Display the library name
displayLibraryName();
// Welcome the member
cout<<endl <<"\t\t\t\t\t\t\tWelcome " <<member.getName() <<" to our library " <<endl;
// Display the member menu
diplayMenuMember();
// Prompt the user to choose an option
int memberOption;
Member_Choose_Option:
cin>>memberOption;
// If the user chooses to logout
if(memberOption==7) {
// Save the files
SaveFiles();
// Clear the console
system("cls");
// Go to the login label
goto Login;
}
// If the user chooses to exit
else if(memberOption==8)
break;
// If the user enters an invalid choice
else if (memberOption <1 || memberOption > 8){
cout<<"Invalid choice" <<endl;
goto Member_Choose_Option;
}
// Clear the console
system("cls");
// Implement the chosen option
implementMemberChoice(member, memberOption);
// Pause the console
system("pause");
// Clear the console
system("cls");
}
}
// If the user is a librarian
else if(type=="librarian"){
// Find the librarian by ID
Librarian librarian = Librarian::findLibrarianByID(id);
// Infinite loop for the librarian menu
while(true){
// Display the library name
displayLibraryName();
// Welcome the librarian
cout<<endl <<"\t\t\t\t\t\t\tWelcome back " <<librarian.getName() <<endl;
// Display the librarian menu
displayMenuLibrarian();
// Prompt the user to choose an option
int librarianOption;
Librarian_Choose_Option:
cin >> librarianOption;
// If the user chooses to logout
if (librarianOption == 15) {
// Save the files
SaveFiles();
// Clear the console
system("cls");
// Go to the login label
goto Login;
}
// If the user chooses to exit
else if (librarianOption == 16) {
break;
}
// If the user enters an invalid choice
else if (librarianOption <1 || librarianOption > 16){
cout<<"Invalid choice" <<endl;
goto Librarian_Choose_Option;
}
// Clear the console
system("cls");
// Implement the chosen option
implementLibrarianChoice(librarian, librarianOption);
// Pause the console
system("pause");
// Clear the console
system("cls");
}
}
// If the user is not found
else if(type=="not found"){
cout<<"You are not registered in our system, Please check your ID again!!"<<endl<<endl;
goto Login;
}
// Save the files
SaveFiles();
// Pause the console
system("pause");
// Join the sound thread
soundThread.join();
return 0;
}
// Function to display the library name
void displayLibraryName(){
SetConsoleTextAttribute(hConsole, 6);
cout<<"\t\t\t ________ ___ _____ ____ ____ ___ ___ __ ________ ____ ___ ______ __\n"
"\t\t\t / ____/ / / | / ___// __ \\/ __ \\ / | / | / / / _/ __ )/ __ \\/ | / __ \\ \\/ /\n"
"\t\t\t / __/ / / ______/ /| | \\__ \\/ / / / / / / / /| | / /| | / / / // __ / /_/ / /| | / /_/ /\\ / \n"
"\t\t\t / /___/ /__/_____/ ___ |___/ / /_/ / /_/ / / ___ |/ ___ | / /____/ // /_/ / _, _/ ___ |/ _, _/ / / \n"
"\t\t\t/_____/_____/ /_/ |_/____/_____/\\___\\_\\/_/ |_/_/ |_| /_____/___/_____/_/ |_/_/ |_/_/ |_| /_/ \n"
"\t\t\t ";
cout<<"\n\n\n";
}
// Function to display the member menu
void diplayMenuMember(){
SetConsoleTextAttribute(hConsole, 3);
cout << "\nSelect an option:\n";
cout << "1. Request to borrow a book\n";
cout << "2. Return a book\n";
cout << "3. Display loaned books\n";
cout << "4. Display your information\n";
cout << "5. Display book list\n";
cout << "6. Find a book\n";
cout << "7. Logout\n";
cout << "8. Exit\n";
}
// Function to display the librarian menu
void displayMenuLibrarian()
{
SetConsoleTextAttribute(hConsole, 3);
cout << "\nSelect an option:\n";
cout << "1. Add book\n";
cout << "2. Remove book\n";
cout << "3. Register new member\n";
cout << "4. Remove member\n";
cout << "5. Edit book\n";
cout << "6. Approve borrow request\n";
cout << "7. Return book\n"; //ana shayef nsheel de
cout << "8. Display all members\n";
cout << "9. Display all books\n";
cout << "10. Display borrow requests\n";
cout << "11. Display all loans\n";
cout << "12. Find a book\n";
cout << "13. Find a member\n";
cout << "14. Find a librarian\n";
cout << "15. Logout\n";
cout << "16. Exit\n";
}
// Function to display the find book menu
void displayMenuFindBook(){
SetConsoleTextAttribute(hConsole, 3);
cout << "\nSelect an option:\n";
cout << "1. Find the book by ISBN\n";
cout << "2. Find the book by name\n";
cout << "3. Find the book by author\n";
}
// Function to display the find member menu
void displayMenuFindMember(){
SetConsoleTextAttribute(hConsole, 3);
cout << "\nSelect an option:\n";
cout << "1. Find the member by name\n";
cout << "2. Find the member by ID\n";
}
// Function to display the find librarian menu
void displayMenuFindlibrarian(){
SetConsoleTextAttribute(hConsole, 3);
cout << "\nSelect an option:\n";
cout << "1. Find the librarian by name\n";
cout << "2. Find the librarian by ID\n";
}
// Function to play a sound
void playSound(const char* wavPath) {
PlaySoundA(wavPath, NULL, SND_FILENAME | SND_LOOP | SND_ASYNC);
}