School Library system
Problem Statement
You are a young tech-entrepreneur who provides technology solutions to challenges faced in the education sector of your country. You decide to build a school library management system that will allow a student to get registered, request to borrow a book from the library through the system and also put in a request to return the book, and a Librarian who will be there to approve requests and accept/check in returned books and update the system.
Required
1.
A Librarian should be able to do all the minimum roles stated, which are:
e.Change/Updatetheirownloginpassword.
f. Fine the students by debiting their library account balance if they have exceeded the number of days that they were to return book. (optional functionality)
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void StudMenu()
{
cout << "\tYou are in the school library management system.\n"
<< "\tPlease, select some of the following:\n"
<< "G - Get Registered\n"
<< "B - Request to borrow a book\n"
<< "R - Return a book\n"
<< "E - Exit menu\n";
cout << "Your choice:";
}
void LibMenu()
{
cout << "\tYou are in the school library management system.\n"
<< "\tPlease, select some of the following:\n"
<< "L - Login to the system\n"
<< "P - Process requests\n"
<< "E - Exit menu\n";
cout << "Your choice:";
}
void MainMenu()
{
cout << "\tYou are in the school library management system.\n"
<< "\t\tWho are you:\n";
cout << "1 - Student\n"
<< "2 - Librarian\n"
<< "3 - Exit program\n";
cout << "Your choice:";
}
struct Student
{
string name;
string passw;
int fee;
bool operator==(Student &s)
{
if (name == s.name && passw == s.passw)
return true;
else
return false;
}
};
void ReqRegUser(vector<Student> &Users, map<pair<string, string>, string> &responses)
{
Student st;
string name;
cout << "\nEnter your name:";
cin >> st.name;
string passw;
cout << "\nEnter your password:";
cin >> st.passw;
int fee;
cout << "\nEnter a flat fee of 1000 shillings:";
cin >> st.fee;
Users.push_back(st);
//Type of response
string resp = "Reg";
responses.insert(pair<pair<string, string>, string>({name, passw}, resp));
cout << "Request submitted!";
}
void ReqBorrowBook(map<pair<string, string>, string> &responses)
{
string nm;
cout << "Enter your name: ";
cin >> nm;
string book;
cout << "\nEnter a book to borrow:";
cin >> book;
string resp = "Bor";
responses.insert(pair<pair<string, string>, string>({nm, book}, resp));
cout << "Request submitted!";
}
void ReqReturnBook(map<pair<string, string>, string> &responses)
{
string nm;
cout << "Enter your name: ";
cin >> nm;
string book;
cout << "\nEnter a book to return:";
cin >> book;
string resp = "Ret";
responses.insert(pair<pair<string, string>, string>({nm, book}, resp));
cout << "Request submitted!";
}
struct Librarian
{
string name;
string passw;
Librarian(string _name, string _passw) : name(_name), passw(_passw) {}
bool operator==(Librarian &l)
{
if (name == l.name && passw == l.passw)
return true;
else
return false;
}
};
bool LoginLibrarian(vector<Librarian> &Libers)
{
string name;
cout << "\nEnter your name:";
cin >> name;
string passw;
cout << "\nEnter your password:";
cin >> passw;
Librarian temp(name, passw);
for (vector<Librarian>::iterator it = Libers.begin(); it != Libers.end(); ++it)
{
if (*it == temp)
return true;
}
return false;
}
void ReqProcess(map<pair<string, string>, string> &responses, vector<Student> &Users, vector<string> &books)
{
cout << "You have this responses:\n";
for (map<pair<string, string>, string>::iterator it = responses.begin(); it != responses.end(); ++it)
{
cout << it->second << " from " << it->first.first << " " << it->first.second << endl;
}
char ch;
cout << "Process? [Y/N]";
cin >> ch;
if (ch == 'Y')
{
for (map<pair<string, string>, string>::iterator it = responses.begin(); it != responses.end(); ++it)
{
if (it->second == "Reg")
{
for (vector<Student>::iterator itu = Users.begin(); itu != Users.end(); ++itu)
{
if (itu->name == it->first.first)
{
if (itu->fee < 1000)
{
cout << "User do not have deposit a flat fee of 1000 shillings\n";
Users.erase(itu);
}
}
}
responses.erase(it->first);
}
if (it->second == "Bor")
{
for (vector<Student>::iterator itu = Users.begin(); itu != Users.end(); ++itu)
{
if (itu->name == it->first.first)
{
auto p = find(books.begin(), books.end(), it->first.second);
books.erase(p);
}
}
responses.erase(it->first);
}
if (it->second == "Ret")
{
books.push_back(it->first.second);
responses.erase(it->first);
}
}
}
}
int main()
{
vector<Student> Users;
vector<Librarian> Libers;
Librarian l("Jack", "12345");
vector<string> books{"Nature", "Bad Man", "Peolpe"};
map<pair<string, string>, string> responses;
char choice;
do
{
MainMenu();
cin >> choice;
if (choice == '1')
{
char ch;
do
{
StudMenu();
cin >> ch;
switch (ch)
{
case 'G':
{
ReqRegUser(Users, responses);
break;
}
case 'B':
{
ReqBorrowBook(responses);
break;
}
case 'R':
{
ReqReturnBook(responses);
break;
}
}
} while (ch != 'E');
}
else if (choice == '2')
{
char ch;
do
{
bool check = false;
LibMenu();
cin >> ch;
switch (ch)
{
case 'L':
{
check = LoginLibrarian(Libers);
break;
}
case 'B':
{
if (check)
ReqProcess(responses, Users, books);
else
{
cout << "You are not autorized to perform this operation!\n";
}
break;
}
}
} while (ch != 'E');
}
} while (choice != '3');
}
Comments
Leave a comment