include and using directives are added)? void show_employee_data(const Employee object): int main( ) \(l\) HourlyEmpl… # Is the following program legal (assuming appropriate #include and using directives are added)? void show_employee_data(const Employee object): int main( ) \(l\) HourlyEmployee joe("Mighty Joe", \\[ \left." 123-45-6789^{\prime \prime}, \quad 2 \theta \cdot 5 \theta, \quad 4 \theta\right) \\] SalariedEmployee boss("Mr. Big Shot", "987-65-4321", 10500.50) ; show_employee_data(joe) show_employee_data(boss) return \(\theta\) \\} void show_employee_data(const Employee object) \\{ cout \(<<\) "Name: \("<<\) object.get_name( ) \(<<\) endl; cout \(<<\) "Social Security Number: \&< object.get_ssn( ) \(<<\) endl;

Short Answer

Expert verified
Answer: The given program can be made legal by making the following corrections: 1. Assuming 'HourlyEmployee' and 'SalariedEmployee' are derived from a base class 'Employee'. 2. Replacing the incorrect syntax for creating the 'HourlyEmployee' object, joe. 3. Verifying that the member functions used in 'show_employee_data()' exist in the 'Employee' base class and the derived classes. 4. Adjusting the main function to include the corrected objects and calling 'show_employee_data()' with them. 5. Ensuring the 'show_employee_data' function is set up correctly to take a constant reference to an 'Employee' object as its parameter. If the mentioned corrections are applied and the appropriate #include and using directives are added, the given program would be legal.

Step by step solution

01

Identify the class hierarchy

Assuming there are class 'Employee', 'HourlyEmployee', and 'SalariedEmployee', it is assumed 'HourlyEmployee' and 'SalariedEmployee' are derived from 'Employee'.
02

Replace incorrect syntax

Replace the given lines of code: \(l\) '\\[ \left." 123-45-6789^{\prime \prime}, \quad 2 \theta \cdot 5 \theta, \quad 4\theta\right) \\]' with the following: HourlyEmployee joe("Mighty Joe", "123-45-6789", 25.0, 40);
03

Identify member functions

Verify that 'Employee', 'HourlyEmployee', and 'SalariedEmployee' have member functions like 'get_name()' and 'get_ssn()'. Ensure that the member functions used in the 'show_employee_data()' function exist in the base class 'Employee', and derived classes 'HourlyEmployee' and 'SalariedEmployee'.
04

Check the main function

The main function should be like below, assuming the mentioned corrections are made: int main() { HourlyEmployee joe("Mighty Joe", "123-45-6789", 25.0, 40); SalariedEmployee boss("Mr. Big Shot", "987-65-4321", 10500.50); show_employee_data(joe); show_employee_data(boss); return 0; }
05

Check the show_employee_data function

Ensure that the function 'show_employee_data' is correctly set up and takes a constant reference to an 'Employee' object as its parameter: void show_employee_data(const Employee &object) { cout << "Name: " << object.get_name() << endl; cout << "Social Security Number: " << object.get_ssn() << endl; } Concluding remarks: If the mentioned corrections are applied and the appropriate #include and using directives are added, the given program would be legal.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Suppose Child is a class derived from the class Parent, and the class Grandchild is a class derived from the class Child. This question is concerned with the constructors and destructors for the three classes Parent, Child, and Grandchild. When a constructor for the class Grandchild is invoked, what constructors are invoked and in what order? When the destructor for the class Grandchild is invoked, what destructors are invoked and in what order?

Suppose the base class and the derived class each have a member function with the same signature. When you have a pointer to a base class object and call a function member through the pointer, discuss what determines which function is actually called-the base class member function or the derived-class function.

The class SalariedEmployee inherits both of the functions get_name and print_check (among other things) from the base class Employee, yet only the function declaration for the function print_check is given in the definition of the class SalariedEmployee. Why isn't the function declaration for the function get_name given in the definition of SalariedEmployee?

Give a definition for a class SmartBut that is a derived class of the base class Smart, which we reproduce for you here. Do not bother with winclude directives or namespace details. class smart \\{ public: Smart( ) : void print_answer() const; protected: int a : int \(b\) \(y\) This class should have an additional data field, crazy, that is of type bool, one additional member function that takes no arguments and returns a value of type \(b o o l,\) and suitable constructors. The new function is named is_crazy. You do not need to give any implementations, just the class definition.

Why can't we assign a base class object to a derived class variable?

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free