-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
1356 lines (1327 loc) · 36.5 KB
/
main.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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
// Make sure to add the given (.txt) files manually as they are not added automatically.
// user.txt, books.txt, lendings.txt, students.txt, returns.txt
// File Handling is used in this project.
// Check if any, errors are present in the code.
void login();
void signup();
void menu();
void addBook();
void deleteBook();
void searchBook();
void addStudent();
void deletestudent();
void searchstudents();
void showallstudents();
void issueBook();
void returnBook();
void showAllBooks();
void showAllLendings();
void showAllFines();
void showAllUsers();
void deleteuserandpass();
void showAllReturns();
void changepassword();
int main()
{
cout << "---------------------------" << endl;
cout << "Group Participants" << endl;
cout << "---------------------------" << endl;
cout << "Hasan Yahya (22L-7971)" << endl;
cout << "Ammar Haider (22L-7985)" << endl;
cout << "Gulrez Amin (22L-7952)" << endl;
cout << "----------------------------------------" << endl;
cout << "Welcome to Library Management System" << endl;
cout << "----------------------------------------" << endl;
cout << "1. Login" << endl;
cout << "2. Sign Up" << endl;
cout << "3. Exit" << endl;
cout << "----------------------------------------" << endl
<< endl;
string choice;
cout << "Enter your choice: ";
cin >> choice;
if (choice == "1")
{
login();
}
else if (choice == "2")
{
signup();
}
else if (choice == "3")
{
exit(0);
}
else
{
cout << "Invalid Choice" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
return 0;
}
void login()
{
system("cls");
string username, password;
cout << "Enter Username: ";
cin >> username;
if (username == "test")
{
cout << "You have By-Passed the login system" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
menu();
}
cout << "Enter Password: ";
cin >> password;
// make a login function, keeping in mind the signup function
ifstream fin;
fin.open("user.txt");
if (!fin)
{
cout << "Error in opening file" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
else
{
string line;
while (getline(fin, line))
{
if (line == username)
{
// open username_user.txt and compare password
string filename = username + "_user.txt";
ifstream fin1;
fin1.open(filename);
if (!fin1)
{
cout << "Error in opening file" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
else
{
string line1;
while (getline(fin1, line1))
{
if (line1 == password)
{
cout << "\n-----------------------" << endl;
cout << "Login Successful" << endl;
cout << "-----------------------\n"
<< endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
menu();
}
else
{
cout << "\n-------------------------" << endl;
cout << "Invalid Password" << endl;
cout << "---------------------------\n"
<< endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
}
}
}
}
cout << "\n-------------------------" << endl;
cout << "Invalid Username" << endl;
cout << "---------------------------\n"
<< endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
}
void menu()
{
int choice;
cout << endl;
cout << "------------------------------------------" << endl;
cout << "1. Add Book" << endl;
cout << "2. Delete Book" << endl;
cout << "3. Search Book" << endl;
cout << "4. Add Student" << endl;
cout << "5. Delete Student" << endl;
cout << "6. Search Student" << endl;
cout << "7. Show All Students" << endl;
cout << "8. Issue Book" << endl;
cout << "9. Return Book" << endl;
cout << "10. Show All Books" << endl;
cout << "11. Show All Lendings" << endl;
cout << "12 Show all Returns" << endl;
cout << "13. Show All Fines" << endl;
cout << "14. Show All Users" << endl;
cout << "15. Show Group Participants" << endl;
cout << "16. Delete User" << endl;
cout << "17. Change password" << endl;
cout << "18. Exit" << endl;
cout << "------------------------------------------" << endl
<< endl;
cout << "Enter your choice: ";
cin >> choice;
if (choice == 1)
{
cout << endl;
addBook();
}
else if (choice == 2)
{
cout << endl;
deleteBook();
}
else if (choice == 3)
{
cout << endl;
searchBook();
}
else if (choice == 4)
{
cout << endl;
addStudent();
}
else if (choice == 5)
{
cout << endl;
deletestudent();
}
else if (choice == 6)
{
cout << endl;
searchstudents();
}
else if (choice == 7)
{
cout << endl;
showallstudents();
}
else if (choice == 8)
{
cout << endl;
issueBook();
}
else if (choice == 9)
{
cout << endl;
returnBook();
}
else if (choice == 10)
{
cout << endl;
showAllBooks();
}
else if (choice == 11)
{
cout << endl;
showAllLendings();
}
else if (choice == 12)
{
cout << endl;
showAllReturns();
}
else if (choice == 13)
{
cout << endl;
showAllFines();
}
else if (choice == 14)
{
cout << endl;
showAllUsers();
}
else if (choice == 15)
{
cout << endl;
cout << "---------------------------" << endl;
cout << "Group Participants" << endl;
cout << "---------------------------" << endl;
cout << "Hasan Yahya (22L-7971)" << endl;
cout << "Ammar Haider (22L-7985)" << endl;
cout << "Gulrez Amin (22L-7952)" << endl;
cout << "---------------------------" << endl;
cout << endl;
menu();
}
else if (choice == 16)
{
cout << endl;
deleteuserandpass();
}
else if (choice == 17)
{
cout << endl;
changepassword();
}
else if (choice == 18)
{
cout << endl;
cout << "---------------------------" << endl;
cout << "You have exited the program" << endl;
cout << "---------------------------" << endl
<< endl;
exit(0);
}
else
{
cout << endl;
cout << "----------------------" << endl;
cout << "Invalid Choice" << endl;
cout << "----------------------" << endl
<< endl;
menu();
}
}
void signup()
{
string username, password;
cout << "Enter your username: ";
cin >> username;
// if username has underscore in it, give error
if (username.find("_") != string::npos)
{
cout << endl;
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Username cannot contain underscore, You are not allowed to use this username!!!" << endl;
cout << "-------------------------------------------------------------------------------" << endl
<< endl;
signup();
}
if (username == "test")
{
cout << endl;
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Username already exists as test, You are not allowed to use this username!!!" << endl;
cout << "-------------------------------------------------------------------------------" << endl
<< endl;
signup();
}
// if username already exists, give error
ifstream fin;
fin.open("user.txt");
if (!fin)
{
cout << "Error in opening file" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
else
{
string line;
while (getline(fin, line))
{
if (line == username)
{
cout << endl;
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Username already exists, You are not allowed to use this username!!!" << endl;
cout << "-------------------------------------------------------------------------------" << endl
<< endl;
signup();
}
}
}
cout << "Enter your password: ";
cin >> password;
// make a signup function, keeping in mind the login function
ofstream fout;
fout.open("user.txt", ios::app);
if (!fout)
{
cout << "Error in opening file" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
else
{
fout << username << endl;
}
// create a file named username.txt and store the password in it
ofstream fout1;
fout1.open(username + "_user.txt");
if (!fout1)
{
cout << "Error in opening file" << endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
else
{
fout1 << password << endl;
}
cout << "-----------------------" << endl;
cout << "Sign Up Successful" << endl;
cout << "-----------------------" << endl
<< endl;
cout << "Press any key to continue" << endl;
_getch();
system("cls");
main();
}
void addBook()
{
// make sure to create and store the book each time in separate txt file, all book info should be saved in that file
// make sure to store the total number of books in the library in a separate txt file
string bookName, authorName, ISBN, dateOfPublishing;
int quantity, totalQuantity;
cout << "Enter the name of the book: ";
// use getline function
cin.ignore();
getline(cin, bookName);
// convert every large letter into small letter using for loop
for (int i = 0; i < bookName.length(); i++)
{
bookName[i] = tolower(bookName[i]);
}
cout << "Enter the name of the author: ";
getline(cin, authorName);
// convert every capital letter to small letter
for (int i = 0; i < authorName.length(); i++)
{
authorName[i] = tolower(authorName[i]);
}
cout << "Enter the ISBN of the book: ";
// use getline function
getline(cin, ISBN);
// convert every capital letter to small letter
for (int i = 0; i < ISBN.length(); i++)
{
ISBN[i] = tolower(ISBN[i]);
}
cout << "Enter the date of publishing: ";
// use getline function
getline(cin, dateOfPublishing);
// make every capital letter into small letter
for (int i = 0; i < bookName.length(); i++)
{
bookName[i] = tolower(bookName[i]);
}
cout << "Enter the quantity of the book: ";
cin >> quantity;
// store the book info in a separate txt file also store the book title in books.txt
ofstream fout;
fout.open("books.txt", ios::app);
fout.close();
fout.open(bookName + ".txt", ios::app);
fout << bookName << endl;
fout << authorName << endl;
fout << ISBN << endl;
fout << dateOfPublishing << endl;
fout << quantity << endl;
fout.close();
// store the total number of books in the library in a separate txt file
// create a file named books.txt and add the name of book into that that file as well
fout.open("books.txt", ios::app);
fout << bookName << endl;
fout.close();
cout << endl;
cout << "--------------------------------------" << endl;
cout << "Book has been added successfully" << endl;
cout << "--------------------------------------" << endl
<< endl;
menu();
}
void deleteBook()
{
// delete book using title of book and thus delete the whole file of book, also, remove the book name from books.text
// make sure to update the total number of books in the library in a separate txt file
string bookName;
int totalQuantity = 0, quantity = 0;
cout << "Enter the name of the book: ";
cin.ignore();
getline(cin, bookName);
// convert every capital letter to small letter
for (int i = 0; i < bookName.length(); i++)
{
bookName[i] = tolower(bookName[i]);
}
// if book is in lending file, you cannot delete the book
ifstream fin;
fin.open("lendings.txt");
string book;
while (fin >> book)
{
if (book == bookName)
{
cout << endl;
cout << "------------------------------------------------------" << endl;
cout << "Book is in lending file, you cannot delete the book" << endl;
cout << "------------------------------------------------------" << endl
<< endl;
menu();
}
}
fin.close();
// ifbook name isnt in books.txt give error and go back to menu
ifstream fin1;
fin1.open("books.txt");
string line1;
bool found = false;
while (getline(fin1, line1))
{
if (line1 == bookName)
{
found = true;
break;
}
}
fin1.close();
if (found == false)
{
cout << endl;
cout << "-----------------------" << endl;
cout << "Book not found" << endl;
cout << "-----------------------" << endl
<< endl;
menu();
}
// remove the txt file with the name of this book
remove((bookName + ".txt").c_str());
// delete the book name from books.txt, using a temp file
ifstream fin2;
fin2.open("books.txt");
ofstream fout;
fout.open("temp.txt");
string line2;
while (getline(fin2, line2))
{
if (line2 != bookName)
{
fout << line2 << endl;
}
}
fin2.close();
fout.close();
remove("books.txt");
rename("temp.txt", "books.txt");
// end program
cout << endl;
cout << "---------------------------------------" << endl;
cout << "Book has been deleted successfully" << endl;
cout << "---------------------------------------" << endl
<< endl;
menu();
}
void searchBook()
{
// search book using title of book
string bookName;
cout << "Enter the name of the book: ";
cin.ignore();
getline(cin, bookName);
// convert every capital letter to small letter
for (int i = 0; i < bookName.length(); i++)
{
bookName[i] = tolower(bookName[i]);
}
ifstream fin;
fin.open(bookName + ".txt");
// if file doesnt open give error and go to menu
if (!fin)
{
cout << endl;
cout << "-------------------" << endl;
cout << "Book not found" << endl;
cout << "-------------------" << endl
<< endl;
menu();
}
int counter = 0;
string line;
while (getline(fin, line))
{
if (counter == 0)
{
cout << "Book Name: " << line << endl;
}
else if (counter == 1)
{
cout << "Author Name: " << line << endl;
}
else if (counter == 2)
{
cout << "ISBN: " << line << endl;
}
else if (counter == 3)
{
cout << "Date of Publishing: " << line << endl;
}
else if (counter == 4)
{
cout << "Quantity: " << line << endl;
}
counter++;
}
fin.close();
// end function to go to menu
menu();
}
void showAllBooks()
{
// show all books in the library
ifstream fin;
fin.open("books.txt");
// if file doesnt open or has no text give error and go to menu
if (!fin)
{
cout << endl;
cout << "-------------------------" << endl;
cout << "Error, opening file..." << endl;
cout << "-------------------------" << endl
<< endl;
menu();
}
string line;
int counter = 0;
while (getline(fin, line))
{
if (line != "")
{
// turn first letter of every word to capital
line[0] = toupper(line[0]);
// turn every letter after space to capital
for (int i = 0; i < line.length(); i++)
{
if (line[i] == ' ')
{
line[i + 1] = toupper(line[i + 1]);
}
}
cout << counter + 1 << ". " << line << endl;
counter++;
}
}
if (counter == 0)
{
cout << endl;
cout << "-------------------------" << endl;
cout << "No books found" << endl;
cout << "-------------------------" << endl
<< endl;
}
fin.close();
// end function to go to menu
menu();
}
void addStudent()
{
// add a student to the library
string studentName;
cout << "Enter the name of the student: ";
cin.ignore();
getline(cin, studentName);
// convert every capital letter to small letter
for (int i = 0; i < studentName.length(); i++)
{
studentName[i] = tolower(studentName[i]);
}
cout << "Enter Student ID: ";
string StudentID;
getline(cin, StudentID);
cout << "Enter Date of Registration: ";
string dateOfRegistration;
getline(cin, dateOfRegistration);
// if student name is already in students.txt give error and go back to menu
ifstream fin;
fin.open("students.txt");
string line;
bool found = false;
while (getline(fin, line))
{
if (line == studentName)
{
found = true;
break;
}
}
fin.close();
if (found == true)
{
cout << endl;
cout << "---------------------------" << endl;
cout << "Student already exists" << endl;
cout << "---------------------------" << endl
<< endl;
menu();
}
// add student to students.txt
ofstream fout;
fout.open("students.txt", ios::app);
fout << studentName << endl;
fout.close();
// create a file for the student
ofstream fout2;
fout2.open(studentName + ".txt");
fout2 << "Student ID: " << StudentID << endl;
fout2 << "Date of Registration: " << dateOfRegistration << endl;
fout2.close();
cout << endl;
cout << "-------------------------------" << endl;
cout << "Student added successfully" << endl;
cout << "-------------------------------" << endl
<< endl;
// end function to go to menu
menu();
}
void deletestudent()
{
// delete a student from the library
string studentName;
cout << "Enter the name of the student: ";
cin.ignore();
getline(cin, studentName);
// convert every capital letter to small letter
for (int i = 0; i < studentName.length(); i++)
{
studentName[i] = tolower(studentName[i]);
}
// if student name isnt in students.txt give error and go back to menu
ifstream fin;
fin.open("students.txt");
string line;
bool found = false;
while (getline(fin, line))
{
if (line == studentName)
{
found = true;
break;
}
}
fin.close();
if (found == false)
{
cout << endl;
cout << "----------------------" << endl;
cout << "Student not found" << endl;
cout << "----------------------" << endl
<< endl;
menu();
}
// delete student from students.txt
ifstream fin2;
ofstream fout2;
fin2.open("students.txt");
fout2.open("temp.txt");
string line2;
while (getline(fin2, line2))
{
if (line2 != studentName)
{
fout2 << line2 << endl;
}
}
fin2.close();
fout2.close();
remove("students.txt");
rename("temp.txt", "students.txt");
// delete student file
remove((studentName + ".txt").c_str());
cout << endl;
cout << "---------------------------------" << endl;
cout << "Student deleted successfully" << endl;
cout << "---------------------------------" << endl
<< endl;
// end function to go to menu
menu();
}
void searchstudents()
{
// search for a student in the library
string studentName;
cout << "Enter the name of the student: ";
cin.ignore();
getline(cin, studentName);
// convert every capital letter to small letter
for (int i = 0; i < studentName.length(); i++)
{
studentName[i] = tolower(studentName[i]);
}
// if student name isnt in students.txt give error and go back to menu
ifstream fin;
fin.open("students.txt");
string line;
bool found = false;
while (getline(fin, line))
{
if (line == studentName)
{
found = true;
break;
}
}
fin.close();
if (found == false)
{
cout << endl;
cout << "--------------------" << endl;
cout << "Student not found" << endl;
cout << "--------------------" << endl
<< endl;
menu();
}
// print the student file
ifstream fin2;
fin2.open(studentName + ".txt");
string line2;
while (getline(fin2, line2))
{
cout << line2 << endl;
}
fin2.close();
// end function to go to menu
menu();
}
void showallstudents()
{
// show all students in the library
ifstream fin;
fin.open("students.txt");
string line;
int counter = 0;
while (getline(fin, line))
{
if (line != "")
{
cout << counter + 1 << ". " << line << endl;
counter++;
}
}
fin.close();
// there are no students
if (counter == 0)
{
cout << endl;
cout << "-------------------------" << endl;
cout << "No students found" << endl;
cout << "-------------------------" << endl
<< endl;
}
// end function to go to menu
menu();
}
void issueBook()
{
// issue a book to a student
string bookName, student;
cout << "Enter the name of the book: ";
cin.ignore();
getline(cin, bookName);
// convert every capital letter to small letter
for (int i = 0; i < bookName.length(); i++)
{
bookName[i] = tolower(bookName[i]);
}
// if book name isnt in books.txt give error and go back to menu
ifstream fin;
fin.open("books.txt");
string line;
bool found = false;
while (getline(fin, line))
{
if (line == bookName)
{
found = true;
break;
}
}
fin.close();
if (found == false)
{
cout << endl;
cout << "-------------------" << endl;
cout << "Book not found" << endl;
cout << "-------------------" << endl
<< endl;
menu();
}
// if the quantity of book is zero, give error
ifstream fin2;
fin2.open(bookName + ".txt");
string line2;
int quantity;
// quantity is in 5th line of each txt folder
for (int i = 0; i < 5; i++)
{
getline(fin2, line2);
}
fin2.close();
quantity = stoi(line2);
if (quantity == 0)
{
cout << endl;
cout << "---------------------------------" << endl;
cout << "No more copies of this book" << endl;
cout << "---------------------------------" << endl
<< endl;
menu();
}
cout << "Enter the name of the student: ";
getline(cin, student);
// convert every capital letter to small letter
for (int i = 0; i < student.length(); i++)
{
student[i] = tolower(student[i]);
}
// if student name isnt in students.txt give error and go back to menu
ifstream fin3;
fin3.open("students.txt");
string line3;
bool found2 = false;
while (getline(fin3, line3))
{
if (line3 == student)
{
found2 = true;
break;
}
}
fin3.close();
if (found2 == false)
{
cout << endl;
cout << "----------------------" << endl;
cout << "Student not found" << endl;
cout << "----------------------" << endl
<< endl;
menu();
}
// save the Book, Student in Lendings.txt
ofstream fout;
fout.open("lendings.txt", ios::app);
fout << bookName << " " << student << endl;
fout.close();
// subtract 1 from quantity
quantity--;
// Replace the old quantity with new quantity in the book file,
ifstream fin4;
ofstream fout2;
fin4.open(bookName + ".txt");
fout2.open("temp.txt");
string line4;
int counter = 0;
while (getline(fin4, line4))
{
if (counter == 4)
{
fout2 << quantity << endl;
}
else
{
fout2 << line4 << endl;
}
counter++;
}
fin4.close();
fout2.close();
// delete book file
remove((bookName + ".txt").c_str());
// rename temp file to book file
rename("temp.txt", (bookName + ".txt").c_str());
// print success message
cout << endl;
cout << "-------------------------" << endl;
cout << "Book issued successfully" << endl;
cout << "-------------------------" << endl
<< endl;
// end function to go to menu
menu();
}
void returnBook()
{
// return book found in lending file
string bookName, student;
cout << "Enter the name of the book: ";
cin.ignore();
getline(cin, bookName);
// convert every capital letter to small letter
for (int i = 0; i < bookName.length(); i++)
{
bookName[i] = tolower(bookName[i]);
}