Untitled
unknown
c_cpp
2 years ago
29 kB
12
Indexable
// library management system - Project 2023, BSCS 1-B /* Mustafa - 02-134222-022 Mutahhar - 02-134222- Abdur Rafay - 02-134222- */ #include <iostream> #include <fstream> #include <string> #include <iomanip> #include <sstream> using namespace std; string admin = "mustafa"; string adminpassword = "19232"; int book_i = -1; int user_i = -1; int lend_i = -1; int today_d, today_m, today_y; int new_d, new_m, new_y; struct book { int id; // will be regulated with "i" string name; string category; string authname; string publisher; string avail; // availibility status string isbn; }book[200]; struct user { int accid; // will be regulated with "i" string name; string phone; }user[100]; struct lend { int id; string user; string book; string date; string newdate; int nodays; // number of days to lend }lend[100]; void outermost(); void userRecMenu(); void bookRecMenu(); void lendingRecMenu(); void goBack(int menu); /*------------------------------------------------------------------------- CHECKER FUNCTIONS -------------------------------------------------------------------------*/ bool checkDate() { if(today_d > 31 || today_m > 12) { return false; } else { return true; } } string toStringDate(int d, int m, int y) { stringstream sn_d; stringstream sn_m; stringstream sn_y; sn_d << d; string strNew_d=sn_d.str(); sn_m << m; string strNew_m=sn_m.str(); sn_y << y; string strNew_y=sn_y.str(); string strDate = strNew_d + "/" + strNew_m + "/" + strNew_y; return strDate; } void checkEndLim() { if(new_d >= 31) { new_m++; lend[lend_i].nodays = 31 - lend[lend_i].nodays; new_d = today_d + lend[lend_i].nodays; lend[lend_i].nodays = 31 - lend[lend_i].nodays; } else if(new_d >= 31 && today_m == 12) { new_y++; lend[lend_i].nodays = 31 - lend[lend_i].nodays; new_d = today_d + lend[lend_i].nodays; lend[lend_i].nodays = 31 - lend[lend_i].nodays; new_m = 1; } } // assuming library only lends books for 31 days only. bool checkBookEmpty() { if (book_i == -1) { return true; } else { return false; } } bool checkUserEmpty() { if (user_i == -1) { return true; } else { return false; } } bool checkLendEmpty() { if (lend_i == -1) { return true; } else { return false; } } int getUserId(); void getUserAll(); string getPhoneByName(string name) { getUserAll(); int j = getUserId(); string str; for (int i = 0; i < j; i++) { if (user[i].name == name) { str = user[i].phone; } } return str; } int getLendId(); int checkNotif() { int j; int notif = 0; fstream getLendId; getLendId.open("lendidlog.txt", ios::in); getLendId >> j; getLendId.close(); string date = toStringDate(today_d, today_m, today_y); for (int i = 0; i < j; i++) { if (date == lend[i].newdate) { notif++; } } return notif; } bool checkRetDate() { int j = getLendId(); fstream getLendDate; string skip; getLendDate.open("lendlogs.txt", ios::in); for (int i = 0; i < j; i++) { getLendDate >> lend[i].id>> skip >> lend[i].user >> skip >> lend[i].newdate >> skip; } getLendDate.close(); int got[j]; bool found = false; string date = toStringDate(today_d, today_m, today_y); int count = 0; cout << "TODAY'S RETURN LENDS ARE: \n"; for (int i = 0; i < j; i++) { if (date == lend[i].newdate) { found = true; got[j] = i; } else { got[j] = -1; } } for (int i = 0; i < j; i++) { if(got[i] != -1 && found == true) { cout << "CHECK LEND ID: " << lend[got[i]].id << endl; cout << "CALL USER : " << getPhoneByName(lend[got[i]].user) << endl; cout << "\n \n"; } } return found; } bool hasBookLend(int x, int y) { int j = getLendId(); for(int i = 0; i < j; i++) { if(lend[x].user == lend[i].user || lend[y].book == lend[i].book) { return true; } else if(lend[x].user == "DEL" && lend[y].book == "DEL") { return false; } } return false; } /*------------------------------------------------------------------------- TEXT-TO ARRAY FUNCTIONS -------------------------------------------------------------------------*/ int getBookId() { fstream getBookId; getBookId.open("bookidlog.txt", ios::in); getBookId >> book_i; getBookId.close(); return book_i; } int getLendId() { ifstream getLendId("lendidlog.txt"); getLendId >> lend_i; getLendId.close(); return lend_i; } int getUserId() { ifstream getUserId("useridlog.txt"); getUserId >> user_i; getUserId.close(); return user_i; } void getBookAll() { fstream getBookId; getBookId.open("bookidlog.txt", ios::in); getBookId >> book_i; getBookId.close(); fstream bookAvail; bookAvail.open("bookAvails.txt", ios::in); int j = 0; int tempId; string tempAv; while(!bookAvail.eof()) { bookAvail >> tempId >> tempAv; book[j].id = tempId; book[j].avail = tempAv; j++; } bookAvail.close(); ifstream getBook("bookRecs.txt"); j = 0; while(!getBook.eof()) { getBook >> book[j].isbn >> book[j].id >> book[j].name >> book[j].category >> book[j].authname >> book[j].publisher; j++; } // !eof => not end of file. } void checkAvailBook() { int lid = getLendId(); int bid = getBookId(); for (int i = 0; i < bid; i++) { book[i].avail = "yes"; } for(int i = 0; i < lid; i++) { for(int j = 0; j < bid; j++) { if (lend[i].book == book[j].name) { book[j].avail = "no"; } } } remove("bookAvails.txt"); fstream remake; remake.open("bookAvails.txt", ios::out); for(int i = 0; i < bid; i++) { remake << book[i].id << "\t" << book[i].name << endl; } remake.close(); } void getUserAll() { // getting user ID fstream getUserId; getUserId.open("useridlog.txt", ios::in); getUserId >> user_i; getUserId.close(); int lineId; string lineName, linePhone; fstream userId; userId.open("userids.txt", ios::in); int j = 0; while(!userId.eof()) { userId >> user[j].accid; j++; } fstream userName; userName.open("usernames.txt", ios::in); j = 0; while(!userName.eof()) { getline(userName, lineName); user[j].name = lineName; j++; } fstream userPhone; userPhone.open("userPhones.txt", ios::in); j = 0; while(!userPhone.eof()) { getline(userPhone, linePhone); user[j].phone = linePhone; j++; } } void getLendRec() { int j; ifstream getLendId("lendidlog.txt", ios::in); getLendId >> j; getLendId.close(); ifstream getLendRecs("lendlogs.txt"); int i = 0; for(int i = 0; i < j; i++) { getLendRecs >> lend[i].id >> lend[i].book >> lend[i].user >> lend[i].date >> lend[i].newdate >> lend[i].nodays; } } /*------------------------------------------------------------------------- STORING FUNCTIONS -------------------------------------------------------------------------*/ void setAvailBook(int i) { fstream availBook; availBook.open("bookAvails.txt", ios::out); for (int i = 0; i < (getBookId()); i++) { availBook << book[i].id << "\t" << book[i].avail << endl; } } void storeBookRec() { // fstream bookAvail; bookAvail.open("bookAvails.txt", ios::app); bookAvail << book[book_i].id << "\t" << book[book_i].avail << endl; // ofstream storeBook("bookRecs.txt", ios::app); storeBook << book[book_i].isbn << endl << book[book_i].id << endl << book[book_i].name << endl << book[book_i].category << endl << book[book_i].authname << endl << book[book_i].publisher << endl; storeBook.close(); fstream writeBookId; writeBookId.open("bookidlog.txt", ios::out); writeBookId << book[book_i].id; writeBookId.close(); bookAvail.close(); } void storeUserRec() { fstream userId; userId.open("userids.txt", ios::app); fstream userName; userName.open("usernames.txt", ios::app); fstream userPhone; userPhone.open("userPhones.txt", ios::app); userId << user[user_i].accid << "\n"; userName << user[user_i].name << "\n"; userPhone << user[user_i].phone << "\n"; fstream writeUserId; writeUserId.open("useridlog.txt", ios::out); writeUserId << user[user_i].accid; writeUserId.close(); userId.close(); userName.close(); userPhone.close(); } void storeLendRec() { ofstream setLendRecs("lendlogs.txt", ios::app); setLendRecs << lend[lend_i].id << endl << lend[lend_i].book << endl << lend[lend_i].user << endl << lend[lend_i].date << endl << lend[lend_i].newdate << endl << lend[lend_i].nodays << endl; setLendRecs.close(); } /*------------------------------------------------------------------------- RETURN LEND FUNCTIONS & PSEUDO-DELETERS -------------------------------------------------------------------------*/ void returnLend(int x) { getLendRec(); getBookAll(); int index; int j = getLendId(); for (int i = 0; i < j; i++) { if(lend[i].id == lend[x].id) { lend[i].id = -1; index = i; lend[i].user = "DEL"; lend[i].date = "RETURNED"; lend[i].newdate = "RETURNED"; } } } void delUser(int x) { getUserAll(); int j = getUserId(); for (int i = 0; i < j; i++) { if(user[i].accid == user[x].accid) { user[i-1].accid = -1; } } } void delBook(int x) { getBookAll(); int j = getBookId(); for (int i = 0; i < j; i++) { if(book[i].id == book[x].id) { book[i].id = -1; } } } /*------------------------------------------------------------------------- DELETER MENUS -------------------------------------------------------------------------*/ void delUserMenu() { system("cls"); int j = getUserId(); int x; cout << "\n \n \n \t \t \t USER DELETE \n \n \n"; cout << "Which user (ID) do you want to delete? \n \n"; cin >> x; delUser(x); remove("userids.txt"); fstream remake; remake.open("userids.txt", ios::out); for(int i = 0; i < j; i++) { remake << user[i].accid << endl; } remake.close(); goBack(2); } void delBookMenu() { system("cls"); int j = getBookId(); int x; cout << "\n \n \n \t \t \t BOOK DELETE \n \n \n"; cout << "Which book (ID) do you want to delete? \n \n"; cin >> x; delBook(x); remove("bookRecs.txt"); remove("bookAvails.txt"); fstream remakeBookRec; fstream remakeBookAvail; remakeBookRec.open("bookRecs.txt", ios::out); remakeBookAvail.open("bookAvails.txt", ios::out); j--; for(int i = 0; i < j; i++) { if(book[i].id != -1) { remakeBookAvail << book[i].id << "\t" << book[i].avail << endl; remakeBookRec << book[i].isbn << endl << book[i].id << endl << book[i].name << endl << book[i].category << endl << book[i].authname << endl << book[i].publisher << endl; } } remakeBookRec.close(); remakeBookAvail.close(); remove("bookidlog.txt"); fstream remakeBookId; remakeBookId.open("bookidlog.txt",ios::out); remakeBookId << j; remakeBookId.close(); goBack(1); } void returnLendMenu() { system("cls"); int j = getLendId(); int x; cout << "\n \n \n \t \t \t LEND RETURN \n \n \n"; cin >> x; int y = x-1; returnLend(y); remove("lendlogs.txt"); fstream remakeLendLog; remakeLendLog.open("lendlogs.txt", ios::out); j--; for(int i = 0; i < j; i++) { if(lend[i].id != -1) { remakeLendLog << lend[i].id << endl << lend[i].book << endl << lend[i].user << endl << lend[i].date << endl << lend[i].newdate << endl << lend[i].nodays << endl; } } remakeLendLog.close(); remove("lendidlog.txt"); fstream remakeLendId; remakeLendId.open("lendidlog.txt",ios::out); remakeLendId << j; remakeLendId.close(); goBack(1); } /*------------------------------------------------------------------------- SEARCHING FUNCTIONS -------------------------------------------------------------------------*/ // this functions is specifically for lending menu int searchBookByName(string toBeBook) { getBookAll(); bool found = false; int index; for(int i = 0; i < book_i; i++) { if(book[i].name == toBeBook) { found = true; index = i; } } if (found == true) { return index; cout << " \n \nFOUND!"; } else { return -1; cout << "\n \n not found..."; } } // BOOK SEARCHES void filterByCategory() { string cat; cout << "\n \n \t \t SEARCH BY CATEGORY \n \n \n "; cout << "Enter what category you want to search in. \n \n"; cin >> cat; cout << "\n \n \n"; cout << "YOUR RESULTS ARE \n \n:"; int k = getBookId(); cout << left << setw(10) << "ID" << left << setw(20) << "Title" << left << setw(15) << "Category" << left << setw(10) << "Author" << left << setw(15) << "Availibility" << endl; for (int j = 0; j < k; j++) { if (book[j].category == cat) { cout << left << setw(10) << book[j].id << left << setw(20) << book[j].name << left << setw(15) << book[j].category << left << setw(20) << book[j].authname << left << setw(5) << book[j].avail << endl; } } } void filterByAvail() { int k = getBookId(); cout << left << setw(10) << "ID" << left << setw(20) << "Title" << left << setw(15) << "Category" << left << setw(10) << "Author" << left << setw(15) << "Availibility" << endl; for (int j = 0; j < k; j++) { if ((book[j].id != -1) && (book[j].avail == "yes")) { cout << left << setw(10) << book[j].id << left << setw(20) << book[j].name << left << setw(15) << book[j].category << left << setw(20) << book[j].authname << left << setw(5) << book[j].avail << endl; } } } void bookSearchMenu() { int k = getBookId(); string skip; fstream getBookRecs; getBookRecs.open("bookRecs.txt", ios::in); for(int i = 0; i < k; i++) { getBookRecs >> skip >> book[i].id >> book[i].name >> book[i].category >> book[i].authname >> skip; } getBookRecs.close(); fstream getBookAvail; getBookAvail.open("bookAvails.txt", ios::in); for (int i = 0; i < k; i++) { getBookAvail >> book[i].id >> book[i].avail; } getBookAvail.close(); int choice; cout << "\n \n \n \n \t \t \t SEARCH BOOK BY FILTER \n \n \n"; cout << left << setw(25) << "Press 1 to search by category\n" << left << setw(25) << "Press 2 to search by availibility\n" << left << setw(25) << "Press 3 to go back.\n" << endl; cin >> choice; if (choice == 1) { system("cls"); filterByCategory(); goBack(1); } else if(choice == 2) { system("cls"); cout << "AVAILIBLE BOOKS CURRENTLY ARE: \n \n"; filterByAvail(); goBack(1); } else if(choice == 3) { goBack(1); } } /*------------------------------------------------------------------------- ADDING FUNCTIONS -------------------------------------------------------------------------*/ void addUser() { char cont; do { system("cls"); cout << "ADD USER" << endl; cout << "-----------------"; //getting user id from log text file fstream getUserId; getUserId.open("useridlog.txt", ios::in); getUserId >> user_i; getUserId.close(); // checking if users are empty.. if (checkUserEmpty() == true) { cout << "\t \t \t NO USER RECORDS YET!\t \n"; user_i++; } else { cout << "\t \t \t TOTAL USERS :" << user_i + 1 << endl; } string tempName; user[user_i].accid = user_i + 1; cout << "Enter User Name" << endl; getline(cin >> ws, tempName); user[user_i].name = tempName; cout << "Enter User's Phone Number" << endl; cin >> user[user_i].phone; storeUserRec(); cout << "do you want to continue? y/n \n"; cin >> cont; if (cont == 'n' || cont == 'N') { userRecMenu(); } } while(cont == 'y' || cont == 'Y'); } void addbook() { char cont; do { system("cls"); cout << "ADD BOOK" << endl; cout << "-------------------" << endl; // checking if there are book records or not, displaying appropriately fstream getBookId; getBookId.open("bookidlog.txt", ios::in); getBookId >> book_i; getBookId.close(); if(checkBookEmpty() == true) { cout << "\t \t NO BOOKS CURRENTLY \n \n"; book_i++; } else { cout << "\t \t TOTAL BOOKS CURRENTLY: " << book_i << endl; } string tempName, tempAuth, tempCat, tempPub, tempISBN; // using temporary string to take in from getline and assign it to book structures book[book_i].id = book_i + 1; cout << endl << "Enter ISBN of book " << book[book_i].id << endl; getline(cin >> ws, tempISBN); book[book_i].isbn = tempISBN; cout << endl << "Enter name of book " << book[book_i].id << endl; getline(cin >> ws, tempName); book[book_i].name = tempName; cout << endl << "Enter Author of book " << book[book_i].id << endl; getline(cin >> ws, tempAuth); book[book_i].authname = tempAuth; cout << endl << "Enter Category of book " << book[book_i].id << endl; getline(cin >> ws, tempCat); book[book_i].category = tempCat; cout << endl << "Enter Publisher of book " << book[book_i].id << endl; getline(cin >> ws, tempPub); book[book_i].publisher = tempPub; // assuming the book is recently added, hence it must be availible - book[book_i].avail = "yes"; storeBookRec();// storing records using function cout << "do you want to continue? y/n \n"; cin >> cont; if (cont == 'n' || cont == 'N') { bookRecMenu(); } } while(cont == 'y' || cont == 'Y'); } void addLend() { int testid; int i; char choice; fstream getLendId("lendidlog.txt", ios::in); getLendId >> lend_i; getLendId.close(); if (lend_i == -1) { lend_i++; } do { lend[lend_i].id = lend_i + 1; system("cls"); cout << "\t \t \n NEW LEND \n \n" << endl; char choice; // Lends can only be created with integer lend.nodays for 30 days only. do { cout << "Enter ID of User that wants to lend a book.\n \n"; cin >> testid; if(user[testid-1].accid == -1) { cout << "\n \nTHIS USER IS TEMPORARILY NOT AVAILIBLE \n \n"; goBack(3); } cout << "\t \n do you want this user to lend the book? \n \n"; cout << left <<setw(10) << "User ID:" << left <<setw(50) << "User Name:" << left <<setw(10) << "User Phone" <<endl; cout << left << setw(10) << user[testid-1].accid << left << setw(50) << user[testid-1].name << left << setw(10) << user[testid-1].phone << "\n \n y/n"; cin >> choice; } while(choice == 'n' || choice == 'N'); //if(return int --> value of checkLentBooks(testid) > 5 etc etc); char bookYN; do { system("cls"); cout << "SEARCH BOOK \n \n"; cout << "------------ \n \n"; string toBeBook; // searching variable cout << "ENTER Name of the Book to get ID! \n \n"; getline(cin >> ws, toBeBook); i = searchBookByName(toBeBook); if (i == -1) { cout << "book not found \n"; goBack(3); } cout << "do you want to add lend for this book : \n \n"; cout << left << setw(10) << book[i].id << left << setw(30) << left << book[i].name << endl << "y / n \n"; cin >> bookYN; if (bookYN == 'y' || bookYN == 'Y') { book[i].avail = "no"; setAvailBook(i); lend[lend_i].book = book[i].name; } }while(bookYN == 'n' || bookYN == 'N'); cout << "No. Days To lend" << endl; cin >> lend[lend_i].nodays; // converting today's date into string lend[lend_i].date = toStringDate(today_d, today_m, today_y); // calculating future dates for lends new_d = today_d + lend[lend_i].nodays; new_m = today_m; new_y = today_y; checkEndLim(); // converting new lend days, month, year into string :: lend[lend_i].newdate = toStringDate(new_d, new_m, new_y); lend[lend_i].user = user[testid-1].name; if(!hasBookLend(i,testid-1)) { cout << "RECORD ADDED SUCCESFULLY! \n \n"; storeLendRec(); fstream writeLendId; writeLendId.open("lendidlog.txt", ios::out); writeLendId << lend[lend_i].id; } else { cout << "Error, cannot add to pre-existing users and books! \n \n"; } cout << "do you want to continue? y / n \n \n"; cin >> choice; if (choice == 'n' || choice == 'N') { lendingRecMenu(); } } while(choice == 'y' || choice == 'Y'); } /*------------------------------------------------------------------------- PRINT / READ FUNCTIONS -------------------------------------------------------------------------*/ void printUserAll() { int k = getUserId(); system("cls"); cout << " " << setw(50) << "\n \n \n \t \t \t ALL USER RECORDS \n \n \n"; cout << left << setw(10) << "Acc ID" << left << setw(30) << "Name" << left << setw(15) << "Phone Number" << endl; for (int j = 0; j < k; j++) { if (user[j].accid != -1) { cout << left << setw(10) << user[j].accid << left << setw(30) << user[j].name << left << setw(15) << user[j].phone << endl; } else { continue; } } } void printISBN() { int k = getBookId(); cout << " " << setw(50) << "BOOK ID & ISBN TABLE" << endl; cout << left << setw(10) << "ID" << left << setw(30) << "ISBN" << endl; for (int j = 0; j < k; j++) { if(book[j].id != -1) { cout << left << setw(10) << book[j].id << left << setw(30) << book[j].isbn << endl; } else { continue; } } } void printBookAll() { checkAvailBook(); int k = getBookId(); char choice; system("cls"); cout << "\n \ndo you want to print ISBN table as well? \n \n"; cin >> choice; if(choice == 'y' || choice == 'Y') { printISBN(); cout << " \n \n " << "Do you want to clear the ISBN table? y/n"; cin >> choice; if(choice == 'y' || choice == 'Y') { system("cls"); } else { cout << " \n"; } } cout << " " << setw(50) << "\n \n \n \t \t \t ALL BOOK RECORDS: \n \n \n" << endl; cout << left << setw(10) << "ID" << left << setw(20) << "Title" << left << setw(15) << "Category" << left << setw(10) << "Author" << left << setw(15) << "Availibility" << endl; for (int j = 0; j < k; j++) { if (book[j].id != -1) { cout << left << setw(10) << book[j].id << left << setw(20) << book[j].name << left << setw(15) << book[j].category << left << setw(20) << book[j].authname << left << setw(5) << book[j].avail << endl; } else { continue; } } } void printLendAll() { system("cls"); int k = getLendId(); cout << "\n \n \t \t \t ALL LEND RECORDS \n \n \n \n"; cout // << left << setw(5) << "ID" // << left << setw(20) << "Book NAME" // << left << setw(20) << "Lended TO" // << left << setw(10) << "FROM" // << left << setw(14) << "TILL" // << left << setw(9) << "DAYS" << endl; for (int j = 0; j < k; j++) { if(lend[j].id != -1) { cout // << left << setw(5) << lend[j].id // << left << setw(20) << lend[j].book // << left << setw(20) << lend[j].user // << left << setw(14) << lend[j].date // << left << setw(14) << lend[j].newdate // << left << setw(5) << lend[j].nodays << endl; } else { continue; } } } /*------------------------------------------------------------------------- NAVIGATION MENUS / FUNCTIONS -------------------------------------------------------------------------*/ void lendingRecMenu(); void goBack(int menu) { int back; cout << "\n \ndo you want to go back?" << "\n Press 1 to go back to Previous Menu\n" << "Press 2 to go back to Main Menu \n"; cin >> back; if(back == 1 && menu == 2) { bookRecMenu(); } else if (back == 1 && menu == 1) { userRecMenu(); } else if (back == 1 && menu == 3) { lendingRecMenu(); } if (back == 2) { outermost(); } } void bookRecMenu() { int choice; int menu = 2; system("cls"); cout << "BOOK RECORDS \n \n" << endl; cout << "Press 1 to Add New book \n" << "Press 2 to Search a book \n" << "Press 3 to Print Book \n" << "Press 4 to Delete a book \n \n" << "Press 0 to go back \n"; cin >> choice; if (choice == 1) { addbook(); } else if (choice == 2) { getBookAll(); bookSearchMenu(); } else if (choice == 3) { getBookAll(); printBookAll(); goBack(menu); } else if (choice == 4) { delBookMenu(); } else if (choice == 0) { outermost(); } } void userRecMenu() { int choice; int menu = 1; system("cls"); cout << "USER ACCOUNT RECORDS \n \n" << endl; cout << "Press 1 to add new user account \n" << "Press 2 to print all user accounts \n" << "Press 3 to delete a user account \n \n" << "Press 0 to go back \n"; cin >> choice; if (choice == 1) { addUser(); } else if (choice == 2) { getUserAll(); printUserAll(); goBack(menu); } else if (choice == 3) { delUserMenu(); } else if (choice == 0) { outermost(); } } void lendingRecMenu() { int choice; getLendRec(); getUserAll(); int menu = 3; system("cls"); cout << "LENDING LOGS \n \n" << endl; if (checkRetDate() == true) { cout << "\n \n"; } else { cout << "NO RETURN DATES TODAY! \n \n"; } cout << "press 1 to create new lend" << endl; cout << "press 2 to print all recent logs" << endl; cout << "press 3 to return the existing lends" << endl; cout << endl; cout << "press 0 to go back \n"; cin >> choice; if (choice == 1) { addLend(); } else if (choice == 2) { getLendRec(); printLendAll(); goBack(menu); } else if (choice == 3) { returnLendMenu(); } else if (choice == 0) { outermost(); } } void outermost() { getLendRec(); system("cls"); int choice; int notif = checkNotif(); string date = toStringDate(today_d, today_m, today_y); bool logged = true; checkNotif(); cout << "Welcome back " << admin << "." << right << setw(50) << date << endl; if (notif != 0) cout << "YOU HAVE " << notif << " NEW NOTIFICATIONS, CHECK LEND LOG MENU " << endl;// welcome message cout << "\n \n"; cout << "press 1 for user records \n press 2 for book records \n press 3 for lending logs \n press 0 to exit \n"; cin >> choice; if(choice == 1) { userRecMenu(); } else if (choice == 2) { bookRecMenu(); } else if (choice == 3) { lendingRecMenu(); } else if (choice == 0) { exit(0); } } int main() { /* MAIN VARIABLES */ string username; // admin login system string password; // admin login system bool logged = false; int choice; /* GATHERING ALL DATA AS ARRAYS */ if(checkBookEmpty() == false || checkUserEmpty() == false || checkLendEmpty() == false) { getBookAll(); getUserAll(); getLendRec(); } // only empty when program is started. else { cout << "------ Library Management System ------" << endl; cout << "\n \n"; do { cout << "\t \tEnter today's date. \n"; cout << "Enter day \n"; cin >> today_d; cout << "Enter Month \n"; cin >> today_m; cout << "Enter Year \n"; cin >> today_y; if(checkDate() == false) { system("cls"); cout << "wrong date, try again \n"; } } while(checkDate() == false); // adding an admin / password login system for security system("cls"); do { cout << "\n \n \n \t \t \t Admin LOGIN \t \n \n"; cout << "enter username" << endl; cin >> username; cout << "enter password" << endl; cin >> password; if (username == admin && password == adminpassword) { logged = true; outermost(); } else { system("cls"); cout << "\n \t \t \t invalid credentials, try again."; } } while(logged==false); } } // end
Editor is loading...