Answer to Question #285383 in C++ for King Hassan

Question #285383

Q1. Define a class Deposit that has a principal, a rate of interest, which is fixed for all


deposits and a period in terms of years. Write member functions to


(i) alter(float) which can change the rate of interest.


(ii) interest() which computes the interest and returns it.


(iii) print() which prints data as shown below. Note that the width of each column is 20.


5mks


Q2. Assume that the cell users are two kinds – those with a postpaid option and those


with a prepaid option. Postpaid gives a fixed free talk time and the rest is computed at


the rate of N2.90 per pulse. Prepaid cards have a fixed talk time.


Define a class Cell_user as a base class and derive the hierarchy of classes. Define


member functions and override them wherever necessary to


(i) retrieve the talk time left for each user.


(ii) print the bill in a proper format containing all the information for the postpaid user.



1
Expert's answer
2022-01-07T01:49:33-0500
#include <iostream>
#include <iomanip>

class Deposit
{
    float interest_rate;
    double principal;
    int term;
    
public:
    float set_rate(float rate)
    {
        this->interest_rate = rate;
        return this->interest_rate;
    }
    
    double interest()
    {
        return this->principal * interest_rate + this->principal;
    }
    
    void print()
    {
        std::wcout<<std::setw(20)<<this->interest_rate <<std::setw(20)<<this->principal<<std::setw(20)<<this->term<<std::endl;
    };
    class Cell
    {
protected:
        bool prepaid;
        bool postpaid;
        float talk_time;
        int amount;
    };
    class Cell_user: public Cell
    {
        
public:
    float get_talk_time()
    {
        return this->talk_time;
    }
        
    void print_bill()
    {
        std::cout<<"You have to pay "<<this->amount<<std::endl;
    }
        
    };
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment