Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <time.h>
  4. #include <cstdlib>
  5. #include "Savings.h"
  6. #include "Checking.h"
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     //Variables
  13.     double withdrawal;
  14.     double deposit;
  15.     int selection;
  16.     int account;
  17.     int month = 1;
  18.     double sbalanceAdded = 0.0;
  19.     double cbalanceAdded = 0.0;
  20.     double serviceCharge = 0.0;
  21.  
  22.     //Variables to generate day of banking month
  23.     int numDays = 0;
  24.     time_t seconds;
  25.     time(&seconds);
  26.     srand ((unsigned int) seconds);
  27.  
  28.     //Create an instance of Savings and Checking account objects
  29.     Savings *s = new Savings();
  30.     Checking *c = new Checking();
  31.  
  32.     cout << "This program simulates a bank account.\n\n";\
  33.     do{
  34.         //Combine the service charges of checking and savings
  35.         serviceCharge = (s->getServiceCharge() + c->getServiceCharge());
  36.  
  37.         cout << "\n\n*******************************************" << endl;
  38.         cout << "* Savings Account Balance..........$" << setprecision(2) << showpoint << fixed << s->getBalance() << "\n";
  39.         cout << "* Checking Account Balance.........$" << setprecision(2) << showpoint << fixed << c->getBalance() << "\n";
  40.         cout << "* Service Charges..................$" << setprecision(2) << serviceCharge << "\n";
  41.         cout << "*******************************************";
  42.         cout << "\nWhat would you like to do, enter a number 1-4:" << endl;
  43.         cout << "1. Deposit" << endl;
  44.         cout << "2. Withdraw" << endl;
  45.         cout << "3. Print monthly statement" << endl;
  46.         cout << "4. Quit" << endl;
  47.         cin >> selection;
  48.  
  49.         switch(selection)
  50.         {
  51.         ////////Deposit////////
  52.         case 1:
  53.             {
  54.             cout << endl << "Please select the account:\n1. Savings\n2. Checking\n" << endl;
  55.             cin >> account;
  56.             if (account == 1)
  57.             {
  58.                 cout << endl << "Please enter the amount to be deposited:" << endl;
  59.                 cin >> deposit;
  60.                 s->deposit(deposit);
  61.                 sbalanceAdded += deposit;
  62.                 cout << "You deposited " << deposit << " dollars into your savings account." << endl;
  63.  
  64.                 numDays += rand() % (7 - 1 + 1) +1;
  65.  
  66.                 if(numDays >= 31)
  67.                 {
  68.                     cout << "Monthly Service Charge.....$" << serviceCharge;
  69.                     s->setBeginningBalance(s->getBalance() - sbalanceAdded);
  70.                     s->monthEnd();
  71.                     s->setEndingBalance(s->getBalance());
  72.                     numDays -=31;
  73.                     sbalanceAdded = 0.0;
  74.                 }
  75.             }
  76.             if (account == 2)
  77.             {
  78.                 cout << endl << "Please enter the amount to be deposited:" << endl;
  79.                 cin >> deposit;
  80.                 c->deposit(deposit);
  81.                 cbalanceAdded += deposit;
  82.                 cout << "You deposited $" << deposit << " into your checking account." << endl;
  83.                 numDays += rand() % (7 - 1 + 1) +1;
  84.  
  85.                 if(numDays >= 31)
  86.                 {
  87.                     cout << "Monthly Service Charge.....$" << serviceCharge;
  88.                     c->setBeginningBalance(c->getBalance() - cbalanceAdded);
  89.                     c->setEndingBalance(c->getBalance());
  90.                     numDays -=31;
  91.                     c->monthEnd();
  92.                     cbalanceAdded = 0.0;
  93.                 }
  94.             }
  95.         break;
  96.             }
  97.         ////////Withdraw////////
  98.         case 2:
  99.             {
  100.                 cout << endl << "Please select the account:\n1. Savings\n2. Checking\n" << endl;
  101.                 cin >> account;
  102.  
  103.                 if (account == 1)
  104.                 {
  105.                     if (s->getBalance() >= 25.0)
  106.                     {
  107.                         cout << endl << "Please enter the amount to be withdrawn:" << endl;
  108.                         cin >> withdrawal;
  109.                         s->withdraw(withdrawal);
  110.                         sbalanceAdded -= withdrawal;
  111.                         cout << "You withdrew $" << withdrawal << " from your savings account." << endl;
  112.                     }
  113.                     else
  114.                         cout << "Account has insufficient funds." << endl;
  115.                     if (s->getNumWithdrawls()>4)
  116.                         s->monthlyProc();
  117.                     numDays += rand() % (7 - 1 + 1) + 1;
  118.  
  119.                     if (numDays >= 31 || (s->getNumDeposits() + c->getNumDeposits()) == 4)
  120.                     {
  121.  
  122.                         s->monthlyProc();
  123.                         cout << "Monthly Service Charge.....$" << setprecision(2) << serviceCharge;
  124.                         s->setBeginningBalance(s->getBalance() - sbalanceAdded);
  125.                         s->monthEnd();
  126.                         s->setEndingBalance(s->getBalance());
  127.                         numDays -= 31;
  128.                         sbalanceAdded = 0.0;
  129.                     }
  130.                 }
  131.                 if (account == 2)
  132.                 {
  133.  
  134.                     cout << endl << "Please enter the amount to be withdrawn:" << endl;
  135.                     cin >> withdrawal;
  136.  
  137.                         c->withdraw(withdrawal);
  138.  
  139.                         if((c->getBalance() - withdrawal) > 0)
  140.                         {
  141.                         cbalanceAdded -= withdrawal;
  142.                         cout << "You withdrew $" << withdrawal << " from your checking account." << endl;
  143.                         }
  144.  
  145.                     numDays += rand() % (7 - 1 + 1) +1;
  146.                     if(numDays >= 31 || (s->getNumDeposits() + c->getNumDeposits()) == 4)
  147.                     {
  148.                         c->monthlyProc();
  149.                         cout << "Monthly Service Charge.....$" << setprecision(2) << serviceCharge + 5.1;
  150.                         c->setBeginningBalance(c->getBalance() - cbalanceAdded);
  151.                         c->setEndingBalance(c->getBalance());
  152.                         numDays -=31;
  153.                         c->monthEnd();
  154.                         cbalanceAdded = 0.0;
  155.                     }
  156.                 }
  157.             break;
  158.             }
  159.  
  160.         ////////Print Monthly Bank Statement////////
  161.         case 3:
  162.             cout << "\n********Monthly Bank Statement********" << endl;
  163.             cout << "It is day number " << numDays << " of the current banking month." << endl;
  164.             cout << "* Savings Account Balance: $"  << s->getBalance() << "\n";
  165.             cout << "Previous Month Starting Balance $" << s->getBeginningBalance() << endl;
  166.             cout << "Previous Month Ending Balance $"<< s->getEndingBalance() << endl;
  167.             cout << "Savings Account Deposits " << s->getNumDeposits() << endl;
  168.             cout << "Savings Account Withdrawals " << s->getNumWithdrawls() << endl << endl;
  169.  
  170.             cout << "* Checking Account Balance: $"  <<   c->getBalance() << endl;
  171.             cout << "Previous Month Starting Balance: $"<< c->getBeginningBalance() << endl;
  172.             cout << "Previous Month Ending Balance: $" << c->getEndingBalance() << endl;
  173.             cout << "Checking Account Deposits: " << c->getNumDeposits() <<  endl;
  174.             cout << "Checking Account Withdrawals: " << c->getNumWithdrawls() << endl;
  175.             cout << "****************************************";
  176.  
  177.         break;
  178.  
  179.         ////////Quit////////
  180.         case 4:
  181.             cout << "Exiting program." << endl;
  182.             return 0;
  183.  
  184.         break;
  185.  
  186.         default:
  187.             cout << "Invalid selection.  Please choose an option 1-4." << endl;
  188.         }
  189.     } while (selection != 4);
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement