@@ -9,27 +9,43 @@ class BankAccount {
99
1010public:
1111 // Constructor
12- BankAccount (){
13- // TODO: Implement the constructor
12+ BankAccount () : accountNumber( " " ), accountHolderName( " " ), balance( 0.0 ) {
13+ // Default initialization for an empty account
1414 }
1515
16- BankAccount (const std::string& accNumber, const std::string& accHolder, double initialBalance){
17- // TODO: Implement the constructor
16+ BankAccount (const std::string& accNumber, const std::string& accHolder, double initialBalance)
17+ : accountNumber(accNumber), accountHolderName(accHolder), balance(initialBalance) {
18+ // Constructor initializes the account with the provided values
1819 }
1920
2021 // Deposit method
2122 void Deposit (double amount) {
2223 // TODO: Implement the Deposit method
24+ if (amount > 0 ){
25+ balance += amount;
26+ std::cout << " Deposited " << amount << " to the account.\n " ;
27+ } else {
28+ std::cout << " Deposit amount must be positive.\n " ;
29+ }
2330 }
2431
2532 // Withdraw method
2633 void Withdraw (double amount) {
2734 // TODO: Implement the Deposit method
35+ if (amount <= balance){
36+ balance -= amount;
37+ std::cout << " Withdrew " << amount << " from the account.\n " ;
38+ } else {
39+ std::cout << " Insufficient balance for withdrawal.\n " ;
40+ }
2841 }
2942
3043 // Display account information
3144 void DisplayAccountInfo () {
3245 // TODO: Implement the DisplayAccountInfo method
46+ std::cout << " Account Number: " << accountNumber << std::endl;
47+ std::cout << " Account Holder: " << accountHolderName << std::endl;
48+ std::cout << " Balance: " << balance << std::endl;
3349 }
3450
3551 double GetBalance () const {
0 commit comments