Question

In: Computer Science

c++ using polymorphyism , create an inheritance hierarchy for the following types of insurance : Home,...

c++

using polymorphyism , create an inheritance hierarchy for the following types of insurance :

Home, vehicle , life

2 member functions should be included:

- calcpremium

   - Home- 0.5% of the value of the home

   - Life- 1% of the value of the policy

   - Vehicle - 0.5% of the value of the policy

calcCommission

Home- 0.2% of the value of the home

Life- 1% of the value of the policy

Vehicle - 0.5% of the value of the policy

in main

   1. instantiate an object for each type of insurance policy.

       - Home: value is $457,999.00

       - Life: policy value $1,000,000.00

       - Vehicle: policy value is $25,000.00

   2. Call a global function ( exercising polymorphism) to print out the premium

   and commission for each policy.

   3. make sure that objects of the base class cannot be instantiated.

Solutions

Expert Solution

#include <iostream>
using namespace std;

//base class to hold insurance details
class Insurance
{
public:

//declare variables
int value;

//functions expected to be overridden by child classed
virtual double calcpremium()=0;
virtual double calcCommission()=0;

//global function to display insurance details
void display()
{
     cout<<"\nValue: \t\t"<<value;
     cout<<"\nPremium: \t"<<calcpremium();
     cout<<"\nCommission: \t"<<calcCommission();
}
};

//home insurance class
class Home:public Insurance
{
    public:
    Home(int v)
    {
        value=v;
    }
    double calcpremium()
    {
        return value* 0.5/100;
    }
    double calcCommission()
    {
        return value*0.2/100;
    }
};

//vehicle class
class Vehicle:public Insurance
{
    public:
    Vehicle(int v)
    {
        value=v;
    }
    double calcpremium()
    {
        return value* 0.5/100;
    }
    double calcCommission()
    {
        return value*0.5/100;
    }
};

//life insurance class

class Life:public Insurance
{
    public:
    Life(int v)
    {
        value=v;
    }
    double calcpremium()
    {
        return value* 0.1/100;
    }
    double calcCommission()
    {
        return value*0.1/100;
    }
};

//main function which triggers the class
int main()
{
    //delcare insurance object
   Insurance *i;

   //declare objects of three classes
   Home home(457999);
   Vehicle vehicle(25000);
   Life life(1000000);

   //assign home object to base class object
   cout<<"\n***Home Insurance****";
   i=&home;
   i->display();

   //assign life object to base class object
   cout<<"\n***Life Insurance****";
   i=&life;
   i->display();

   //assign vehicle object to base class object
   cout<<"\n***Vehicle Insurance****";
   i=&vehicle;
   i->display();
   return 0;
}

Sample Output:

***Home Insurance****                                                                                                                                           

Value:          457999                                                                                                                                          

Premium:        2289.99                                                                                                                                         

Commission:     915.998                                                                                                                                         

***Life Insurance****                                                                                                                                           

Value:          1000000                                                                                                                                         

Premium:        1000                                                                                                                                            

Commission:     1000                                                                                                                                            

***Vehicle Insurance****                                                                                                                                        

Value:          25000                                                                                                                                           

Premium:        125                                                                                                                                             

Commission:     125


Related Solutions

Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create...
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive a Square Class from the Rectangle Class 3. Derive a Right Triangle Class from the Rectangle Class 4. Create a Circle Class 5. Create a Sphere Class 6. Create a Prism Class 7. Define any other classes necessary to implement a solution 8. Define a Program Driver Class for Demonstration (Create a Container to hold objects of the types...
Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive...
Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive a Square Class from the Rectangle Class 3. Derive a Right Triangle Class from the Rectangle Class 4. Create a Circle Class 5. Create a Sphere Class 6. Create a Prism Class 7. Define any other classes necessary to implement a solution 8. Define a Program Driver Class for Demonstration (Create a Container to hold objects of the types described above Create and Add...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the opportunity to overload or override an inherited member function. What is the difference? and which one is the better?
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
Java Code: Problem #1: Create an inheritance hierarchy of Rodent: mouse, gerbil, hamster, guinea pig. In...
Java Code: Problem #1: Create an inheritance hierarchy of Rodent: mouse, gerbil, hamster, guinea pig. In the base class, provide methods that are common to all rodents based on behaviours you find with a quick Internet search. Be sure to document the behaviours you implement (e.g., eat, sleep, groom, move, etc.). Each behaviour should print its action to standard output (e.g., rodent eating). Next, refine these behaviours in the child classes to perform different behaviours, depending on the specific type...
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery...
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include data members representing the name, address, city, state and ZIP...
Given the following business scenario, create a Crow’s Foot ERD using a specialization hierarchy if appropriate....
Given the following business scenario, create a Crow’s Foot ERD using a specialization hierarchy if appropriate. Two-Bit Drilling Company keeps information on employees and their insurance dependents. Each employee has an employee number, name, date of hire, and title. If an employee is an inspector, then the date of certification and the renewal date for that certification should also be recorded in the system. For all employees, the Social Security number and dependent names should be kept. All dependents must...
Java programming question:Consider the inheritance hierarchy in the figure on the next page.The top...
Java programming question:Consider the inheritance hierarchy in the figure on the next page. The top of the hierarchy begins with class Shape, which is extended by subclasses TwoDShape and ThreeDShape, corresponding to 2D and 3D shapes, respectively. The third level of this hierarchy contains specific types of 2D and 3D shapes such as circles and spheres, respectively. The arrows in the graph represent is a(inheritance) relationships and the boxes represent classes. For example, a Triangle is a TwoDShape, which in...
JAVA: *USING INHERITANCE *USING SUPER IN TH CONSTRUCTOR *USING SUPER IN THE METHOD *METHOD OVERRIDING Create...
JAVA: *USING INHERITANCE *USING SUPER IN TH CONSTRUCTOR *USING SUPER IN THE METHOD *METHOD OVERRIDING Create an application with 5 classes: 1.) Vehicle 2.) Car 3.) Bus 4.) Truck 5.) Tester Following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassengers, isCpnvertable, numberSeats, maxWeightLoad, numberAxels **Class Vehicle: should have a constructor that initializes all of it's data **Classes Car, Bus, Truck: will have constructors that resuse their parents constructors and provide additional code for initalizing their specific data...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions:...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions: Simulation Calculation Interface apps
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT