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?
Using C++ Create a polymorphic banking program using the Bank-Account hierarchy created in Exercise 2 of...
Using C++ Create a polymorphic banking program using the Bank-Account hierarchy created in Exercise 2 of Written Assignment 4. For each account in the vector, allow the user to specify an amount of money to withdraw from the Bank-Account using member function debit and an amount of money to deposit into the Bank-Account using member function credit. As you process each Bank-Account, determine its type. If a Bank-Account is a Savings, calculate the amount of interest owed to the Bank-Account...
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...
C++ Programming. Create a class hierarchy to be used in a university setting. The classes are...
C++ Programming. Create a class hierarchy to be used in a university setting. The classes are as follows: The base class isPerson. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The classshould also have a static data member called nextID which is used to assignanID numbertoeach object created(personID). All data members must be private. Create the following member functions: Accessor functions to allow access to first name and last name (updates and retrieval). These functions should...
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...
Given the following business scenario, create a Crow’s Foot ERD using a specialization hierarchy (EER) if...
Given the following business scenario, create a Crow’s Foot ERD using a specialization hierarchy (EER) 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 a full-time inspector, then the date of certification, the renewal date for that certification, and the yearly salary should also be recorded in the system. If an employee is a part-time inspector, then the date of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT