Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment has been designed sothat you would be able to review the basic a

ID: 3616060 • Letter: T

Question

This assignment has been designed sothat you would be able to review the basic and essential conceptsin Object Oriented Programming.

This assignment will check your OOPprogramming skills in implementing

n      Inheritance

n      Using Base class

n      Using Derived class

And other relatedfeatures of Object Oriented Programming.

Assignment

Create an inheritancehierarchy by writing the source code, containing baseclass Accountand derived classes SavingsAccount and CheckingAccount that inheritfrom class Account. Make sure all return values, arguments, andmember functions are declared const where appropriate.

i. Base class Accountshould include onedata member of type double to represent the account balance. Theclass should provide a constructor that receives an initial balanceand uses it to initialize the data member. The constructor shouldvalidate the initial balance to ensure that it is greater than orequal to 0.0. If not, the balance should be set to 0.0 and theconstructor should display an error message, indicating that theinitial balance was invalid. (You may wish to use the cerr object,which functions just like cout except that it outputs to thestandard error output rather than standard text output. Usually,but not always, the two are functionally similar.)

The class shouldprovide four member functions. Member function Credit should add anamount to the current balance. Member function Debit shouldwithdraw money from the Account and ensure that the debit amountdoes not exceed the Account's balance. If it does, the balanceshould be left unchanged and the function should print the message"Debit amount exceeded account balance." Member function getBalanceshould return the current balance.

ii.Derived classSavingsAccount should inherit the functionality ofan Account, but also include a data member of type doubleindicating the yearly interest rate (percentage) assigned to theAccount. SavingsAccount's constructor should receive the initialbalance, as well as an initial value for the SavingsAccount'sinterest rate. (Make sure to call the base class constructorappropriately.) SavingsAccount should provide a public memberfunction calculateInterest that returns a double indicating theamount of interest earned by an account. Member functioncalculateInterest should take one integer argument indicating thenumber of years gone by, and should determine the interest amountby the formula I = B *(1+ r)t, where I is theinterest, B is the initial balance, r is the interest rate, and tis the number of years gone by. [Note: SavingsAccount shouldinherit member functions credit and debit as is without redefiningthem.]

iii.Derived classCheckingAccount should inherit from base classAccount and include an additional data member of type double thatrepresents the fee charged per transaction. CheckingAccount'sconstructor should receive the initial balance, as well as aparameter indicating a fee amount.

Explanation / Answer

#include <iostream> using namespace std;
class Account { public: Account(double initial){ if (initial >= 0.0) balance = initial; else { balance = 0.0; cerr << "Invalid initial balance."; }/*else*/ }/*constructor*/
void Credit(double amount){ //i assume that there is no checking required for negativeamounts balance += amount; }/*procedure*/
void Debit(double amount){ if (amount > balance) cerr << "Debit amount exceeded account balance."; else //again, i assume no checking is required for negativenumbers balance -= amount; }/*procedure*/
double getBalance(){ return balance; }/*function*/
protected: double balance; }/*class*/;
class SavingsAccount : public Account { public: SavingsAccount(double initial, double IR) :Account(initial){ interestRate = IR; }/*constructor*/
double calculateInterest(int years){ return balance*(1 + interestRate)*years; }/*function*/
protected: double interestRate; }/*class*/;
class CheckingAccount : public Account { public: CheckingAccount(double initial, double fee) :Account(initial){ transactionFee = fee; }/*constructor*/ /* not sure if you're supposed to overwrite the debitprocedure to deduct the transaction fee from the balance or not, if so,simply uncomment the following otherwise delete it. If you need to do it forthe credit procedure, i'm sure you can figure it out from thefollowing one... */ /* void Debit(double amount){ balance -= (amount + transactionFee); }/*procedure*/
protected: double transactionFee; }/*class*/;
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote