fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Book {
  6. public:
  7. string id, name;
  8. bool issue = false;
  9.  
  10. Book(string i, string n) {
  11. id = i;
  12. name = n;
  13. }
  14. };
  15.  
  16. vector<Book> b = {
  17. {"B001","C++"},
  18. {"B002","Java"},
  19. {"B003","Python"}
  20. };
  21.  
  22. #define RED "\033[31m"
  23. #define GREEN "\033[32m"
  24. #define BLUE "\033[34m"
  25. #define CYAN "\033[36m"
  26. #define YELLOW "\033[33m"
  27. #define RESET "\033[0m"
  28.  
  29. int main() {
  30.  
  31. string u, p, id;
  32. int ch;
  33.  
  34. // COLORFUL LOGIN PAGE
  35. cout << CYAN;
  36. cout << "\n****************************************\n";
  37. cout << "* LIBRARY MANAGEMENT SYSTEM *\n";
  38. cout << "****************************************\n";
  39. cout << RESET;
  40.  
  41. cout << BLUE << "\n========== LOGIN PAGE ==========\n" << RESET;
  42.  
  43. cout << YELLOW << "Username : " << RESET;
  44. cin >> u;
  45.  
  46. cout << YELLOW << "Password : " << RESET;
  47. cin >> p;
  48.  
  49. if(u != "admin" || p != "1234") {
  50. cout << RED << "\nWrong Login!\n" << RESET;
  51. return 0;
  52. }
  53.  
  54. cout << GREEN << "\nLogin Successful!\n" << RESET;
  55.  
  56. // MENU
  57. cout << CYAN;
  58. cout << "\n1. View Books";
  59. cout << "\n2. Issue Book";
  60. cout << "\n3. Return Book";
  61. cout << "\n4. Exit\n";
  62. cout << RESET;
  63.  
  64. while(true) {
  65.  
  66. cout << "\nEnter Choice: ";
  67. cin >> ch;
  68.  
  69. if(ch == 1) {
  70.  
  71. cout << "\n--- BOOKS ---\n";
  72.  
  73. for(auto x : b) {
  74. cout << x.id << " - " << x.name;
  75.  
  76. if(x.issue)
  77. cout << RED << " (Issued)";
  78.  
  79. cout << RESET << endl;
  80. }
  81. }
  82.  
  83. else if(ch == 2) {
  84.  
  85. cout << "Enter Book ID: ";
  86. cin >> id;
  87.  
  88. for(auto &x : b) {
  89. if(x.id == id) {
  90. x.issue = true;
  91. cout << GREEN << "Book Issued!\n" << RESET;
  92. }
  93. }
  94. }
  95.  
  96. else if(ch == 3) {
  97.  
  98. cout << "Enter Book ID: ";
  99. cin >> id;
  100.  
  101. for(auto &x : b) {
  102. if(x.id == id) {
  103. x.issue = false;
  104. cout << GREEN << "Book Returned!\n" << RESET;
  105. }
  106. }
  107. }
  108.  
  109. else if(ch == 4) {
  110. cout << RED << "Good Bye!\n" << RESET;
  111. break;
  112. }
  113.  
  114. else {
  115. cout << RED << "Invalid Choice!\n" << RESET;
  116. }
  117. }
  118.  
  119. return 0;
  120. }
  121.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout

****************************************
*      LIBRARY MANAGEMENT SYSTEM       *
****************************************

========== LOGIN PAGE ==========
Username : Password : 
Wrong Login!