Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. // BankAccount.cpp
  2.  
  3. #include "BankAccount.h"
  4.  
  5. BankAccount::BankAccount(const string & actN, const string & fname, const string & lname, double bal) {
  6.     ActNum = actN;
  7.  
  8.     // Validate balance
  9.     if (bal < 0) {
  10.         cout << "Balance is invalid. Value cannot be negative." << endl;
  11.         balance = 0.0;
  12.     }
  13.     else {
  14.         balance = bal;
  15.     }
  16.  
  17.     FirstName = fname;
  18.     LastName = lname;
  19. }
  20.  
  21. const string BankAccount::toString() const {
  22.     ostringstream os;
  23.     os << fixed << showpoint << setprecision(2);
  24.     os << "Full Name: " << FirstName << " " << LastName << endl;
  25.     os << "Account Number: " << ActNum << endl;
  26.     os << "Balance: $" << setprecision(2) << fixed << balance << endl;
  27.     return os.str();
  28. }
  29.  
  30. void BankAccount::setAccountNumber(const string & actN) {
  31.     ActNum = actN;
  32. }
  33.  
  34. void BankAccount::deposit(double money) {
  35.     if (money < 0) {
  36.         cout << "Deposit amount was negative. It cannot be negative." << endl;
  37.     }
  38.     else {
  39.         balance += money;
  40.     }
  41. }
  42.  
  43. void BankAccount::withdraw(double money) {
  44.     if (balance >= money) {
  45.         balance -= money;
  46.     }
  47.     else {
  48.         cout << "Withdrawl amount exceeded available funds." << endl;
  49.     }
  50. }
  51.  
  52. void BankAccount::setLastName(const string & lname) {
  53.     LastName = lname;
  54. }
  55.  
  56. string BankAccount::getAccountNumber() const {
  57.     return ActNum;
  58. }
  59.  
  60. double BankAccount::getBalance() const {
  61.     return balance;
  62. }
  63.  
  64. const string BankAccount::getFirstName() const {
  65.     return FirstName;
  66. }
  67.  
  68. const string BankAccount::getLastName() const {
  69.     return LastName;
  70. }
  71.  
  72. const string BankAccount::getFullName() const {
  73.     return FirstName + " " + LastName;
  74. }
  75.  
  76. void BankAccount::print() const {
  77.     cout << "Full Name: " << FirstName << " " << LastName << endl;
  78.     cout << "Account Number: " << ActNum << endl;
  79.     cout << "Balance: $" << setprecision(2) << fixed << balance << endl;
  80. }
  81.  
  82. void BankAccount::print(ostream & out) const {
  83.     out << "Full Name: " << FirstName << " " << LastName << endl;
  84.     out << "Account Number: " << ActNum << endl;
  85.     out << "Balance: $" << setprecision(2) << fixed << balance << endl;
  86. }
  87.  
  88. void BankAccount::getInstance(BankAccount & BA)
  89. {
  90.     string actNum, fName, lName;
  91.     double bal;
  92.     cout << "Account Number: ";
  93.     cin >> actNum;
  94.     cout << "First Name: ";
  95.     cin >> fName;
  96.     cout << "Last Name: ";
  97.     cin >> lName;
  98.     cout << "Balance: $";
  99.     cin >> bal;
  100.  
  101.     BA = BankAccount(actNum, fName, lName, bal);
  102. }
  103.  
  104. void BankAccount::getInstance(BankAccount & BA, ifstream & in)
  105. {
  106.     string actNum, fName, lName;
  107.     double bal;
  108.     in >> actNum >> lName >> fName >> bal;
  109.  
  110.     BA = BankAccount(actNum, fName, lName, bal);
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement