Advertisement
Guest User

account.cpp

a guest
Aug 3rd, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include "account.h"
  2.  
  3. using namespace std;
  4.  
  5. Account::Account(void) :balance(0)
  6. {
  7.  
  8. }
  9.  
  10. vector<string> Account::Report()
  11. {
  12.     vector<string> report;
  13.     report.push_back("Balance is " + to_string(balance));
  14.     report.push_back("Transactions: ");
  15.     for (auto t : log)
  16.     {
  17.         report.push_back(t.Report());
  18.     }
  19.     report.push_back("--------------------");
  20.  
  21.     return report;
  22. }
  23.  
  24. bool Account::deposit(int amt)
  25. {
  26.     if (amt >= 0)
  27.     {
  28.         balance += amt;
  29.         log.push_back(Transaction(amt, "Deposit"));
  30.         return true;
  31.     }
  32.     else
  33.     {
  34.         return false;
  35.     }
  36. }
  37. bool Account::withdraw(int amt)
  38. {
  39.     if (amt >= 0)
  40.     {
  41.         if (balance >= amt)
  42.         {
  43.             balance -= amt;
  44.             log.push_back(Transaction(amt, "Withdrawn"));
  45.             return true;
  46.         }
  47.         else
  48.         {
  49.             return false;
  50.         }
  51.     }
  52.     else
  53.     {
  54.         return false;
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement