Untitled
bilalahmad
plain_text
a month ago
1.2 kB
2
Indexable
#include <iostream> #include <string> using namespace std; class BankAccount { private: string depositorName; int accountNumber; string accountType; float balance; public: BankAccount(string name, int accNum, string type, float initialBalance) { depositorName = name; accountNumber = accNum; accountType = type; balance = initialBalance; } void deposit(float amount) { balance += amount; } void withdraw(float amount) { if (amount <= balance) { balance -= amount; } else { cout << "Insufficient balance!" << endl; } } void display() { cout << "Name: " << depositorName << endl; cout << "Balance: " << balance << endl; } }; int main() { BankAccount account("Sadia", 12345, "Savings", 1000.0); account.display(); account.deposit(500.0); cout << "After depositing 500:" << endl; account.display(); account.withdraw(200.0); cout << "After withdrawing 200:" << endl; account.display(); account.withdraw(2000.0); cout << "After attempting to withdraw 2000:" << endl; account.display(); return 0; }
Editor is loading...
Leave a Comment