-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
214 lines (190 loc) · 5.93 KB
/
main.cpp
File metadata and controls
214 lines (190 loc) · 5.93 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
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
class the_book {
private:
string book_name, book_author;
public:
the_book() {} // default constructor
the_book(string name, string book_author) : book_name(name),
book_author(book_author) {
cout << "Book is created\n";
}
string get_book_name() const {
return this->book_name;
}
};
class customer {
private:
//int id;
string password, name;
bool login_status, signUp_status;
vector<string> list;
public:
customer() : login_status(0), signUp_status(0) { list.clear(); } // default constructor Using initailizer List
string getname()const{
return this->name;
}
bool getlogin_status()const{
return this->login_status;
}
bool getsignup_status()const{
return this->login_status;
}
void setlogin_status(bool login){
this-> login_status = login;
}
void setsignup_status(bool signup){
this->signUp_status = signup;
}
void signUp() { // This fn. enteres the user;
cout << "signUp:\n";
cout << "Enter Your name:\n";
cin >> name;
cout << "Enter a password :\n";
cin >> this->password;
cout << "Enter pass again to Confirm your password\n";
while (true) {
string temp_pass;
cin >> temp_pass;
if (temp_pass == this->password) break;
cout << "Passwords don't match , enter it again\n";
}
cout << "Welcome To The online book reader\n";
login_status = signUp_status = 1;
}
bool CheckLoginOrNot()const {
return login_status;
}
void login() {
if(login_status)return;
if (!signUp_status) {
cout << "You must SignUp first\n";
signUp();
return;
}
cout << "Login:\n";
string name2 = "", pass2 = "";
while (true) {
cout << "Enter Your name:\n";
cin >> name2;
cout << "Enter a password :\n";
cin >> pass2;
if (pass2 == this->password && name2 == this->name) break;
cout << "Name or Password is not valid , please try again\n";
}
cout << "Welcome To The online book reader\n";
login_status = 1;
}
void logOut() {
cout << "now,You are logged out\n";
login_status = 0;
}
/* void viewProfile() {} TO BE IMPLMENTED */
void startToRead(string book_name) { // For choosing a book
list.push_back(book_name);
}
void viewReadingList()const {
cout << "Your Reading List :\n";
for (auto book: this->list) {
cout << book << " ";
}
}
};
class admin {
public:
bool isAdmin()const {
cout << "Enter the Admin code please\n";
string entryCode;
cin >> entryCode;
if(entryCode!="1212ad")cout<<entryCode<<"\n"<<"the admin entry code isn't correct\n ";
return entryCode == "1212ad";
}
map<int, the_book> mp; // put a static to the object
void add_book(string name, string book_author) {
int generated_id = mp.size() + 1;
the_book bo(name, book_author);
mp[generated_id] = bo; //
cout << "Your book is added Successfully and its id = " << generated_id << "\n";
}
void remove_book(int id) {
cout << "so, You want to remove specific book\n";
while (true) {
if (isAdmin()) {
if (mp.count(id) != 0) {
mp.erase(id);
cout << "Your book is Deleted Successfully\n";
} else {
cout << "There's no book with this id\n";
}
break;
}
cout << "are you an admin ?,Please Try again\n";
}
}
void viewAllBooks() const{
for (auto i: mp) {
cout << i.first << " " << i.second.get_book_name() << "\n";
}
}
};
string ask() {
cout << "choose admin or customer or exit?\n";
string ans;
cin >> ans;
return ans;
}
int main() {
admin ad;
customer cu;
while (1) {
string ans=ask();
while (ans == "admin") {
if(!ad.isAdmin())break;
cout << "choose a number from :\n 1-add book \n 2-remove book\n 3-view All Books\n 4-back\n";
int a;
cin >> a;
if (a == 1 ) {
string name, author;
const int N=1000;
cout << "enter the book name\n";
cin.ignore();
getline(cin,name,'\n');
cout << "enter the book author\n";
cin.ignore();
getline(cin, author,'\n');
ad.add_book(name, author);
} else if (a == 2 ) {
int id;
cout << "Enter the book id to remove it\n";
cin >> id;
ad.remove_book(id);
} else if (a == 3 ) {
ad.viewAllBooks();
} else
break;
}
while (ans == "customer") {
cu.login();
cout << "Choose one of these options\n";
int num;
cout << "1-view my reading list \n 2-start reading\n 3-view All Books\n 4-exit\n";
cin >> num;
if (num == 1) {
cu.viewReadingList();
} else if (num == 2) {
cout << "Choose book from the current list:\n";
ad.viewAllBooks();
cout << "-------------------------------------\n";
string name;
cout << "Enter the bookName\n";
cin >> name;
cu.startToRead(name);
} else if (num == 3) {
ad.viewAllBooks();
}else break;
}
if (ans == "Exit"||ans =="exit")break;
}
}