Question

Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits...

Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp

CheckingAccount

Derived class CheckingAccount that inherits from base class Account and include an additional data member of type double that represents the fee charged per transaction (transactionFee).

Write Checking- Account’s constructor that receives the initial balance, as well as a parameter indicating a transaction fee amount. If transaction fee is less than zero, the transactionFee will be set to zero.

Write the chargeFee member function that updates the balance by deducting the transactionFee from the balance.

Override member functions debit for class CheckingAccount so that it subtracts the transactionFee from the account balance (call chargeFee). If the operation is successful, it will return true otherwise it does nothing and will return false (debit is successful if the amount is not greater than the balance). CheckingAccount’s versions of this function should invoke the base-class Account version to perform the debit operation.

Hint: Define Account’s debit function so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.

Override member functions credit for class CheckingAccount so that it subtracts the transactionFee from the account balance (call chargeFee). CheckingAccount’s versions of this function should invoke the base-class Account version to perform the credit operation.

Override the display function in the Account class that insert that print a SavingsAccount in the following format (example):

Account.h:

#ifndef ICT_ACCOUNT_H__
#define ICT_ACCOUNT_H__

#include

using namespace std;
namespace ict
{
    class Account
    {
       private:
           double balance; // data member that stores the balance
       protected:
           double getBalance() const; // return the account balance
           void setBalance( double ); // sets the account balance
       public:
           // TODO: Write a prototype for constructor which initializes balance
           Account(double);
           // TODDO: Write a function prototype for the virtual function credit
           virtual void credit(double);
           // TODO: Write a function prototype for the virtual function debit
           virtual bool debit(double);
           // TODO: Write a function prototype for the virtual function display
           // Add the prototype of pure virtual function display that receives a reference to ostream.
           virtual void display(ostream &) = 0;
    };
};
#endif

Account.cpp:

#include "Account.h"

using namespace std;
namespace ict
{
    // constructor
    // Write the constructor that validates the initial balance to ensure that it’s greater
    // than or equal to 0. If not, set the balance to the safe empty state
    // (balance equals to -1.0).
    Account::Account(double bal)
    {
       if(bal >= 0)
           balance = bal;
       else
           balance = -1.0;  
    }
   
    // credit (add) an amount to the account balance
    //Write the virtual member function credit that adds an amount to the current balance.
    void Account::credit(double amount)
    {
       balance += amount;
    }
   
    // debit (subtract) an amount from the account balance return bool
    // Write the virtual member function debit that withdraws money from the account and
    // ensure that the debit amount does not exceed the Account’s balance. If the balance
    // is less the amount, the balance should be left unchanged and the function should
    // return false (otherwise it should return true).
    bool Account::debit(double amount)
    {
       if(amount > balance)
           return false;
       balance -= amount;
       return true;  
    }
   
    double Account::getBalance() const   {   return balance;   }
    void Account::setBalance( double newBalance )   {   balance = newBalance;   }
}

SavingsAccount.h:

#ifndef ICT_SAVINGSACCOUNT_H__
#define ICT_SAVINGSACCOUNT_H__
#include "Account.h"

using namespace std;

namespace ict
{
    class SavingsAccount : public Account
    {
       private:
           double interestRate; // interest rate (percentage)
       public:
           // TODO: put prototypes here
           SavingsAccount(double bal, double interest);
           double calculateInterest();
           void display(ostream&);
    };
};
#endif

SavingsAccount.cpp:

#include "SavingAccount.h"
#include
using namespace std;

namespace ict
{
    // TODO: Implement SavingsAccount member functions here
    // Write the SavingsAccount’s constructor that receives the initial balance, as well
    // as an initial value for the SavingsAccount’s interest rate, and then initializes
    // the object. If interest rate is less than zero, the interstRate will be set to zero.
    SavingsAccount::SavingsAccount(double bal, double interest) : Account(bal)
    {
       if(interest < 0)
           interestRate = 0;
       else
           interestRate = interest;
    }
    // Write the public member function calculateInterest for SavingsAccount class that
    // returns the amount of interest earned by an account. Member function
    // calculateInterest should determine this amount by multiplying the interest rate
    // by the account balance.
    double SavingsAccount::calculateInterest()
    {
       return interestRate * getBalance();
    }
    void SavingsAccount::display(ostream &out)
    {
       out << "Account type: Saving" << endl;
       out << "Balance: $ " << fixed << setprecision(2) << getBalance() << endl;
       out << "interest Rate (%): " << fixed << setprecision(2) << interestRate * 100 << endl;
    }  
}

Main.cpp

#include

#include "Account.h"

#include "SavingsAccount.h"

#include "CheckingAccount.h"

using namespace ict;

using namespace std;

int main()

{

     // Create Account for Angelina

     Account * Angelina_Account[2];

   

     // initialize Angelina Accounts

    

     Angelina_Account[ 0 ] = new SavingsAccount( 400.0, 0.12 );

     Angelina_Account[ 1 ] = new CheckingAccount( 400.0, 1.0);

     cout << "**************************" << endl;

     cout << "DISPLAY Angelina Accounts:" << endl;

     cout << "**************************" << endl;

     Angelina_Account[0]->display(cout);

     cout << "-----------------------" << endl;

     Angelina_Account[1]->display(cout);

     cout << "**************************" << endl ;

     cout << "DEPOSIT $ 2000 $ into Angelina Accounts ..." << endl ;

     for(int i=0 ; i < 2 ; i++){

         Angelina_Account[i]->credit(2000);

     }

     cout << "WITHDRAW $ 1000 and $ 500 from Angelina Accounts ..." << endl;

     Angelina_Account[0]->debit(1000);

     Angelina_Account[1]->debit(500);

     cout << "**************************" << endl;

     cout << "DISPLAY Angelina Accounts:" << endl;

     cout << "**************************" << endl;

     Angelina_Account[0]->display(cout);

     cout << "-----------------------" << endl;

     Angelina_Account[1]->display(cout);

     cout << "-----------------------" << endl;

     return 0;

}

The following is the exact output of the tester program:

DISPLAY Angelina Accounts:

**************************

Account type: Saving

Balance: $ 400.00

Interest Rate (%): 12.00

-----------------------

Account type: Checking

Balance: $ 400.00

Transaction Fee: 1.00

**************************

DEPOSIT $ 2000 $ into Angelina Accounts ...

WITHDRAW $ 1000 and $ 500 from Angelina Accounts ...

**************************

DISPLAY Angelina Accounts:

**************************

Account type: Saving

Balance: $ 1400.00

Interest Rate (%): 12.00

-----------------------

Account type: Checking

Balance: $ 1898.00

Transaction Fee: 1.00

-----------------------

ChekingAccount.cpp

#include "CheckingAccount.h"
using namespace std;
namespace ict{
// TODO: define CheckingAccount class member functions here

}

ChekingAccount.h

#ifndef ICT_CHECKINGACCOUNT_H__
#define ICT_CHECKINGACCOUNT_H__
#include "Account.h"
using namespace std;
namespace ict{
class CheckingAccount : public Account {
private:
double transactionFee;
// TODO: chargeFee subtract transaction fee form the balance
public:
// TODO: constructor initializes balance and transaction fee
// TODO: Write a function prototype to override credit function
// TODO: Write a function prototype to override debit function
// TODO: Write a function prototype to override display function
};
};

#endif

Homework Answers

Answer #1
#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account
{
public:
   Account( double ); // constructor initializes balance
   void credit( double ); // add an amount to the account balance
   bool debit( double ); // subtract an amount from the account balance
   void setBalance( double ); // sets the account balance
   double getBalance(); // return the account balance
private:
   double balance; // data member that stores the balance
}; // end class Account

#endif
//  Account.cpp
// Member-function definitions for class Account.
#include <iostream>
using namespace std;

#include "Account.h" // include definition of class Account

// Account constructor initializes data member balance
Account::Account( double initialBalance )
{
   // if initialBalance is greater than or equal to 0.0, set this value
   // as the balance of the Account
   if ( initialBalance >= 0.0 )
      balance = initialBalance;
   else // otherwise, output message and set balance to 0.0
   {
      cout << "Error: Initial balance cannot be negative." << endl;
      balance = 0.0;
   } // end if...else
} // end Account constructor

// credit (add) an amount to the account balance
void Account::credit( double amount )
{
   balance = balance + amount; // add amount to balance
} // end function credit

// debit (subtract) an amount from the account balance
// return bool indicating whether money was debited
bool Account::debit( double amount )
{
   if ( amount > balance ) // debit amount exceeds balance
   {
      cout << "Debit amount exceeded account balance." << endl;
      return false;
   } // end if
   else // debit amount does not exceed balance
   {
      balance = balance - amount;
      return true;
   } // end else
} // end function debit

// set the account balance
void Account::setBalance( double newBalance )
{
   balance = newBalance;
} // end function setBalance

// return the account balance
double Account::getBalance()
{
   return balance;
} // end function getBalance
//  SavingsAccount.h
// Definition of SavingsAccount class.
#ifndef SAVINGS_H
#define SAVINGS_H

/* Write a directive to include the Account header file */

/* Write a line to have class SavingsAccount inherit publicly from Account */
{
public:
   // constructor initializes balance and interest rate
   /* Declare a two-parameter constructor for SavingsAccount */
   /* Declare member function calculateInterest */
private:
   /* Declare data member interestRate */
}; // end class SavingsAccount

#endif
// Lab 1: SavingsAccount.cpp
// Member-function definitions for class SavingsAccount.

#include "SavingsAccount.h" // SavingsAccount class definition

// constructor initializes balance and interest rate
/* Write the SavingsAccount constructor to call the Account constructor and validate and set the interest rate value */

// return the amount of interest earned
/* Write the calculateInterest member function to return the interest based on the current balance and interest rate */
// CheckingAccount.h
// Definition of CheckingAccount class.
#ifndef CHECKING_H
#define CHECKING_H

/* Write a directive to include the Account header file */
/* Write a line to have class CheckingAccount inherit publicly from Account */
{
public:
   // constructor initializes balance and transaction fee
   /* Declare a two-argument constructor for CheckingAccount */
   /* Redeclare member function credit, which will be redefined */
   /* Redeclare member function debit, which will be redefined */
private:
   /* Declare data member transactionFee */
   // utility function to charge fee
   /* Declare member function chargeFee */
}; // end class CheckingAccount
#endif
//  CheckingAccount.cpp
// Member-function definitions for class CheckingAccount.
#include <iostream>
using namespace std;

#include "CheckingAccount.h" // CheckingAccount class definition

// constructor initializes balance and transaction fee
/* Write the CheckingAccount constructor to call the Account constructor and validate and set the transaction fee value */

// credit (add) an amount to the account balance and charge fee
/* Write the credit member function to call Account's credit function and then charge a fee */

// debit (subtract) an amount from the account balance and charge fee

// subtract transaction fee
/* Write the chargeFee member function to subtract transactionFee from the current balance and display a message */
// Test program for Account hierarchy.
#include <iostream>
#include <iomanip>
using namespace std;

#include "Account.h" // Account class definition
#include "SavingsAccount.h" // SavingsAccount class definition
#include "CheckingAccount.h" // CheckingAccount class definition

int main()
{
        Account account1( 50.0 ); // create Account object
        SavingsAccount account2( 25.0, .03 ); // create SavingsAccount object
        CheckingAccount account3( 80.0, 1.0 ); // create CheckingAccount object
        
        cout << fixed << setprecision( 2 );
        
        // display initial balance of each object
        cout << "account1 balance: $" << account1.getBalance() << endl;
        cout << "account2 balance: $" << account2.getBalance() << endl;
        cout << "account3 balance: $" << account3.getBalance() << endl;

        cout << "\nAttempting to debit $25.00 from account1." << endl;
        account1.debit( 25.0 ); // try to debit $25.00 from account1
        cout << "\nAttempting to debit $30.00 from account2." << endl;
        account2.debit( 30.0 ); // try to debit $30.00 from account2
        cout << "\nAttempting to debit $40.00 from account3." << endl;
        account3.debit( 40.0 ); // try to debit $40.00 from account3

        // display balances
        cout << "\naccount1 balance: $" << account1.getBalance() << endl;
        cout << "account2 balance: $" << account2.getBalance() << endl;
        cout << "account3 balance: $" << account3.getBalance() << endl;

        cout << "\nCrediting $40.00 to account1." << endl;
        account1.credit( 40.0 ); // credit $40.00 to account1
        cout << "\nCrediting $65.00 to account2." << endl;
        account2.credit( 65.0 ); // credit $65.00 to account2
        cout << "\nCrediting $20.00 to account3." << endl;
        account3.credit( 20.0 ); // credit $20.00 to account3

        // display balances
        cout << "\naccount1 balance: $" << account1.getBalance() << endl;
        cout << "account2 balance: $" << account2.getBalance() << endl;
        cout << "account3 balance: $" << account3.getBalance() << endl;

        // add interest to SavingsAccount object account2
        /* Declare a variable interestEarned and assign it the interest account2 should earn */
        cout << "\nAdding $" << interestEarned << " interest to account2." << endl;
        /* Write a statement to credit the interest to account2's balance */
        
        cout << "\nNew account2 balance: $" << account2.getBalance() << endl;
} // end main
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Experience with Functions Are the following statements a function header, a prototype or a function call?...
Experience with Functions Are the following statements a function header, a prototype or a function call? double calcMonthlyPmt(double amt); void displayResults() void showMenu(); showNum(45.67); area = CalArea(5,10); Write the function calls for the following headers and prototypes: void showValue(int quantity) void display(int arg1, double arg2, char arg3); pass the following to the call: int age; double income; char initial double calPay(int hours, double rate); What is the output of the following program? #include <iostream> using namespace std; void showDouble(int); //Function...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent points in the cartesian plane #include <iostream> using namespace std; class Point { public:     Point()      // default constructor         Point(double x, double y); // another constructor         double x() const; // get function, return _x         double y() const; // get function, return _y private:         double _x, _y; }; (ii) Here is a test driver file for the Point class...
Using the following definition for a BST node: class BTNode { public: int data; BTNode *left;...
Using the following definition for a BST node: class BTNode { public: int data; BTNode *left; BTNode *right; BTNode(int d,BTNode *l=nullptr,BTNode *r=nullptr) :data(d),left(l),right(r) {} }; Implement a function to calculate the balance factor of a node in a BST. The function prototype must match the following function: int balance_factor(BTNode *subtree) { // IMPLEMENT return -2; } You may implement other functions to help you. In particular, you may want to implement a function to calculate a node's height. //C++ #include...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's length, width, and area Define an overloaded constructor and use it when creating the Rectangle object instead of using the setters. Change this program to calculate and display the rectangle's perimeter. Example: In feet, how wide is your house? 20 In feet, how long is your house? 25 The house is 20.00 feet wide. The house is 25.00 feet long. The house has 500.00...
Create a Software Application for XYZ Bank that allows its members to access their bank account...
Create a Software Application for XYZ Bank that allows its members to access their bank account information through an “ATM like” interface. The Menu Options should include: checking the account balance, debiting the account and crediting the account, along with an option to exit the program. Create an Account Class to represent the customers’ bank accounts. Include a data member of type float to represent the account balance. Provide a constructor that receives an initial balance and uses it to...
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...