namespace

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter8: Working With Advanced Functions
Section: Chapter Questions
Problem 4.3CP
icon
Related questions
Question

#include "Bank.h"

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int main() {
    Account** accounts = new Account * [10];
    ifstream infile;
    infile.open("bank2.txt");
    if ( !infile )
        cerr << "File cannot be opened" << endl;
    else
        cout << "File Opened" << endl;

    string operationType;
    int totalAccount = 0;

    while (infile >> operationType) {
        if (operationType == "Saving") {
            int id;
            double initialBalance, minimumBalance, annualInterestRate;
            infile >> id >> initialBalance >> minimumBalance >> annualInterestRate;
            Saving* savingAccount = new Saving();
            savingAccount->setInterest(annualInterestRate);
            savingAccount->setMinBalance(minimumBalance);
            accounts[totalAccount] = savingAccount;
            accounts[totalAccount]->setID(id);
            accounts[totalAccount]->setBalance(initialBalance);
            totalAccount++;
            cout << "Saving account number " << totalAccount << " created" << endl;
            cout << "with an initial balance of $" << accounts[totalAccount - 1]->getBalance() << endl;
        }
        else if (operationType == "Checking") {
            int id;
            double initialBalance, minimumBalance, monthlyFees;
            infile >> id >> initialBalance >> minimumBalance >> monthlyFees;
            Checking* checkingAccount = new Checking();
            checkingAccount->setMonthlyFee(monthlyFees);
            checkingAccount->setMinBalance(minimumBalance);
            accounts[totalAccount] = checkingAccount;
            accounts[totalAccount]->setID(id);
            accounts[totalAccount]->setBalance(initialBalance);
            totalAccount++;
            cout << "Checking account number " << totalAccount << " created" << endl;
            cout << "with an initial balance of $" << accounts[totalAccount - 1]->getBalance() << endl;
        }
        else if (operationType == "Deposit") {
            int id;
            double amount;
            int pos;
            bool isFound = false;
            infile >> id >> amount;
            for (int i = 0; i < totalAccount; i++) {
                if (accounts[i]->getID() == id) {
                    isFound = true;
                    accounts[i]->deposit(amount);
                    pos = i;
                }
            }
            if (!isFound) {
                cout << "Invalid Account Number - " << id << endl;
            }
            else {
                cout << "Deposited $" << amount << " into account #" << id << endl;
                cout << "current balance is $" << accounts[pos]->getBalance() << endl;
            }
        }
        else if (operationType == "Withdraw") {
            int id;
            double amount;
            int pos;
            infile >> id >> amount;
            bool isFound = false;
            for (int i = 0; i < totalAccount; i++) {
                if (accounts[i]->getID() == id) {
                    isFound = true;
                    accounts[i]->withdraw(amount);
                    pos = i;
                }
            }
            if (!isFound) {
                cout << "Invalid Account Number - " << id << endl;
            }
            else {
                cout << "Withdraw $" << amount << " from account #" << id << endl;
                cout << "current balance is $" << accounts[pos]->getBalance() << endl;
            }
        }
        else if (operationType == "Balance") {
            int id;
            infile >> id;
            int pos;
            bool isFound = false;
            for (int i = 0; i < totalAccount; i++) {
                if (accounts[i]->getID() == id) {
                    isFound = true;
                    cout << "current balance in account #" << id << " is $" << accounts[i]->getBalance() << endl;
                    pos = i;
                }
            }
            if (!isFound) {
                cout << "Invalid Account Number - " << id << endl;
            }
        }
        else if (operationType == "Close") {
            cout << "End of month processing complete" << endl;
            for (int i = 0; i < totalAccount; i++) {
                accounts[i]->closeMonth();
            }
        }
        else if (operationType == "Report") {
            for (int i = 0; i < totalAccount; i++) {
                cout << accounts[i]->accountString() << endl;
            }
        }
        else {
            cout << "Unrecognised command - " << operationType << endl;
            string dummyLine;
            getline(infile, dummyLine);
        }
    }
    infile.close();
}

This does not handle the end of month
processing correctly. The monthly fee should
only be deducted if the balance is below the
minimm. Similarly, the interest should only be
added if the balance is above the minimum.
Please correct and resubmit.
Transcribed Image Text:This does not handle the end of month processing correctly. The monthly fee should only be deducted if the balance is below the minimm. Similarly, the interest should only be added if the balance is above the minimum. Please correct and resubmit.
End of month processing complete
Saving account a1 has balance of $1014.390067
Checking account a2 has balance of $2015.090000
Saving account a3 has balance of $3051.054600
Checking account a4 has balance of $3987.65000
Transcribed Image Text:End of month processing complete Saving account a1 has balance of $1014.390067 Checking account a2 has balance of $2015.090000 Saving account a3 has balance of $3051.054600 Checking account a4 has balance of $3987.65000
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Module hierarchy chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage