Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <time.h>
- #include <cstdlib>
- #include "Savings.h"
- #include "Checking.h"
- using namespace std;
- int main()
- {
- //Variables
- double withdrawal;
- double deposit;
- int selection;
- int account;
- int month = 1;
- double sbalanceAdded = 0.0;
- double cbalanceAdded = 0.0;
- double serviceCharge = 0.0;
- //Variables to generate day of banking month
- int numDays = 0;
- time_t seconds;
- time(&seconds);
- srand ((unsigned int) seconds);
- //Create an instance of Savings and Checking account objects
- Savings *s = new Savings();
- Checking *c = new Checking();
- cout << "This program simulates a bank account.\n\n";\
- do{
- //Combine the service charges of checking and savings
- serviceCharge = (s->getServiceCharge() + c->getServiceCharge());
- cout << "\n\n*******************************************" << endl;
- cout << "* Savings Account Balance..........$" << setprecision(2) << showpoint << fixed << s->getBalance() << "\n";
- cout << "* Checking Account Balance.........$" << setprecision(2) << showpoint << fixed << c->getBalance() << "\n";
- cout << "* Service Charges..................$" << setprecision(2) << serviceCharge << "\n";
- cout << "*******************************************";
- cout << "\nWhat would you like to do, enter a number 1-4:" << endl;
- cout << "1. Deposit" << endl;
- cout << "2. Withdraw" << endl;
- cout << "3. Print monthly statement" << endl;
- cout << "4. Quit" << endl;
- cin >> selection;
- switch(selection)
- {
- ////////Deposit////////
- case 1:
- {
- cout << endl << "Please select the account:\n1. Savings\n2. Checking\n" << endl;
- cin >> account;
- if (account == 1)
- {
- cout << endl << "Please enter the amount to be deposited:" << endl;
- cin >> deposit;
- s->deposit(deposit);
- sbalanceAdded += deposit;
- cout << "You deposited " << deposit << " dollars into your savings account." << endl;
- numDays += rand() % (7 - 1 + 1) +1;
- if(numDays >= 31)
- {
- cout << "Monthly Service Charge.....$" << serviceCharge;
- s->setBeginningBalance(s->getBalance() - sbalanceAdded);
- s->monthEnd();
- s->setEndingBalance(s->getBalance());
- numDays -=31;
- sbalanceAdded = 0.0;
- }
- }
- if (account == 2)
- {
- cout << endl << "Please enter the amount to be deposited:" << endl;
- cin >> deposit;
- c->deposit(deposit);
- cbalanceAdded += deposit;
- cout << "You deposited $" << deposit << " into your checking account." << endl;
- numDays += rand() % (7 - 1 + 1) +1;
- if(numDays >= 31)
- {
- cout << "Monthly Service Charge.....$" << serviceCharge;
- c->setBeginningBalance(c->getBalance() - cbalanceAdded);
- c->setEndingBalance(c->getBalance());
- numDays -=31;
- c->monthEnd();
- cbalanceAdded = 0.0;
- }
- }
- break;
- }
- ////////Withdraw////////
- case 2:
- {
- cout << endl << "Please select the account:\n1. Savings\n2. Checking\n" << endl;
- cin >> account;
- if (account == 1)
- {
- if (s->getBalance() >= 25.0)
- {
- cout << endl << "Please enter the amount to be withdrawn:" << endl;
- cin >> withdrawal;
- s->withdraw(withdrawal);
- sbalanceAdded -= withdrawal;
- cout << "You withdrew $" << withdrawal << " from your savings account." << endl;
- }
- else
- cout << "Account has insufficient funds." << endl;
- if (s->getNumWithdrawls()>4)
- s->monthlyProc();
- numDays += rand() % (7 - 1 + 1) + 1;
- if (numDays >= 31 || (s->getNumDeposits() + c->getNumDeposits()) == 4)
- {
- s->monthlyProc();
- cout << "Monthly Service Charge.....$" << setprecision(2) << serviceCharge;
- s->setBeginningBalance(s->getBalance() - sbalanceAdded);
- s->monthEnd();
- s->setEndingBalance(s->getBalance());
- numDays -= 31;
- sbalanceAdded = 0.0;
- }
- }
- if (account == 2)
- {
- cout << endl << "Please enter the amount to be withdrawn:" << endl;
- cin >> withdrawal;
- c->withdraw(withdrawal);
- if((c->getBalance() - withdrawal) > 0)
- {
- cbalanceAdded -= withdrawal;
- cout << "You withdrew $" << withdrawal << " from your checking account." << endl;
- }
- numDays += rand() % (7 - 1 + 1) +1;
- if(numDays >= 31 || (s->getNumDeposits() + c->getNumDeposits()) == 4)
- {
- c->monthlyProc();
- cout << "Monthly Service Charge.....$" << setprecision(2) << serviceCharge + 5.1;
- c->setBeginningBalance(c->getBalance() - cbalanceAdded);
- c->setEndingBalance(c->getBalance());
- numDays -=31;
- c->monthEnd();
- cbalanceAdded = 0.0;
- }
- }
- break;
- }
- ////////Print Monthly Bank Statement////////
- case 3:
- cout << "\n********Monthly Bank Statement********" << endl;
- cout << "It is day number " << numDays << " of the current banking month." << endl;
- cout << "* Savings Account Balance: $" << s->getBalance() << "\n";
- cout << "Previous Month Starting Balance $" << s->getBeginningBalance() << endl;
- cout << "Previous Month Ending Balance $"<< s->getEndingBalance() << endl;
- cout << "Savings Account Deposits " << s->getNumDeposits() << endl;
- cout << "Savings Account Withdrawals " << s->getNumWithdrawls() << endl << endl;
- cout << "* Checking Account Balance: $" << c->getBalance() << endl;
- cout << "Previous Month Starting Balance: $"<< c->getBeginningBalance() << endl;
- cout << "Previous Month Ending Balance: $" << c->getEndingBalance() << endl;
- cout << "Checking Account Deposits: " << c->getNumDeposits() << endl;
- cout << "Checking Account Withdrawals: " << c->getNumWithdrawls() << endl;
- cout << "****************************************";
- break;
- ////////Quit////////
- case 4:
- cout << "Exiting program." << endl;
- return 0;
- break;
- default:
- cout << "Invalid selection. Please choose an option 1-4." << endl;
- }
- } while (selection != 4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement