Answer to Question #222502 in C++ for Jaguar

Question #222502
Consider the class definition below and answer the questions that follow:

class InsurancePolicy
{
public:
InsurancePolicy();
InsurancePolicy(int pNr, string pHolder, double aRate);
~InsurancePolicy();
void setPolicy(int pNr, string pHolder, double aRate);
int get_pNr()const;
string get_pHolder()const;
double get_aRate()const;
private:
int policyNr;
string policyHolder;
double annualRate;
};

(c) Implement the class CarInsurance and use the code below to implement
setPolicy():
void CarInsurance:: setPolicy(int pNr, string pHolder,
double aRate, double
eValue)
{
policyNr = pNr;
policyholder = pHolder;
annualRate = aRate;
excess = eValue;
}
You should obtain the following errors:
Explain why setPolicy()is not a legal definition in the derived class
CarInsurance?
Suggest two ways to fix this problem.
1
Expert's answer
2021-08-06T04:24:46-0400

Code

Correct code for setPolicy() Method of carInsurance class

#include<iostream>
#include<string>

using namespace std;

class Insurancepolicy
{
public:
    Insurancepolicy();
    Insurancepolicy(int pNr, string pHolder, double aRate);
    ~Insurancepolicy();
    void setPolicy(int pNr, string pHolder, double aRate);
    int get_pNr();
    string get_pHolder();
    double get_aRate();

private:
    int policyNr;
    string policyHolder;
    double annualRate;
};

class CarInsurance :public Insurancepolicy
{
public:
    void setPolicy(int nPr, string pHolder, double aRate, double  eValue);
private:
    double excess;
};


void CarInsurance::setPolicy(int nPr, string pHolder, double aRate, double  eValue)
{
    Insurancepolicy::setPolicy(nPr, pHolder, aRate);
    excess = eValue;
}


Reason setPolicy() is not legal definition in derived class 

Now in InsurancePolicy class we have declared all the member variable as a private. So outside of this class we can no access this variable because its private access specifier.. . 

CarInsurance class is derived from the InsurancePolicy class so CarInsurance class can no directly access the private member of the InsurancePolicy class. For this we have to use its public method to get and set member property.


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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS