-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_mgmt_with_oop.cpp
401 lines (363 loc) · 9.37 KB
/
lib_mgmt_with_oop.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#include<iostream>
#define sas 50
#define sba 50
using namespace std;
int flag=0;
int sid=0;
class Lib{
public :
// private :
string record[sas];
string student[sas] = { "shafqat" , "talha" , "ata" , "tehrim" , "akash" , "null" };
string booksnames[sba] = {"Islamiat ", "G. Science " , "Mathematics" , "Programming" , "Physics " , "null"};
int token[sas] = {1 , 1 , 1 , 1 , 1};
int collection[sba] = { 10 , 10 , 10 , 10 , 10 , 0 } ;
void editstudent(){
int snu;
string editedstudentname;
cout<<" which student's name want you to edit ?\n";
for(int i=0;student[i]!="null";i++)
{
cout<<i+1<<":"<<student[i]<<endl;
}
cin>>snu;
cout<<" enter new name for student : "<<student[snu-1]<<endl;
cin>>editedstudentname;
student[snu-1]=editedstudentname;
cout<<"Done !\n";
}
void removestudent(){
int rs;
cout<<" which student you want to remove \n";
for(int i=0;student[i]!="null";i++)
{
cout<<i+1<<":"<<student[i]<<endl;
}
cin>>rs;
for(int i=rs-1 ; student[i]!="null" ; i++){
student[i]=student[i+1];
}
cout<<" student name has been deleted succesfullu !\n";
}
void addstudent(){
int already=0;
string newname;
cout<<"enter name of new student\n";
cin>>newname;
for(int i=0 ; student[i]!="null" ; i++)
{
if(newname==student[i]){
already=1;
break;
}
}
if(already){
cout<<" student is already registered\n";
}
else{
for(int i=0 ; student[i]!="null" ; i++){
if(student[i+1]=="null")
{
student[i+1]=newname;
student[i+2]="null";
token[i+1]=1;
cout<<" new student : "<<newname<<" has been added succesfully\n";
break;
}
}
}
}
void modifystudents(){
int cho;
cout<<"1. for add new student \n2. for remove registered student \n3. for edit current student name \n";
cin>>cho;
switch(cho)
{
case 1:
addstudent();
break;
case 2:
removestudent();
break;
case 3:
editstudent();
break;
default:
system("cls");
cout<<" invalid choice \n";
modifystudents();
}
}
void editbook(){
int bookid;
string newnameofbook;
cout<<" which book you want to edit \n";
for(int a=0 ; booksnames[a]!="null" ; a++)
{
cout<<a+1<<". "<<booksnames[a]<<endl;
}
cin>>bookid;
cout<<" write new book name to replace \n";
cin>>newnameofbook;
booksnames[bookid-1]=newnameofbook;
cout<<" Done !\n";
}
void removebook(){
int bookid;
cout<<" which book you want to remove ?\n";
int c=0;
while(booksnames[c]!= "null")
{
cout<<c+1<<". "<<booksnames[c]<<endl;
c++;
}
cin>>bookid;
char sure;
cout<<" are you sure to delete the book : "<<booksnames[--bookid]<<" ? ( y/n)\n";
cin>>sure;
if(sure=='y' || sure=='N'){
//booksnames[bookid]=NULL;
int d=bookid;
while(booksnames[d] != "null")
{
booksnames[d]=booksnames[d+1];
d++;
}
cout<<" the book has been deleted succesfully \n";
} else if(sure=='n' || sure=='N'){
cout<<" the book is not deleted \n ";
}
else {
cout <<" you have selected invalid option \n";
}
}
void addbook(){
string newbookname;
int already;
int q;
cout<<" write name of new book to add it into the list \n";
cin>>newbookname;
cout<<" Quantity : ";
cin>>q;
for(int b=0 ; b<sba ; b++){
if(newbookname==booksnames[b])
{
already=1;
break;
}
else
{
already=0;
}
}
if(already)
{
cout<<" sorry book is already available so you can not add the same book more than one time \n";
}
else{
for(int e=0 ; e<sba ; e++)
{
if(booksnames[e]=="null"){
booksnames[e]=newbookname;
booksnames[e+1]="null";
collection[e]=q;
cout<<" new book : "<<newbookname<<" hase been succesfully added \n";
break;
}
}
}
}
void bookmodify(){
int opt;
cout<<" 1. for edit book \n 2. for add new book \n 3. for remove book\n";
cin>>opt;
switch(opt)
{
case 1:
editbook();
break;
case 2:
addbook();
break;
case 3:
removebook();
break;
default :
cout<<" invalid option \n";
bookmodify();
}
}
bool isReg()
{ int check=0;
string user;
cout<<"Enter Student name \n( Note : write name in lower case letters ) \n";
cin>>user;
for(int i=0 ; i<5 ;i++){
if(user==student[i])
{
sid=i;
//return sid;
check=1;
i=5;
break;
}
else{
check=0;
}
}
if(check!=1)
{
cout<<"Sorry you are not a registered student \n";
librarianmenu();
}
}
void bookissue(int sid)
{
int bookid;
cout<<"Which book you want to be issued ? \n";
viewbooks();
cin>>bookid;
system("cls");
dec();
cout<<endl<<endl<<endl;
if(collection[--bookid]==0){
cout<<" Sorry we have no more your desire books to issue \n";
}
else if(token[sid]!=1)
{
cout<<" Sorry you already have one book to return \n";
}
else{
cout<<" The book : "<<booksnames[bookid]<<" has been issued on the name of : "<<student[sid]<<endl;
collection[bookid]--;
token[sid]=0;
record[sid]=booksnames[bookid];
}
}
void view()
{
char a;
cout<<"1. View Registered Students\n2. View Books with Quantity \n";
cin>>a;
switch(a)
{
case '1':
for(int i=0;student[i]!="null";i++)
{
cout<<i+1<<":"<<student[i]<<endl;
}
break;
case '2':
system("cls");
dec();
cout<<"Book : Quantity \n";
for(int i=0;booksnames[i]!="null" ;i++)
{
cout<<i+1<<":"<<booksnames[i]<<" : "<<collection[i]<<endl;
}
break;
}
}
void returnbook(int sid)
{ int whichbook;
if(token[sid]==1){
cout<<"You dont have to return any book \n";
}
else
cout<<"Thanks "<<student[sid]<<" for returning book : "<<record[sid]<<" on time \n";
for(int i=0 ; booksnames[i]!="null" ; i++)
{
if(record[sid]==booksnames[i])
{
whichbook=i;
break;
}
}
collection[whichbook]++;
token[sid]=1;
record[sid]="null";
}
void viewbooks()
{
system("cls");
dec();
cout<<"Book : Quantity \n";
for(int i=0; booksnames[i]!="null" ;i++)
{
cout<<i+1<<":"<<booksnames[i]<<" : "<<collection[i]<<endl;
}
}
void dec(){
cout<<" ******************************************************************\n";
cout<<" ********** Welcome to Student Library Management System *********\n";
cout<<" ******************************************************************\n";
}
////////////////////////
void librarianmenu()
{
int choice,bookid,A;
B:
cout<<"\n1: for issue \n2: for return book \n3: View\n4: for modify books \n5: for modify students\n6: for logout \n7: for exit \n";
cin>>choice;
system("cls");
dec();
switch(choice)
{ case 1:
isReg();
bookissue(sid);
goto B;
case 2:
isReg();
returnbook(sid);
goto B;
case 3:
view();
goto B;
case 4:
bookmodify();
goto B;
case 5:
modifystudents();
goto B;
case 6:
cout<<" Succesfully Logout !\n";
librarian_login();
case 7:
system("cls");
cout<<" Thank You for using Our Software ! \n \t see you soon \n";
exit(0);
default:
cout<<"Wrong Choice\n";
goto B;
}
}
/////////////////
int librarian_login()
{ string adminuser;
string adminpass;
l:
cout<<"\t \t \t Login \n";
cout<<" username : ";
cin>>adminuser;
cout<<" password : ";
cin>>adminpass;
if(adminuser== "admin" && adminpass=="admin"){
system("cls");
dec();
cout<<" * * * Welcom Admin * * * \n";
librarianmenu();
}
else {
cout<<" user or pass or both incorrect \n";
goto l;
}
}
};
int main()
{
Lib obj;
obj.dec();
obj.librarian_login();
system("pause");
return 0;
}