Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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- Accounts 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). CheckingAccounts versions of this function should invoke the base-class Account version to perform the debit operation.

Hint: Define Accounts 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). CheckingAccounts 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 its 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 Accounts 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 SavingsAccounts constructor that receives the initial balance, as well // as an initial value for the SavingsAccounts 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago