Question
2. In this question we modify the bank account classes discussed in class so that the base class account has a method called write which
2. In this question we modify the bank account classes discussed in class so that the base class account has a method called write which sends the values of the members to a stream. This method is overridden in the derived classes to also send any new members to the stream.
class savingsaccount has the data member interestrate and the method addinterest. class chequingaccount has the data member remainingfreewithdrawals and overrides the withdraw method so that the withdrawal fee is not charged if remainingfreewithdrawls is positive.
Complete the implemenation (boxed in red) of the derived classes. To achieve code reuse, methods of the derived classes must utilize methods of the base classes.
For marking purposes, run the program and capture the screen output. Declaration of Classes AccountTypes
PLEASE DO NOT MODIFY THE REST OF THE CODE THANK YOU.
THIS IS THE COPY/PASTE VERSION OF THIS CODE:
Declaration of Classes AccountTypes:
/* File: accounttypes.h
Shows how to derive classes */
#ifndef ACCOUNTTYPES_H
#define ACCOUNTTYPES_H
#include
#include
using namespace std;
class account {
private:
string owner;
float balance;
float withdrawfee;
public:
account(string name, float fee);
void write(ostream & out) const;
void deposit(float amount);
bool withdraw(float amount);
float getbalance(void) const;
float getwithdrawfee(void) const;
};
class savingsaccount :public account {
private:
float interestrate;
public:
savingsaccount(string name, float fee, float rate);
void write(ostream & out) const;
void addinterest(void);
};
class chequingaccount : public account {
private:
int remainingfreewithdrawals;
public:
chequingaccount(string name, float fee, int numberfree);
void write(ostream & out) const;
bool withdraw(float amount);
};
#endif /* ACCOUNTTYPES_H */
Implementation of classes AccountTypes:
/* File: accounttypes.cpp
Implementation of classes accounttypes */
#include "accounttypes.h"
///////////////////// implementation of account ///////////////////////
account::account(string name, float fee)
{
owner = name;
balance = 0;
withdrawfee = fee;
}
void account::write(ostream & out) const
{
out
out
out
}
void account::deposit(float amount)
{
balance = balance + amount;
}
bool account::withdraw(float amount)
{
bool result;
if (amount > balance-withdrawfee) {
cout
result = false;
} else {
balance = balance - amount - withdrawfee;
result = true;
}
return result;
}
float account::getbalance(void) const
{
return balance;
}
float account::getwithdrawfee(void) const
{
return withdrawfee;
}
///////////////////// implementation of savingsaccount ///////////////////////
///////////////////// implementation of chequingaccount ///////////////////////
Main Program Using Classes AccountTypes:
/* File: testaccounttypes.cpp
Application program using accounttypes classes
Programmer: your name Date: */
#include "accounttypes.h"
int main(void)
{
savingsaccount s("joe", 0.50, 0.02);
chequingaccount c("bob", 0.50, 2);
s.deposit(100.);
c.deposit(100.);
cout
s.write(cout);
cout
c.write(cout);
s.withdraw(10.);
s.withdraw(5.);
s.withdraw(20.0);
s.addinterest();
cout
s.write(cout);
c.withdraw(10.);
c.withdraw(5.);
c.withdraw(20.0);
cout
c.write(cout);
return 0;
}
File: accounttypes.h Shows how to derive classes #if n d e f ACCOUNT!YPES.H #d e fine ACCOUNTTYPES.H #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started