Memory.cpp
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class Bank { 6 private: 7 int accountNumber; 8 string accountHolderName; 9 double balance; 10 11 public: 12 void openAccount() { 13 cout << "Enter Account Number: "; 14 cin >> accountNumber; 15 cout << "Enter Account Holder Name: "; 16 cin.ignore(); 17 getline(cin, accountHolderName); 18 cout << "Enter Opening Balance: "; 19 cin >> balance; 20 } 21 22 void showAccount() { 23 cout << "Account Number: " << accountNumber << endl; 24 cout << "Account Holder Name: " << accountHolderName << endl; 25 cout << "Balance: " << balance << endl; 26 } 27 28 void deposit() { 29 double amount; 30 cout << "Enter Amount to Deposit: "; 31 cin >> amount; 32 balance += amount; 33 cout << "Amount Deposited Successfully!" << endl; 34 } 35 36 void withdraw() { 37 double amount; 38 cout << "Enter Amount to Withdraw: "; 39 cin >> amount; 40 if (amount > balance) { 41 cout << "Insufficient Balance!" << endl; 42 } else { 43 balance -= amount; 44 cout << "Amount Withdrawn Successfully!" << endl; 45 } 46 } 47 48 bool search(int accNumber) { 49 return accountNumber == accNumber; 50 } 51 }; 52 53 int main() { 54 Bank accounts[5]; 55 int choice, accNumber, found = 0; 56 57 while (true) { 58 cout << "\nBank Management System" << endl; 59 cout << "1. Open Account" << endl; 60 cout << "2. Show Account Info" << endl; 61 cout << "3. Deposit" << endl; 62 cout << "4. Withdraw" << endl; 63 cout << "5. Search Account" << endl; 64 cout << "6. Exit" << endl; 65 cout << "Enter Your Choice: "; 66 cin >> choice; 67 68 switch (choice) { 69 case 1: 70 for (int i = 0; i < 5; i++) { 71 cout << "\nOpening Account " << (i + 1) << ":" << endl; 72 accounts[i].openAccount(); 73 } 74 break; 75 case 2: 76 for (int i = 0; i < 5; i++) { 77 cout << "\nAccount Info " << (i + 1) << ":" << endl; 78 accounts[i].showAccount(); 79 } 80 break; 81 case 3: 82 cout << "Enter Account Number to Deposit: "; 83 cin >> accNumber; 84 for (int i = 0; i < 5; i++) { 85 if (accounts[i].search(accNumber)) { 86 accounts[i].deposit(); 87 found = 1; 88 break; 89 } 90 } 91 if (!found) cout << "Account Not Found!" << endl; 92 break; 93 case 4: 94 cout << "Enter Account Number to Withdraw: "; 95 cin >> accNumber; 96 for (int i = 0; i < 5; i++) { 97 if (accounts[i].search(accNumber)) { 98 accounts[i].withdraw(); 99 found = 1; 100 break; 101 } 102 } 103 if (!found) cout << "Account Not Found!" << endl; 104 break; 105 case 5: 106 cout << "Enter Account Number to Search: "; 107 cin >> accNumber; 108 for (int i = 0; i < 5; i++) { 109 if (accounts[i].search(accNumber)) { 110 accounts[i].showAccount(); 111 found = 1; 112 break; 113 } 114 } 115 if (!found) cout << "Account Not Found!" << endl; 116 break; 117 case 6: 118 exit(0); 119 default: 120 cout << "Invalid Choice!" << endl; 121 } 122 } 123 124 return 0; 125 }