Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
28 kB
0
Indexable
Never
// 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 <bits/stdc++.h>


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;
	
	// lending log & user connecter ::: usables:
	int lentNoBooks; // will be regulated by ++ iteration each time
	int lateSubWarn;
}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();
bool checkRetDate() {
	
	int j = getLendId();
	bool found = false;
	string date = toStringDate(today_d, today_m, today_y);
	int got[j];
	int count = 0;
	cout << "TODAY'S RETURN LENDS ARE: \n";
	for (int i = 0; i < j; i++)
	if (date == lend[i].newdate) {
				found = true;
				count++;
				got[j] = i;	
	}
	else {
		got[j] = -1;
	}
	
	for (int i = 0; i < j-1; 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;
		}
	}
	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();
//// opening all txt file records
//	fstream bookIsbn;
//	bookIsbn.open("bookISBN.txt", ios::in);
//	
//	fstream bookName;
//	bookName.open("booknames.txt", ios::in);
//	
//	fstream bookId;
//	bookId.open("bookIds.txt", ios::in);
//	
//	fstream bookAuthName;
//	bookAuthName.open("bookAuthNames.txt", ios::in);
//	
//	fstream bookPub;
//	bookPub.open("bookPublishers.txt", ios::in);
//	
//	fstream bookCat;
//	bookCat.open("bookCat.txt", ios::in);
//	
	fstream bookAvail;
	bookAvail.open("bookAvails.txt", ios::in);
//	
//	// using temporary strings to circumvent getline argument
//	int lineId;
//	string lineName, lineAuth, linePub, lineAvail, lineCat, lineISBN;
//	int j = 0;
//		while(!bookIsbn.eof()) {
//		getline(bookIsbn, lineISBN);
//		book[j].isbn = lineISBN;
//		j++;
//	}
//	j = 0;
//	while(!bookName.eof()) {
//		getline(bookName, lineName);
//		book[j].name = lineName;
//		j++;
//	}
//		j = 0;
//		while(!bookId.eof()) {
//		bookId >> lineId;
//		book[j].id = lineId;
//		j++;
//	}
//		j = 0;
//		while(!bookAuthName.eof()) {
//		getline(bookAuthName, lineAuth);
//		book[j].authname = lineAuth;
//		j++;
//	}
//			j = 0;
//		while(!bookCat.eof()) {
//		getline(bookCat, lineCat);
//		book[j].category = lineCat;
//		j++;
//	}
//		 j = 0;
//			while(!bookPub.eof()) {
//		getline(bookPub, linePub);
//		book[j].publisher = linePub;
//		j++;
//	}
		 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 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) {
//	getBookAll();
//	fstream availBook;
//	availBook.open("bookRecs2.txt", ios::out);
//	
//	for (int j = 0; j < getBookId(); j++) {
//		availBook << book[j].isbn << endl << book[j].id << endl << book[j].name << endl << book[j].category << endl << book[j].authname << endl << book[j].publisher << endl << book[j].avail << endl;
//	}

	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 bookIsbn;
//	bookIsbn.open("bookISBN.txt", ios::app);
//	
//	fstream bookName;
//	bookName.open("booknames.txt", ios::app);
//	
//	fstream bookId;
//	bookId.open("bookIds.txt", ios::app);
//	
//	fstream bookAuthName;
//	bookAuthName.open("bookAuthNames.txt", ios::app);
//	
//	fstream bookPub;
//	bookPub.open("bookPublishers.txt", ios::app);
//	
//	fstream bookCat;
//	bookCat.open("bookCat.txt", ios::app);
//	
	fstream bookAvail;
	bookAvail.open("bookAvails.txt", ios::app);
//	
//	
//	bookIsbn << book[book_i].isbn << "\n";
//	bookId << book[book_i].id << "\n";
//	bookName << book[book_i].name << "\n";
//	bookCat << book[book_i].category << "\n";
//	bookAuthName << book[book_i].authname << "\n";
//	bookPub << book[book_i].publisher << "\n";
	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();
//	bookId.close();
//	bookName.close();
//	bookCat.close();
//	bookAuthName.close();
//	bookPub.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() {
	
	
		/*
		fstream addLend("lendlogs.txt", ios::app);
	// to get w.r.t lend_i for all, we would have to use lendBook[lend_i] and lendUser[lend_i] for recalling
	// after getting, we can change and then setLendAll() to add those changes onto the file in::out mode.
	// in the delete lend, we will ask which user has returned the book, along with book id, we will then use that
	// info to update user & book related things connected with lend.
		addLend << lend[lend_i].id << "\t" << book[i].name << "\t" << user[testid-1].name << "\t" << lend[lend_i].date << "\t" << lend[lend_i].newdate << endl;
	addLend.close();
	fstream setLendRecs;
	setLendRecs.open("lendcheck.txt",ios::app);
	setLendRecs << lend.id[i] << "\t" << lend.user[i] << "\t" << lend.book[i] << "\t" << lend.date[i] << "\t" << lend.newdate[i] << "\t" << lend.nodays << "\n";
	setLendRecs.close(); */
	
	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();
	
	
}

/*-------------------------------------------------------------------------
							 SEARCHING FUNCTIONS
-------------------------------------------------------------------------*/	

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...";
		}
}
/*-------------------------------------------------------------------------
							 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;


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 << "do you want Book's ISBN to be searched?" << endl;
	cin >> choice;
	checkBookLend();
	if (checkBookLend() == true) {
		/// add lend etc
	}
	else {
		/// error, cannot add new lend coz the book is already lent.
		// - cout the line that shows its lend-log.
		// - go back button.
	}
	if (choice == 'y' || choice == 'Y') {
		int gotBook = searchBookById(toBeBook);
		book[gotBook].avail = "no";
	}*/
	
	
	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() {
	
	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 < user[j].accid; j++)
    {
        cout
            << left
            << setw(10)
            << user[j].accid
            << left
            << setw(30)
            << user[j].name
            << left
            << setw(15)
            << user[j].phone
            << endl;
    }
}


void printISBN() {
        cout << " " << setw(50) << "BOOK ID & ISBN TABLE" << endl;
        
        cout
            << left
            << setw(10) 
            << "ID"
            << left
            << setw(30)
            << "ISBN"
            << endl;
            
        
        for (int j = 0; j < book[j].id; j++) {
            cout
                << left
                << setw(10)
                << book[j].id
                << left
                << setw(30)
                << book[j].isbn
                << endl;
        }
}
void printBookAll() {
	
	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 < book[j].id; j++) {
				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 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++) {
	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;
		}
}


/*-------------------------------------------------------------------------
							 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) {
				//searchbook();
			}
			
			else if (choice == 3) {
				getBookAll();
				printBookAll();
				goBack(menu);
			}
			
			else if (choice == 4) {
				//deletebook();
		
}

			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 search a user account \n" 
            << "Press 3 to print all user accounts \n"
            << "Press 4 to delete a user account \n \n" 
            << "Press 0 to go back \n";
			
			cin >> choice;
			
			if (choice == 1) {
				addUser();
			}
			
			else if (choice == 2) {
				//searchuser();
			}
			
			else if (choice == 3) {
				getUserAll();
				printUserAll();
				goBack(menu);
			}
			
			else if (choice == 4) {
				//deleteuser();
			}
			
			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 search a log by ID or DATE" << endl;
			cout << "press 3 to print all recent logs" << endl;
			cout << endl;
			cout << "press 0 to go back \n";
			
			
			cin >> choice;
			
			if (choice == 1) {
				addLend();
			}
			
			else if (choice == 2) {
				//searchLog();
			}
			
			else if (choice == 3) {
				getLendRec();
				printLendAll();
				goBack(menu);
			}
			
			else if (choice == 0) {
				outermost();
			}
}

void outermost() {
	
	system("cls");
		int choice;
		string date = toStringDate(today_d, today_m, today_y);
			bool logged = true;
		cout << "Welcome back " << admin << "." << right << setw(50) << date << 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();
	}
	
}


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);
}
}
// TODO

/* make a code, so that we could have a reading only file, and a displaying only file
make a code, so that book_i is saved in a log file and upon new setup, it picks up the saved number.

make it so that the lending will change status of book

make it so that we can check availible books and non-availible books w.r.t lent

make it so that in addLend, admin should only add ID, and returning of user record is automatic.

make it so that a book which isn't found cannot be lent. 


NOTE TO SELF:


//////////// METHOD 1 TO SOLVE WITHOUT HAVING TO STORE EVERY RECORD IN ONE FILE
it will be better if we make new file for each record, and then if we want to search that record
we can just use the file name to print out the record inside it, same goes with other
methods like update etc, but data repitition will cost long-term memory.

pros: less code, coz its easier to search file name rather than string from a line
cons: data repitition.


//////////// METHOD 2 TO SOLVE WITHOUT HAVING TO STORE EVERY RECORD IN ONE FILE
This idea is now exempted, we now are sacrificing short term memory of the program by
using Arrays.which gather from file upon loading, and write its changes onto the 
file once again when its completed.*/

// NEW TODO:



/* 

WORK ON INPUT FUNCTION IN BOOK TO ENCOMPASS ISBN AND PAIR IT WITH BOOK ID
               TO SHOW ON A DIFFERENT TABLE --- ----  (done)



WORK ON LEND FUNCTIONS, ESPECIALLY ADD - Try to have Log-based output (wip)

work on the prompt of return date etc, format the menus in such a way
that there is a date on top at all times (of today).

WORK ON SEARCH / UPDATE IN BOOK FUNCTIONS -- Sort by ID, by Name, by Category, by Author.
WORK ON SEARCH / UPDATE IN User FUNCTIONS -- Sort by Id, by Name


CALCULATION FUNCTIONS IN LEND - - 

try having functions that show under 10 days remaining of ppl who ought to
return a book.

try having functions that can give warning to users if they don't return book
by time. // Try having this shown on main window(?)

ADD A CHECK CRITERIA THAT SEES IF A BOOK IS LENT OR NOT, IF YES, THEN
COUT IT IS NOT POSSIBLE TO ADD NEW LEND!
 */