Question: Derived Class of Account Class - CDAccount. Any help is greatly appreciated, thank you. I am having a difficult time trying to figure out how
Derived Class of Account Class - CDAccount.
Any help is greatly appreciated, thank you.
I am having a difficult time trying to figure out how to fix the functions (Set and Get functions) in my CDAccount.cpp correctly and how to get the correct output that includes the Account ID, Annual Rate, etc, in a table format. I have posted what I have done so far with my code below and my output.
- Create one derived class, CDAccount, public inherited from the base class, Account. You will add two private variables, duration (in months) and CDannualInterestRate, and few more member functions like getDuration(), setDuration(), getCDannualInterestRate(), setCDannualInterestRate(). (I've already done this)
-Add one static variable NumberOfObjects, and one static function getNumberOfObjects. Modify the constructor and destructor in the CDAccount class to print out CDAccount ID and NumberOfObjects info whenever one CDAccount object is created or destroyed.Refer to the UML diagram. (I've already done this also)
-Every three months CD duration will increase the CDannualInterestRate by 0.5% from the annualInterestRate of the base class. For example: if annualInterestRate is 3%, the CDannualInterestRate will be 3.5% of a three-months CD saving account, and the CDannualInterestRate will be 4% of a six-month CD. (I am having trouble figuring out and understanding this part)
-Write a driver program to test class CDAccount. Instantiate one CDAccount array to create five different objects of class CDAccount with balances of $1000.00 to $5000.00, and duration from 3-month to 15-months respectively. Set the Account::annualInterestRate to 5%. Calculate and print the monthly interest of every month during the saving period for each CDAccount. Display both CDannualInterestRate and the mature balance. (Also need help here)
MatureBalance = balance * ( 1+ monthly_interest_rate ) duration (not even sure where to put this)


Sample output:

My output:

My code so far:
ACCOUNT.H
#ifndef Account_h
#define Account_h
#include
using namespace std;
class Account
{
const int id;
double balance;
double static annualInterestRate;
static int NumberOfObjects;
double setBalance(double);
friend ostream &operator
public:
Account(const int = 0, double = 0.0); // Constructor
~Account(); // Destructor
// set function
void static setAnnualInterestRate(double); // set the initial value as 5%
// get functions
unsigned int getID() const;
double getBalance() const;
static double getAnnualInterestRate();
static int getNumberofObjects();
double getMonthlyInterestRate() const;
double getMonthlyInterest() const;
void withdraw(double);
void deposit(double);
};
#endif // Account_h
----------------------------------------
CDACCOUNT.H
#ifndef CDAccount_h
#define CDAccount_h
#include "Account.h"
using namespace std;
class CDAccount : public Account
{
int duration; // 3-month to 15-months
double CDInterestRate;
static int NumberOfObjects;
static int getNumberofObjects();
public:
CDAccount(int = 0, double = 0.0, int = 0); // Constructor
~CDAccount(); // Destructor
void setDuration(int);
int getDuration() const;
void setCDAnnaualInterestRate(double);
double getCDAnnualInterstRate() const;
double getMonthlyInterestRate() const;
double getMonthlyInterest() const;
double getMatureBalance() const;
};
#endif // CDAccount_h
----------------------------------------
ACCOUNT.CPP
#include
#include
#include
#include "Account.h"
using namespace std;
double Account::annualInterestRate = 0.05;
int Account::NumberOfObjects = 0;
Account::Account(const int newID, double newBalance) // constructor initialises each data member
: id(newID), balance(newBalance)
{
cout
NumberOfObjects++;
cout
}
Account::~Account() // destructor
{
cout
--NumberOfObjects;
cout
}
double Account::setBalance(double Newbalance)
{
this->balance = Newbalance;
return 0;
}
void Account::setAnnualInterestRate(double newannualInterestRate)
{
annualInterestRate = newannualInterestRate;
}
unsigned int Account::getID() const
{
return id;
}
double Account::getBalance() const
{
return balance;
}
double Account::getAnnualInterestRate()
{
return annualInterestRate;
}
int Account::getNumberofObjects()
{
return NumberOfObjects;
}
double Account::getMonthlyInterestRate() const
{
return (annualInterestRate / 12);
}
double Account::getMonthlyInterest() const
{
return balance*(annualInterestRate / 12);
}
void Account::withdraw(double withdrawAmount)
{
if (balance >= withdrawAmount)
{
balance -= withdrawAmount; //balance = balance - withdrawAmount
}
else
throw invalid_argument("No sufficient balance");
}
void Account::deposit(double depositAmount)
{
balance += depositAmount; //balance = balance + depositAmount
}
ostream &operator
{
output
return output;
}
----------------------------------------
CDACCOUNT.CPP
#include
#include
#include "CDAccount.h"
using namespace std;
int CDAccount::NumberOfObjects = 0;
CDAccount::CDAccount(int newID, double newBalance, int newDuration)// Constructor
:Account (newID,newBalance)
{
setDuration(newDuration);
cout
NumberOfObjects++;
cout
}
CDAccount::~CDAccount() // Destructor
{
cout
--NumberOfObjects;
cout
}
void CDAccount::setDuration(int newDuration)
{
duration = newDuration;
}
int CDAccount::getDuration() const
{
return duration;
}
int CDAccount::getNumberofObjects()
{
return NumberOfObjects;
}
void CDAccount::setCDAnnaualInterestRate(double newCDannualInterestRate)
{
CDInterestRate = newCDannualInterestRate;
}
double CDAccount::getCDAnnualInterstRate() const
{
return 0 ; // fix return ___;
}
double CDAccount::getMonthlyInterestRate() const
{
return 0 ; // fix return ___;
}
double CDAccount::getMonthlyInterest() const
{
return 0 ; // fix return ___;
}
double CDAccount::getMatureBalance() const
{
return 0 ; // fix return ___;
}
----------------------------------------
ACCOUNTMAIN.CPP
#include
#include
#include
#include "CDAccount.h"
using namespace std;
int main()
{
Account::setAnnualInterestRate(5.00);
CDAccount CDAccount1(1000, 1000.00,1);
CDAccount CDAccount2(2000, 2000.00,2);
CDAccount CDAccount3(3000, 3000.00,3);
CDAccount CDAccount4(4000, 4000.00,4);
CDAccount CDAccount5(5000, 5000.00,5);
cout
cout
cout
cout
return 0;
}
UML Diagram Account id:const balance: double annuallnterestRate: double NumberOfObiects: int + > Account(id: int=0, balance: double=0) + > Account() + getID): int const setBalance(balance: double) + getBalance): double + setAnnuallnterestRate( annuallnterestRate: double) + getAnnuallnterestRate: double + getNumberOfObiects: int + getMonthlylnterestRate0: double + getMonthlylnterest( + withdraw(amount: double) + deposit(amount: double) const nas ): double const
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
