Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

consider the definition of the following class: (1,2,3,5,7) class emplyee { publ

ID: 3564106 • Letter: C

Question

consider the definition of the following class: (1,2,3,5,7)

class emplyee

{

public:

emplyee ();

emplyee (string,int,double);

emplyee(int,double);

employee (string);

void setData (string,int, double);

void print () const;

void updateSalary (double x);

int getNumOfServiceYears() const;

double getSalary () const;

private:

string name;

int numOfServiceYears;

double salary;

};

a. Give the line number containing the constructor that is executed in each of the following declararions:

i. employee tempEmployee;

ii. emplyee newEmployee (" Harry Miller", 0,2500);

iii. employee oldEployee ("Bill Dunbar", 15, 55000);

b. Write the definition of the constructor in Line 4 so that the instance variables are initialized to " ", 0, and 0.0 ,respectively.

c. Write the definition of the constructor in LIne 5 so that the instance variables are initialized according to the parameters.

d. Write the definition of the constructor in line 6 so that the insurance variable name is initialized to empty string and the remaining instance variables are initialized according to the parmeters.

Explanation / Answer

class emplyee

{

public:

employee ()

{

name = "";

  numOfServiceYears = 0;

salary = 0.0;

}

employee (string Na,int Years,double sal)

{

name = Na;

  numOfServiceYears = Years;

salary = sal;

}

employee(int,double);

employee (string);

void setData (string,int, double);

void print () const;

void updateSalary (double x);

int getNumOfServiceYears() const;

double getSalary () const;

private:

string name;

int numOfServiceYears;

double salary;

};

a)

i) default Constructor line 4 is Executed.

ii) Parameterized Constructor line 10 is Executed.

iii) Parameterized Constructor line 10 is Executed.

b)

// initialized to " ", 0, and 0.0 ,respectively.

employee ()

{

name = "";

  numOfServiceYears = 0;

salary = 0.0;

}

c)

// initialized according to the parameters

employee (string Na,int Years,double sal)

{

name = Na;

  numOfServiceYears = Years;

salary = sal;

}

d)

// name is "" and remain initialized according to the parameters

employee (int Years,double sal)

{

name = "";

numOfServiceYears = Years;

salary = sal;

}