Professional Documents
Culture Documents
public:
BankAccount(double initialBalance = 0.0, double initialInterestRate = 0.0) {
balance = initialBalance;
interestRate = initialInterestRate;
interestEarned = 0.0;
numTransactions = 0;
}
void addInterest() {
interestEarned = balance * interestRate;
balance += interestEarned;
numTransactions++;
}
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;
}