Advertisement
lokhun

Untitled

Feb 3rd, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <string>
  2.  
  3. class Account {
  4. public:
  5.  
  6.    Account(std::string accountName, int initialBalance)
  7.       : name{accountName} {
  8.  
  9.       if (initialBalance > 0) {
  10.          balance = initialBalance;
  11.       }
  12.    }
  13.  
  14.    void deposit(int depositAmount) {
  15.       if (depositAmount > 0) {
  16.          balance = balance + depositAmount;
  17.       }
  18.    }
  19.  
  20.    void withdraw(int withdrawAmount){
  21.       if (withdrawAmount <= balance)
  22.          balance = balance - withdrawAmount;
  23.  
  24.       if (withdrawAmount > balance)
  25.       std::cout << "\nWithdrawal amount exceeded account balance."<< std::endl;
  26.  
  27.    }
  28.  
  29.    int getBalance() const {
  30.       return balance;
  31.    }
  32.  
  33.    void setName(std::string accountName) {
  34.       name = accountName;
  35.    }
  36.  
  37.    std::string getName() const {
  38.       return name;
  39.    }
  40. private:
  41.    std::string name;
  42.    int balance{0};
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement