-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
293 lines (176 loc) · 4.13 KB
/
client.cpp
File metadata and controls
293 lines (176 loc) · 4.13 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
283
284
285
286
287
288
289
290
291
292
293
//headers for implementation of class client
#include "book.cpp"
#include<vector>
//headers for password abstraction
#include <cstdlib>
#include <iostream>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
using namespace std;
//demo initialisation for making it a friend
class libaray;
class client{
//friend
friend class library;
//private data members
string name;
string password;
vector<book> books_with_client;
//private methords
//private accessors
void get_data();
string get_name();
//private mutators
void set_name(string&);
void set_password(string&);
void change_password();
//overloaded operators
bool operator==(client&);
friend ostream& operator<<(ostream&,client&);
int inner_menu();
void add_books(book);
void return_books();
void view_books();
public:
//public methords
//constructors
client();
client(int);
//menu for clients
int menu();
};
ostream& operator<<(ostream& out,client& c){
cout<<"^^^^^^^^^^^CLIENT^^^^^^^^^^\n";
cout<<"NAME:: "<<c.name<<endl;
cout<<"books with me "<<endl;
for(int i=0;i<c.books_with_client.size();i++){
cout<<c.books_with_client[i]<<endl;
}
return out;
}
void client::set_password(string& password){
this->password=password;
return ;
}
void client::set_name(string& name){
this->name=name;
return ;
}
client::client(int i){
//version of constructor that allows garbage
}
string client::get_name(){
//accesor for name
return this->name;
}
bool client::operator==(client& c){
//fxn to compare equality of two clients base don username
return (name==c.get_name());
}
void client::view_books(){
//private methord to vew client
cout<<"#########################\n\n";
cout<<" "<<name<<endl<<endl;
cout<<"books with you are\n\n";
for(int i=0;i<books_with_client.size();i++){
cout<<books_with_client[i]<<endl;
}
return ;
}
void client::change_password(){
//private methord to change password to be called only by menu fxn
password=getpass("enter your password");
}
void client::return_books(){
//private methord to return books to library
for(int i=0;i<books_with_client.size();i++){
cout<<"######## "<<i<<" ###########\n"<<books_with_client[i]<<endl;
}
int index;
cin>>index;
if(index<0||index>=books_with_client.size()){
cout<<"wrong input\n";
return_books();
}
else{
int qty;
cout<<"enter the no of copies to return\n";
cin>>qty;
if(qty<0||qty>books_with_client[index].get_copies()){
cout<<"wrong input \n";
return_books();
}
else if(qty==books_with_client[index].get_copies()){
books_with_client.erase(books_with_client.begin()+index);
return ;
}
else {
books_with_client[index].set_copies(books_with_client[index].get_copies()-qty);
return ;
}
}
return ;
}
void client::add_books(book b){
//private methord to add books to the client collection
for(int i=0;i<books_with_client.size();i++){
if(books_with_client[i]==b){
books_with_client[i].set_copies(books_with_client[i].copies+b.get_copies());
return ;
}
}
books_with_client.push_back(b);
return ;
}
void client::get_data(){
//private methord only to be called by constructor to get imp data
cout<<"enter the name of the client (username must be unique) \n";
getline(cin,name);
cout<<"enter the password for the client\n";
password=getpass("enter your password");
}
int client::inner_menu(){
//fxn to return choice for the main menu to be called only by the menu
int choice;
cout<<"1:: issue books\n";
if(this->books_with_client.size())cout<<"2:: return book\n";
cout<<"3:: view books with you\n";
cout<<"4:: change your password\n";
cout<<"0:: return\n";
cin>>choice;
return choice;
}
int client::menu(){
//menu for the client
while(1){
switch(inner_menu()){
case 1:
{
cout<<"here we go\n";
return 1;
}
break;
case 2:
this->return_books();
break;
case 3:
this->view_books();
break;
case 4:
this->change_password();
break;
case 0:
return 0;
break;
default:
cout<<"wrong choice\n";
break;
}
}
return 0;
}
client::client(){
//priavte methord called by constructor to get data
this->get_data();
}