C++Define an Employee class Solution

Using C++ program language:

1. Define an Employee class. Add the following private date members to the class: string status, int dependents. Status represents the marital status of the employee and should be set to either “m” or “s”. Add mutator/set and accessor/get methods for each of the new private data members. You must also revise the class constructors and the print method in the class to display all private data members.

2. Include a public method “taxDeduction()” that should inspect the weeklyPay of the employee object and then based on the number of dependents and marital status return the tax deduction from a weekly pay based on the following table



% tax deduction


%tax deduction

Less than or equal to 2









Greater than or equal to 5




4. Write a main function to test the class Employee. Create an object of the type Employee and call it myE then print the object and display the tax deduction from the weekly pay.

5. Add the following to your main function:

• Create two Employee pointer variables ptr1 and ptr2 and set them to NULL.

• Make ptr1 point to the Employee myE created in part 3.

• Dynamically allocated an Employee object and make ptr2 point to it.

• Use the two pointers to call the print method of the object they point to.

• Use ptr1 to change the value of the “dependents” of the myE

• Now make ptr2 point to myE. How many pointers are pointing to the Employee object myE? What happened to the dynamically created object that ptr2 was pointing to? What were you supposed to do before making ptr2 point to myE?

Powered by