Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4542362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:22:45+00:00 2026-05-21T15:22:45+00:00

I am working on an assignment that uses a base class bankAccount and two

  • 0

I am working on an assignment that uses a base class “bankAccount” and two derived classes “checkingAccount” and “savingsAccount”. I am currently bewildered at the output I am getting. all of the ending balances are ending up negative. Could anyone take a look at my code and see if they spot why this might be? I presume I am doing something wrong in the process function of the derived class “checkingAccount”. “savingsAccount” process function will be similar I just haven’t made it yet cause the first one isn’t working. thanks!

header:

#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED

#include <iostream>
#include <fstream>


using namespace std;

class bankAccount
{
    public:
    bankAccount();
    void setAccountInfo(int accountNumTemp, double balanceTemp);
    void prePrint(char accountType);
    void process(char accountType, char transactionTypeTemp, int amountTemp, int j);
    void postPrint();

    private:
    int accountNumber;
    double balance;
};

class checkingAccount: public bankAccount
{
    public:
    void prePrint(int accountNumber, char accountType, double checkingBalance);
    checkingAccount();
    double checkingAccount:: process(char transactionTypeTemp, int amountTemp, int j, double checkingBalance);
    /*applyTansaction();
    applyInterest();*/

    private:
    float interestRate;
    int minimumBalance;
    float serviceCharge;

};

class savingsAccount: public bankAccount
{
    public:
    void prePrint(int savingsAccountNumber, char accountType, double savingsBalance);
    savingsAccount();
   /* applyTansaction();
    applyInterest();*/

    private:
    float interestRate;
};


#endif // HEADER_H_INCLUDED

class Implementation:

#include "header.h"

bankAccount:: bankAccount()
{
    accountNumber = 0;
    balance = 0;
}

void bankAccount:: setAccountInfo(int accountNumTemp, double balanceTemp)
{
    accountNumber = accountNumTemp;
    balance = balanceTemp;
}

void bankAccount:: prePrint(char accountType)
{
    if(accountType == 'C')
    {
        int checkingAccountNumber = accountNumber;
        double checkingBalance = balance;
        checkingAccount ca;
        ca.prePrint(checkingAccountNumber, accountType, checkingBalance);
    }
    else if (accountType == 'S')
    {
        int savingsAccountNumber = accountNumber;
        double savingsBalance = balance;
        savingsAccount sa;
        sa.prePrint(savingsAccountNumber, accountType, savingsBalance);
    }


}

void bankAccount:: process(char accountType, char transactionTypeTemp, int amountTemp, int j)
{
        double checkingBalance;
        checkingAccount ca;
        //savingsAccount sa;

        if (accountType == 'C')
        {
            checkingBalance = balance;
            balance = ca.process(transactionTypeTemp, amountTemp, j, checkingBalance);
        }
        /*else if (accountType == 'S')
        {
            savingsBalance = balance;
            sa.process(transactionTypeTemp, amountTemp, j, savingsBalance)
        }*/

}

void bankAccount:: postPrint()
{
   cout << "Balance after processing: " << balance << endl;
}

checkingAccount:: checkingAccount()
{
    interestRate = .02;
    minimumBalance = 500;
    serviceCharge = 20;
}

void checkingAccount:: prePrint(int checkingAccountNumber, char accountType, double checkingBalance)
{
    cout << "Account Number:" << checkingAccountNumber << " account type:" << accountType << " Starting Balance:" << checkingBalance << endl;
}

double checkingAccount:: process(char transactionTypeTemp, int amountTemp, int j, double checkingBalance)
{
  if (transactionTypeTemp == 'D')
        {
            checkingBalance = checkingBalance + amountTemp;
            checkingBalance = (checkingBalance * interestRate);
        }
  else if (transactionTypeTemp == 'W')
        {
            if ((checkingBalance = checkingBalance - amountTemp) < 0)
            {
            cout << "error: transaction number" << j + 1 << " never occured due to insufficent funds." << endl;
            }
            else
            {
                checkingBalance = checkingBalance - amountTemp;
                if(checkingBalance < minimumBalance) //if last transaction brought the balance below minimum balance
                {
                    checkingBalance = (checkingBalance - serviceCharge); //apply service charge
                    checkingBalance = (checkingBalance * interestRate);  //apply interest

                }
                else // if last transaction did not bring the balance below minimum balance
                {
                    checkingBalance = (checkingBalance * interestRate); //apply interest without service charge
                }
            }
        }

        return checkingBalance;
}

savingsAccount:: savingsAccount()
{
    interestRate = .04;
}

void savingsAccount:: prePrint(int savingsAccountNumber, char accountType, double savingsBalance)
{
    cout << "Account Number:" << savingsAccountNumber << " account type:" << accountType << " Starting Balance:" << savingsBalance << endl;
}

main:

#include "header.h"

int main()
{
    ifstream inFile;
    int numberOfAccounts, accountNumTemp, transactionNum, amountTemp;
    double balanceTemp;
    char discard, accountType, transactionTypeTemp;
    bankAccount ba;

    cout << "Processing account data..." << endl;

    inFile.open("Bank.txt");

    if (!inFile)
    {
        for  (int a = 0; a < 20; a++)
            cout  << endl;
        cout << "Cannot open the input file."
             << endl;
            return 1;
    }

    inFile >> numberOfAccounts;
    inFile.get(discard);

    for (int i = 0; i < numberOfAccounts; i++)
    {
            inFile >> accountNumTemp >> accountType >> balanceTemp >> transactionNum;
            inFile.get(discard);
            ba.setAccountInfo(accountNumTemp, balanceTemp);
            ba.prePrint(accountType);

            for (int j = 0; j < transactionNum; j++)
            {
                inFile >> transactionTypeTemp >> amountTemp;
                inFile.get(discard);
                ba.process(accountType, transactionTypeTemp, amountTemp, j);
            }

            ba.postPrint();

    }


    inFile.close();

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:22:46+00:00Added an answer on May 21, 2026 at 3:22 pm

    I’m actually working for a bank, so I couldn’t leave this. 🙂

    Adding to your problems:

    if (transactionTypeTemp == 'D')
    {
         checkingBalance = checkingBalance + amountTemp;
         checkingBalance = (checkingBalance * interestRate);
    }
    

    This actually only leaves the interest on the account!

    Also, a real bank doesn’t compute the interest when you do a deposit, but on fixed days like once a month or once a year. The interest you get (or pay) also depends on the number of days the account has had a certain balance.

    if ((checkingBalance = checkingBalance - amountTemp) < 0)
    {
        cout << "error: transaction number" << j + 1 << " never occured due to insufficent funds." << endl;
    }
    

    Despite the text written to cout, the transaction really has occurred, as = assigns a new value to Balance! Perhaps you should just compare the balance and the amount?

    You then repeat the invalid interest calculations again in the else part.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working through an assignment that deals with Big-O and running times. I
I'm working on an assignment that is telling me to assume that I have
I am working on an Operating Systems assignment for one of my summer classes.
I am currently working on a homework assignment and I am thoroughly stuck. I
Im working on a assignment which uses signals to transfer a binary message between
I'm working on a homework assignment for my object oriented design class, and I'm
I'm currently working on a programming assignment for school. It's a simple text-based RPG.
I'm having a very weird problem.I'm working on an assignment that involves building a
I'm working on an assignment that allows the user to display events that are
I am working on an assignment that introduces me to operator overloading. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.