#include <iostream>
#include <string>
class BankAccount {
private:
std::string accountHolder;
double balance;
public:
BankAccount(const std::string& name, double initialBalance)
: accountHolder(name), balance(initialBalance) {}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
std::cout << "Deposited: $" << amount << std::endl;
}
}
void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
std::cout << "Withdrawn: $" << amount << std::endl;
} else {
std::cout << "Insufficient funds or invalid amount" << std::endl;
}
}
void displayBalance() const {
std::cout << "Account Holder: " << accountHolder << std::endl;
std::cout << "Current Balance: $" << balance << std::endl;
}
};
int main() {
BankAccount account("John Doe", 1000.0);
account.deposit(500.0);
account.withdraw(200.0);
account.displayBalance();
// account.balance = 1000000; // This would cause a compilation error
return 0;
}