Advertisement
benshepherd

Untitled

Dec 9th, 2019
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7.  
  8. void welcomeMessage();
  9. string userName;
  10. string userPassword;
  11. string login_details[2][100] = {
  12.   {"Kevin","Myra","Usman","Latif"},
  13.   {"1234","5678","asdf","zxcv"}
  14. };
  15. int current = 4;
  16. int ls;
  17. int admin_login();
  18. int student_login();
  19. void addBookinDataBase();
  20. void searchbook();
  21. void deletebook();
  22. void updatepassword();
  23. void login();
  24.  
  25. int main() {
  26.     welcomeMessage();
  27.     login();
  28.     admin_login();
  29. }
  30. void welcomeMessage()
  31. {
  32.     cout << ("If require assist please contact: [email protected]");
  33.     cout << ("\n\n");
  34.     cout << ("\n\t\t\t  **************************************************");
  35.     cout << ("\n\t\t\t  *                                                  *");
  36.     cout << ("\n\t\t\t  *                     WELCOME                      *");
  37.     cout << ("\n\t\t\t  *                       TO                         *");
  38.     cout << ("\n\t\t\t  *                     LIBRARY                      *");
  39.     cout << ("\n\t\t\t  *                                                  *");
  40.     cout << ("\n\t\t\t  ****************************************************\n\n");
  41. }
  42.  
  43. void login() {
  44.     int choice;
  45.     cout << "1. Admin Login" << endl;
  46.     cout << "2. Student Login" << endl;
  47.     cout << "3. Exit" << endl;
  48.     cin >> choice;
  49.     cout << endl;
  50.     if (choice == 1) {
  51.         cout << "Username: ";
  52.         cin >> userName;
  53.         cout << "Password: ";
  54.         cin >> userPassword;
  55.         for (int a = 0; a < current; a++)
  56.         {
  57.             if (login_details[0][a] == userName) {
  58.                 if (login_details[1][a] == userPassword) {
  59.                     cout << "\nWelcome " << login_details[0][a] << endl;
  60.                     cout << "\nThank you " << userName << " for logging in.\n";
  61.                     ls = 1;
  62.                 }
  63.             }
  64.         }
  65.         while (ls == 0) {
  66.             cout << "Login was unsuccessful please try again" << endl;
  67.             login();
  68.         }
  69.     }
  70.     else if (choice == 2) {
  71.         cout << "Username: ";
  72.         cin >> userName;
  73.         cout << "Password: ";
  74.         cin >> userPassword;
  75.         for (int a = 0; a < current; a++)
  76.         {
  77.             if (login_details[0][a] == userName) {
  78.                 if (login_details[1][a] == userPassword) {
  79.                     cout << "\nWelcome " << login_details[0][a] << endl;
  80.                     cout << "\nThank you student for logging in.\n";
  81.                     ls = 1;
  82.                 }
  83.             }
  84.         }
  85.         while (ls == 0) {
  86.             cout << "Login was unsuccessful please try again" << endl;
  87.             login();
  88.         }
  89.     }
  90.  
  91. }
  92. int admin_login()
  93. {
  94.     int choice;
  95.     string bookid;
  96.     string decision;
  97.     string bookname;
  98.     string line;
  99.     string books[50];
  100.     string book_id[50];
  101.     fstream myfile;
  102.     myfile.open("booksrecord.txt");
  103.     int counter = 0;
  104.     while (myfile >> bookid >> bookname)
  105.     {
  106.         books[counter] = bookname;
  107.         book_id[counter] = bookid;
  108.         counter++;
  109.     }
  110.     do {
  111.         cout << "1.Add Book " << endl;
  112.         cout << "2.Search Books " << endl;
  113.         cout << "3.List Books " << endl;
  114.         cout << "4.Delete Books " << endl;
  115.         cout << "5.Update Password " << endl;
  116.         cout << "6.Exit" << endl;
  117.         cin >> choice;
  118.         cout << endl;
  119.  
  120.         if (choice == 1) {
  121.             cout << "Enter Book ID: " << endl;
  122.             cout << "Yes or No" << endl;
  123.             cin >> decision;
  124.             if (decision == "Yes") {
  125.                 cout << " enter the book id";
  126.                 cin >> bookid;
  127.                 cout << "enter the book name";
  128.                 cin >> bookname;
  129.  
  130.                 myfile << bookid << " " << bookname << endl;
  131.             }
  132.         }
  133.         else if (choice == 2) {
  134.             cout << "Enter the bookid: " << endl;
  135.  
  136.         }
  137.         else if (choice == 3) {
  138.             cout << "Book list: \n " << endl;
  139.             for (int i = 0; i < 5; i++)  
  140.             {
  141.                 cout << book_id[i] << ". " << books[i] << endl;
  142.             }
  143.            
  144.         }
  145.  
  146.     } while (choice != 0);
  147.  
  148.     system("pause");
  149.     return 0;
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement