From Week 7 Assignment, we created the Account class with a static annual intere
ID: 3759886 • Letter: F
Question
From Week 7 Assignment, we created the Account class with a static annual interest rate variable, a member function calculateMonthlyInterest, and a static member function modifyInterestRate that sets the static annualInterestRate to a new value. In this assignment, you will create one derived class, CDAccount, public inheritanted from the base class, Account. You will add two private variables, duration (in months) and CDannualInterestRate, and four member functions, getDuration(), setDuration(), getCDannualInterestRate(), and setCDannualInterestRate(). Every three months CD duration will increase the CDannualInterestRate by 0.5% from 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. Make the necessary changes in both base class and derived class. The public function calculateMonthlyInterest() in the derived class will not only calculate the monthly interest of every month in the duration, but also print out the monthly interest. Write a driver program to test class CDAccount. Instantiate five different objects of class CDAccount, CDsaver1 to CDsaver5, with balances of $1000.00 to $5000.00, and duration from 3-month to 15-months respectively. Set the annualInterestRate to 3%. Calculate and print the monthly interest of every month during the saving period for each CDAccount. Display both CDannualInterestRate and the mature date.
week 7's code
1. header
#ifndef ACCOUNT
#define ACCOUNT
#include<iostream>
#include<string>
using namespace std;
/* class */
class Account
{
/* variable declarations and methods used */
public:
// Constructor for Account with default values specified to be 0 for both id and balance
Account(int custID = 0, double balance = 0);
// getter for account Id
int getId();
// setter for account Id
void setId(int custID);
// getter for account Balance
double getBalance();
// setter for account Balance
void setBalance(double balance);
// getter for annual Interest Rate
static double getAnnualInterestRate();
// setter for annual Interest Rate
static void setAnnualInterestRate(double interestRate);
// returns monthly interest rate i.e. annualInterestRate / 12
double getMonthlyInterestRate();
// returns monthly Interest i.e. balance * monthlyInterestRate / 100
double getMonthlyInterest();
// withdraws "withdrawAmount" amount from balance and decrements the balance by the same
void withdraw(double withdrawAmount);
// deposits "depositAmount" amount to balance and increments the balance by the same
void deposit(double depositAmount);
private:
int id;
double balance;
static double annualInterestRate;
};
#endif#pragma once
2. source
/* Account.cpp */
#include "Account.h"
#include <iostream>
#include <string>
using namespace std;
/* constructor */
Account::Account(int custID, double balance)
{
id = custID;
this->balance = balance;
}
int Account::getId()
{
return id;
}
void Account::setId(int custID)
{
id = custID;
}
double Account::getBalance()
{
return balance;
}
void Account::setBalance(double balance) {
this->balance = balance;
}
double Account::getAnnualInterestRate()
{
return annualInterestRate;
}
void Account::setAnnualInterestRate(double interestRate)
{
annualInterestRate = interestRate;
}
double Account::getMonthlyInterestRate()
{
return annualInterestRate / 12;
}
double Account::getMonthlyInterest()
{
return balance * (getMonthlyInterestRate() / 100);
}
void Account::withdraw(double withdrawAmount)
{
if (balance >= withdrawAmount) {
balance -= withdrawAmount;
}
else {
cout << "Insufficient balance...";
}
}
void Account::deposit(double depositAmount)
{
balance += depositAmount;
}
double Account::annualInterestRate;
3. main
/* main.cpp */
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include "Account.h"
using namespace std;
void print(Account holder);
int main(int argc, char *argv[])
{
Account::setAnnualInterestRate(3.00);
Account person1(1000.00, 1000);
person1.withdraw(500.00);
person1.deposit(1000.00);
Account person2(2000.00, 2000);
person2.withdraw(500.00);
person2.deposit(1000.00);
Account person3(3000.00, 3000);
person3.withdraw(500.00);
person3.deposit(1000.00);
Account person4(4000.00, 4000);
person4.withdraw(500.00);
person4.deposit(1000.00);
Account person5(5000.00, 5000);
person5.withdraw(500.00);
person5.deposit(1000.00);
// setting the width of all columns in the output to 20 characters
cout << setw(20) << std::right;
cout << "Account Number";
cout << setw(20) << std::right;
cout << "Monthly Interest";
cout << setw(20) << std::right;
cout << "Balance";
cout << endl;
/*
Printing a separator line by repeating the "=" character 62 times.
62 times because there are 3 columns(Account Number, Monthly Interest and
Balance) each of width 20 and keeping a margin of 1 character on both ends.
Hence, width of separator = 1 + 20 + 20 + 20 + 1
*/
cout << std::string(62, '=') << endl;
print(person1);
print(person2);
print(person3);
print(person4);
print(person5);
return 0;
}
void print(Account holder)
{
// setting the width of each column in the output to 20 characters
cout << setw(20) << std::right;
cout << holder.getId();
double monthlyInterest = holder.getMonthlyInterest();
cout << setw(20) << std::right;
//setting precision of monthlyInterest to display decimal points
cout << std::setprecision(7) << monthlyInterest;
holder.deposit(monthlyInterest);
cout << setw(20) << std::right;
//setting precision of monthlyInterest to display decimal points
cout << std::setprecision(7) << holder.getBalance();
cout << endl;
}
Explanation / Answer
nclude #include class account { char cust_name[20]; int acc_no; char acc_type[20]; public: void get_accinfo() { coutcust_name; coutacc_no; coutacc_type; } void display_accinfo() { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.