Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++. 8. Derivation is one way to build one class from another so that the new class can be used in place of the original.
C++.
8. Derivation is one way to build one class from another so that the new class can be used in place of the original. For example, a HourlyEmployee could be derived from Employee, making "a HourlyEmployee a kind of Employee". (a) Such a derivation is often called inheritance, when the derived class (here, HourlyEmployee) "gets" all of the members of its base (here, HourlyEmployee) as its own. Pro- vided the following UML diagram, write a class declaration for Employee and HourlyEmployee, such that HourlyEmployee is a subtype of Employee. Make sure that the base portion of the derived class is constructed with the base class s constructor Employee - name : std:string + Employee) +Employee(std:.string) + set name(std:.string) + get name): std:string HourlyEmployee - hourly wage: double - hours_worked: double + HourlyEmployee() +HourlyEmployee( name: std::string, hourly wage : double) + set hours worked( double ) + get hours_worked(): double + weekly-pay): double (b) Provided the following UML diagram, write a class declaration for Salar iedEmployee. such that it is also a subtype of Employee. Make sure that the base portion of the derived class is constructed with the base class s constructor. Employee - name : std::string + Employee() + Employee(std::string) + set name(std:string) + get name(): std::string HourlyEmployee SalariedEmployee - hourly_wage : double - hours_worked: double +HourlyEmployee( + HourlyEmployee( name: std:string, hourly wage: double) + set hours worked( double ) +get hours worked(): double + weekly-pay (): double annual salary: double +SalariedEmployee) +SalariedEmployee( name : std::Sstring, annual salary: double ) +weekly-pay (): double (c) A class is abstract if it can only be used as a base class. Assume that we are writing this class hierarchy for an application where it doesn t make sense to have a general Employee object, only particular employees, such as HourlyEmployees and SalariedEmployees. Without declaring a pure virtual function (which is the more common way to create an abstract base class), how could you prevent users from creating Employee objects? Remember, the derived classes need access to the base class s constructor to construct the base portion of the derived classStep 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