Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <string.h>
- using namespace std;
- void welcomeMessage();
- string userName;
- string userPassword;
- string login_details[2][100] = {
- {"Kevin","Myra","Usman","Latif"},
- {"1234","5678","asdf","zxcv"}
- };
- int current = 4;
- int ls;
- int admin_login();
- int student_login();
- void addBookinDataBase();
- void searchbook();
- void deletebook();
- void updatepassword();
- void login();
- int main() {
- welcomeMessage();
- login();
- admin_login();
- }
- void welcomeMessage()
- {
- cout << ("\n\n");
- cout << ("\n\t\t\t **************************************************");
- cout << ("\n\t\t\t * *");
- cout << ("\n\t\t\t * WELCOME *");
- cout << ("\n\t\t\t * TO *");
- cout << ("\n\t\t\t * LIBRARY *");
- cout << ("\n\t\t\t * *");
- cout << ("\n\t\t\t ****************************************************\n\n");
- }
- void login() {
- int choice;
- cout << "1. Admin Login" << endl;
- cout << "2. Student Login" << endl;
- cout << "3. Exit" << endl;
- cin >> choice;
- cout << endl;
- if (choice == 1) {
- cout << "Username: ";
- cin >> userName;
- cout << "Password: ";
- cin >> userPassword;
- for (int a = 0; a < current; a++)
- {
- if (login_details[0][a] == userName) {
- if (login_details[1][a] == userPassword) {
- cout << "\nWelcome " << login_details[0][a] << endl;
- cout << "\nThank you " << userName << " for logging in.\n";
- ls = 1;
- }
- }
- }
- while (ls == 0) {
- cout << "Login was unsuccessful please try again" << endl;
- login();
- }
- }
- else if (choice == 2) {
- cout << "Username: ";
- cin >> userName;
- cout << "Password: ";
- cin >> userPassword;
- for (int a = 0; a < current; a++)
- {
- if (login_details[0][a] == userName) {
- if (login_details[1][a] == userPassword) {
- cout << "\nWelcome " << login_details[0][a] << endl;
- cout << "\nThank you student for logging in.\n";
- ls = 1;
- }
- }
- }
- while (ls == 0) {
- cout << "Login was unsuccessful please try again" << endl;
- login();
- }
- }
- }
- int admin_login()
- {
- int choice;
- string bookid;
- string decision;
- string bookname;
- string line;
- string books[50];
- string book_id[50];
- fstream myfile;
- myfile.open("booksrecord.txt");
- int counter = 0;
- while (myfile >> bookid >> bookname)
- {
- books[counter] = bookname;
- book_id[counter] = bookid;
- counter++;
- }
- do {
- cout << "1.Add Book " << endl;
- cout << "2.Search Books " << endl;
- cout << "3.List Books " << endl;
- cout << "4.Delete Books " << endl;
- cout << "5.Update Password " << endl;
- cout << "6.Exit" << endl;
- cin >> choice;
- cout << endl;
- if (choice == 1) {
- cout << "Enter Book ID: " << endl;
- cout << "Yes or No" << endl;
- cin >> decision;
- if (decision == "Yes") {
- cout << " enter the book id";
- cin >> bookid;
- cout << "enter the book name";
- cin >> bookname;
- myfile << bookid << " " << bookname << endl;
- }
- }
- else if (choice == 2) {
- cout << "Enter the bookid: " << endl;
- }
- else if (choice == 3) {
- cout << "Book list: \n " << endl;
- for (int i = 0; i < 5; i++)
- {
- cout << book_id[i] << ". " << books[i] << endl;
- }
- }
- } while (choice != 0);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement