Question: Lab: Inheritance Implement a base class Account and derived classes Savings and Checking. In the base class, supply member functions deposit and withdraw. Provide a

Lab: Inheritance Implement a base class Account and derived classes Savings and Checking. In the base class, supply member functions deposit and withdraw. Provide a function daily_interest that computes and adds the daily interest. For calculations, assume that every month has 30 days. Checking accounts yield interest of 3 percent monthly on balances over $1,000. Savings accounts yield interest of 6 percent on the entire balance. Use the supplied driver program that makes a months worth of deposits and withdrawals and calculates the interest every day. Use the code below and modified the code to implement the requirement of the lab Define constant for DAYS_PER_MONTH = 30; Define constant SAVING_RATE = 0.06; class Account { public: Account(); // doing nothing Account(double b); // set balance to b void deposit(double amount); // balance is increaed by amount void withdraw(double amount); // balance is reduced by amount // make sure you cant withdraw if // amount is larger than balance double get_balance() const; // return the account balance private: double balance; }; You need to implement all the member functions for the class Account //.................................................................. // define class Savings which will inherit class // object Account modify ????? below with correct code class Savings : ???? // modify ?????? with correct code to inherient { public: Savings(); // doing nothing Savings(double b); // initialize balance to b void daily_interest(); }; You need to implement all the member functions for the class Savings /** Determine the daily interest and deposit it into the account. */ void Savings::daily_interest() { // // calculate the daily interest rate which is // balance * SAVING_RATE / DAYS_PER_MONTH // Then call member function to deposit the interest to the // balance // // your code here to deposit the daily interest } //.................................................................. // define class Checking which will inheritance class // object Account modify ????? below with correct code class Checking: ???? // modify ?????? with correct code to inherient class Account { public: Checking(); // doing nothing Checking(double b); // set balance to b void daily_interest(); }; You need to implement all the member functions for the class Savings /** Determine the daily interest and deposit it into the account. Checking accounts yield interest of 3 percent monthly on balances over $1,000. Calling daily_interest() will calculate daily interest and add the daily interest to the balance */ void Checking::daily_interest() { const double RATE = 0.03; const double MIN_BALANCE = 1000; /* your code here Calculate daily interest for any balance over $1000 and deposit the daily interest to the balance */ } /* Use the following test template to test your program */ int main() { Checking c = Checking(1000.0); Savings s = Savings(1000.0); for (int i = 1; i <= DAYS_PER_MONTH; i++) { c.deposit(i * 5); c.withdraw(i * 2); s.deposit(i * 5); s.withdraw(i * 2); c.daily_interest(); s.daily_interest(); if (i % 10 == 0) // use % to only print out days 10, 20, 30 { cout << "day " << i << " "; cout << "Checking balance: " << c.get_balance() << " "; cout << "Savings balance: " << s.get_balance() << " "; } } return 0;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!