Answered step by step
Verified Expert Solution
Question
1 Approved Answer
language c++ In this assignment, another new concept - Inheritance - will be introduced, which extends the notion of reusability with Classes and Objects. Objectives
language c++
In this assignment, another new concept - Inheritance - will be introduced, which extends the notion of reusability with Classes and Objects. Objectives to be met 11 Demonstrate your understanding of how to define a Simple Inheritance with 3 classes. 2 Define objects that demonstrate the use of derived class constructors. | 3 Demonstrate how to override a member function. Use a model for two classes derived from the same "common" class as shown here: Base---> Insurance Derived---> AutoInsurance Home Insurance You will complete this assignment by writing a new class for the base class and each derived class based on the UML diagrams that accompany this assignment. The base class (Insurance) represents the attributes (data) and behavior (functions) common to both derived classes, whereas each derived class (Auto Insurance and Home Insurance) represents a different kind (type) of base class. Both derived classes are subclasses that derive (or "inherit") data and functions from the base class. The data and functions defined in the Insurance class will encapsulate only those characteristics that are common (general) to both derived classes, for example: annual premium, name of insured, and policy number, and methods for constructing and accessing those fields. Both derived classes will inherit (acquire) those features already defined in the base class. The data defined in both the Auto Insurance and Home Insurance classes will provide additional characteristics that are unique (specific) to only those policies. For example: the Auto Insurance class will define VIN number, whereas the HomeInsurance class will define address of the residency. Each of these classes also will define and/or modify other functions for constructing and accessing their data members. Minimum requirements The classes, their relationship, and their members must adhere to the UML diagram with one exception - you will later (in Step 6) change the access level for data members in the base class from protected to private. Your program must define at least 4 objects (2 for each derived class) demonstrating all 4 derived class constructors you will write. You should initialize 2 objects with literal values when using the constructors with arguments, but get user input and then call the setxxx member functions for the 2 objects defined by the default (0-arg) constructors. In both derived classes, override the toString() member function defined in the base class, and use this function to get the strings to display the data for each of the 4 objects. Use the initialization list with derived class constructors to pass data inherited from the base class to the appropriate constructor in that class. Change the data in the base class "private" (no longer protected as documented in the UML) and use (call) public base class member functions in the derived class where necessary. Include a total at the end of your output that is the sum of all 4 annual premiums. | 7 Considerations: Work with a modest number of fields and member functions to make testing your classes easier. For example, write your first derived class with just one field and two constructors and test it; then add the getxxx and set xxx functions and test those; Then try building that part of the toString() functions and test that; Finally, add other members until you get that entire class working. Then write the other derived class following the same pattern and test it. As you should know by now, waiting until the end before compiling and testing only makes debugging more complicated and more time consuming. (Impatience usually results in additional aggravation and setback)! Remember that private data members in a base class cannot be accessed directly by functions in derived classes, but protected base class data members can be accessed from derived classes. Obviously, constructors and access (observer) member functions should be declared public. Constructors are not inherited. Each class must define its own constructor(s). The same rules apply to each class: if no constructor is defined, a default will be provided; if one or more constructors with arguments are defined, there is no default unless you write one. Each derived class definition header must use the correct syntax along with the base class name to inherit the data and functions defined in the base class. Each member inherited also inherits the same access right that was used to define that member in the base class. Although constructors are not inherited, a derived class constructor may call a base class constructor from its initialization list to handle that part of the initialization. Otherwise, the compiler inserts a call to the base class default constructor (if one exists). Member "functions" defined protected or public in the base class may be used (called) by functions defined in each derived class and (if public) by objects of each derived class. When organizing the classes in your inheritance with a multi-file project, each class should be split into 2 separate files (6 all together): 3 containing the class declarations only and 3 containing the implementations (definitions) for those declarations. Your main program will be in a separate (7th) file, which will include" the 3 header files that declare each class. Additional Requirements: Include your name, course, section (CSC240) at the top of the EVERY program file as a comment. Submit all .cpp and .h files that you either created or modified. Any files that were provided that did NOT have changes do NOT need to be submitted. UML Diagram Insurance # Legend private protected public underline static # annual Premium : double # nameOfInsured : string # policyNumber : string + UPPERCASE constant + Insurance() + Insurance (premium: double, name:string, policyNo:string) + /* accessor (getxxx) members */ + /* mutator (setxxx) members */ + toString(): string "inherits from" - or - "is derived from" Auto Insurance - collisionAmount : double - liabilityAmount : double - vinNumber : string + AutoInsurance() + AutoInsurance (premium: double, name: string, policyNo:string, collision: double, liability: double, vinNo:string) + /* accessor (getxxx) members */ + /* mutator (setxxx) members */ + toString(): string Home Insurance - locationAddress : string - content sAmount : double - liabilityAmount : double + Home Insurance () + Home Insurance (premium: double, name:string, policyNo:string, address :string, contents: double, liability: double) + /* accessor (getxxx) members */ + /* mutator (setxxx) members */ + toString(): string Sample program output: Albert Anderson's Home and Auto Policies Home Insurance Annual Premium: 650.25 Name of Insured: Albert Anderson Policy Number: H-AA-67890 Location Address: 1234 Alberts Drive Contents Amount: 25000.00 Liability Amount: 100000.00 Auto Insurance Annual Premium: 425.50 Name of Insured: Albert Anderson Policy Number: A-AA-12345 Collision Amount: 50000.00 Liability Amount: 100000.00 VIN Number: ABC12345XYZ -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - Mary Merkle's Home and Auto Policies - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Home Insurance Annual Premium: 600.00 Name of Insured: Mary Merkle Policy Number: H-MM-09876 Location Address: 666 Mirkwood Forest Lane Contents Amount: 45000.00 Liability Amount: 90000.00 Auto Insurance Annual Premium: 500.00 Name of Insured: Mary Merkle Policy Number: A-MM-54321 Collision Amount: 40000.00 Liability Amount: 100000.00 VIN Number: A1B2345X6Y7Z8 Total Annual Premiums: 2175.75Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started