Answer to Question #222501 in C++ for Jaguar

Question #222501
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;
};

(b) Code the interface for a class CarInsurance derived from class
InsurancePolicy (the base class). This class has an additional member
variable, excess. Class CarInsurance also has member functions, get_excess() and set_excess()to return member variable excess and
update member variable excess respectively. The class CarInsurance should
override function setPolicy() in order to update the member variables of
CarInsurance.
1
Expert's answer
2021-08-05T12:30:32-0400
#include<iostream>
using namespace std;
class InsurancePolicy
{
	private:




int policyNr;




string policyHolder;




double annualRate;
public:




InsurancePolicy(){
    
}




InsurancePolicy(int pNr, string pHolder, double aRate){
    policyNr = pNr;
    policyHolder = pHolder;
    annualRate = aRate;
}




~InsurancePolicy();




void setPolicy(int pNr, string pHolder, double aRate){
    policyNr = pNr;
    policyHolder = pHolder;
    annualRate = aRate;
}




int get_pNr()const{
    return policyNr;
}




string get_pHolder()const{
    return policyHolder;
}




double get_aRate()const{
    return annualRate;
}










};


class CarInsurance: public InsurancePolicy{
	private:
		string excess;
	
	
	public:
		void set_excess(string ex){
			excess = ex;
			
		}
		string get_excess(){
			return excess;
		}  
 
	


};
InsurancePolicy:: ~InsurancePolicy(void){
    cout<<"Object is being deleted."<<endl;
}
int main(){
   
    CarInsurance insurance;
    insurance.setPolicy(101,"Abraham",19992);
    cout<<"Number is\t"<<insurance.get_pNr()<<endl;
    cout<<"Holder is\t"<<insurance.get_pHolder()<<endl;
    cout<<"Annul rate is\t"<<insurance.get_aRate()<<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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS