You are on page 1of 3

#include <iostream>

using namespace std;


class BankAccount {
private:
double balance;
double interestRate;
double interestEarned;
int numTransactions;

public:
BankAccount(double initialBalance = 0.0, double initialInterestRate = 0.0) {
balance = initialBalance;
interestRate = initialInterestRate;
interestEarned = 0.0;
numTransactions = 0;
}

void showBalance() const {


cout << "Current balance: $" << balance << endl;
}

void showNumTransactions() const {


cout << "Number of transactions: " << numTransactions << endl;
}

void makeDeposit(double amount) {


balance += amount;
numTransactions++;
}

void withdraw(double amount) {


if (balance < amount) {
cout << "Error: Insufficient funds." << endl;
} else {
balance -= amount;
numTransactions++;
}
}

void addInterest() {
interestEarned = balance * interestRate;
balance += interestEarned;
numTransactions++;
}

void showInterest() const {


cout << "Interest earned: $" << interestEarned << endl;
}
};

int main() {
BankAccount myAccount(1000, 0.05);
int choice;

do {
cout << "Bank Account Management System" << endl;
cout << "------------------------------" << endl;
cout << "1. Balance Inquiry" << endl;
cout << "2. Show Number of Transactions" << endl;
cout << "3. Make a Deposit" << endl;
cout << "4. Withdraw Cash" << endl;
cout << "5. Add Interest" << endl;
cout << "6. Show Interest" << endl;
cout << "7. Exit" << endl;
cout << "Enter your choice (1-7): ";
cin >> choice;

switch (choice) {
case 1:
myAccount.showBalance();
break;

case 2:
myAccount.showNumTransactions();
break;

case 3:
double depositAmount;
cout << "Enter amount to deposit: $";
cin >> depositAmount;
myAccount.makeDeposit(depositAmount);
cout << "Deposit successful." << endl;
break;

case 4:
double withdrawAmount;
cout << "Enter amount to withdraw: $";
cin >> withdrawAmount;
myAccount.withdraw(withdrawAmount);
break;

case 5:
myAccount.addInterest();
cout << "Interest added." << endl;
break;

case 6:
myAccount.showInterest();
break;

case 7:
cout << "Thank you for using the Bank Account Management System." << endl;
break;

default:
cout << "Error: Invalid choice. Please enter a number between 1 and 7." << endl;
}
cout << endl;
} while (choice != 7);

return 0;
}

You might also like