Oop Project of 221740, 46,13,19
Oop Project of 221740, 46,13,19
Submitted To:
Prof. Sami Ullah
Submitted By:
Barra Fatima 221740
Mian Hamad Saeed 221746
Huzaifa Akhtar 221713
Rana Zaid 221719
3rd Semester
Department of Computer Science
Topic:
Bank Management System
Source Code:
#include <iostream>
#include <vector>
#include <string>
class BankAccount {
public:
int accountNumber;
string accountHolder;
double balance;
// Constructor
BankAccount(int accNumber, const string& accHolder, double initialBalance)
: accountNumber(accNumber), accountHolder(accHolder), balance(initialBalance) {}
// Member functions
void deposit(double amount) {
balance += amount;
cout << "Amount deposited successfully!" << endl;
}
class BankManagementSystem {
private:
vector<BankAccount> accounts;
public:
int getAccountIndex(int accountNumber) {
for (int i = 0; i < accounts.size(); ++i) {
if (accounts[i].accountNumber == accountNumber) {
return i;
}
}
return -1;
}
void createAccount() {
int accNumber;
string accHolder;
double initialBalance;
if (accountIndex != -1) {
cout << "Enter amount to " << action << ": ";
cin >> amount;
if (action == "deposit") {
accounts[accountIndex].deposit(amount);
} else if (action == "withdraw") {
accounts[accountIndex].withdraw(amount);
}
} else {
cout << "Account not found!" << endl;
}
}
void balanceInquiry() {
int accountNumber;
if (accountIndex != -1) {
accounts[accountIndex].displayBalance();
} else {
cout << "Account not found!" << endl;
}
}
void accountHolderList() {
cout << "----- Account Holder List -----" << endl;
cout << "Account No.\tAccount Holder\tBalance" << endl;
void closeAccount() {
int accountNumber;
if (accountIndex != -1) {
accounts.erase(accounts.begin() + accountIndex);
cout << "Account closed successfully!" << endl;
} else {
cout << "Account not found!" << endl;
}
}
void modifyAccount() {
int accountNumber;
if (accountIndex != -1) {
cout << "Enter new account holder name: ";
cin.ignore();
getline(cin, accounts[accountIndex].accountHolder);
cout << "Account modified successfully!" << endl;
} else {
cout << "Account not found!" << endl;
}
}
};
int main() {
BankManagementSystem bankSystem;
int choice;
while (true) {
cout << "----- Bank Management System -----" << endl;
cout << "1. New Account" << endl;
cout << "2. Deposit Amount" << endl;
cout << "3. Withdraw Amount" << endl;
cout << "4. Balance Inquiry" << endl;
cout << "5. All Account Holder List" << endl;
cout << "6. Close an Account" << endl;
cout << "7. Modify an Account" << endl;
cout << "8. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
bankSystem.createAccount();
break;
case 2:
bankSystem.performTransaction("deposit");
break;
case 3:
bankSystem.performTransaction("withdraw");
break;
case 4:
bankSystem.balanceInquiry();
break;
case 5:
bankSystem.accountHolderList();
break;
case 6:
bankSystem.closeAccount();
break;
case 7:
bankSystem.modifyAccount();
break;
case 8:
cout << "Exiting... Thank you!" << endl;
return 0;
default:
cout << "Invalid choice! Please try again." << endl;
}
START
WHILE
TR
TRUE
CHOICE
CASE 2
performTransaction
BREAK
("deposit")
performTransaction BREAK
CASE 3
("withdraw")