Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in C++, comments, need to see the output please 1) Consider the following class: class Employee { private: string name; const long officeNo;

Need help in C++, comments, need to see the output please

1) Consider the following class:

class Employee

{

private:

string name;

constlong officeNo;

constlong empId;

int deptNo;

char empPosition; // E: entry level, M: manager, D: Director, P:Project_leader

int yearOfExp;

float salary;

static int totalNumofEmployees;

static int nextEmpId;

static int nextOfficeNo;

public:

Employee();

~Employee();

Employee(string theName, int theDeptNo, char theEmpPosition, int theYearOfExp);

void Print()const;

void GetInfo();

}

The default constructor sets name to Unknown, Office Number to nextOfficeNo, Employee number to the value of nextEmpId, Department number to 0, Employee Position to Entry level, year of experience to 0, and salary to 0. It also ensures that the values of all static attributes are incremented by 1.

The second constructor sets the attributes based on what is passed to the function. The value of Employee Salary would still be set to 0 and the values of Office Number and Employee number are set to nextOfficeNo and nextEmpId, respectively. Again, the constructor should increment the values of all static attributes by 1.

The Print function should print all values of all attributes (regular, constants, and static) on the screen.

The GetInfo() function should prompt the user for the name, Employee position, and year of experience.

Create a c-style (stand alone) function called SetSalary(Employee&)that takes an employee object and sets the salary of the employee according to the following rules:

- If position is entry and number of experience is less than 2 years, sets the salary to 50000.

- If position is entry and number of experience is greater than or equal to 2 years, sets the salary to 55000.

- If position is project leader and number of experience is less than 4 years, sets the salary to 60000.

- If position is project leader and number of experience is greater than or equal to 4 years sets the salary to 65000.

- If position is manager, set the salary to 70000.

- If position is director, set the salary to 80000.

Make the SetSalary(Emplyee&) function to be the friend of class Employee so that it can access the private attributes in there.

The value of totalNumOfEmployees must be initialized to 0 before creating any object, be incremented upon creating each object of class Employee (in every constructor), and be decremented when an object of class Employee goes out of scope (in destructor).

The value of nextEmpId must be initialized to 1000 before creating any object, and must be incremented upon creating each object of class Employee in every constructor.

The value of nextOfficeNo must be initialized to 10 before creating any object, and must be incremented upon creating each object of class Employee in every constructor.

Write a driver program (main program ) to do the following:

Create an object, emp1, which calls the default constructor right upon its creation. Then call the print function to print the information of emp1 on the screen

Create another object, emp2, such the right upon its creation the employee name is set to unknown, the department number is set to 10, the employee office number becomes the value of nextOfficeNo, employee id becomes the value of nextEmpId, employee position becomes ?, year of experience becomes 0.

Use the object emp2 to call the GetInfo() function to prompt the user for setting name, employee position, and year of experience. Input Adam Smith for name, P (project leader) for employee position and 7 for the year of experience.

Call the SetSalary function and pass emp2 to the function to find and set the value of salary for emp2.

Call the Print function to print the information of emp2 on the screen.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books