54.7k views
1 vote
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.

User Nba
by
6.1k points

1 Answer

4 votes

Answer:

See explanation

Step-by-step explanation:

i. employee tempEmployee;

Here an object of class is created. So when an object is created, the constructor is called. So

the line number containing the constructor that is executed in this declaration is:

employee ();

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

This is the call to a parameterized constructor. Since it is passing three values to constructor so the constructor with three parameters is invoked here.

employee(string, int, double);

iii employee oldEmployee ("Bill Dunbar", 15, 55000);

This is the call to a parameterized constructor. Since it is passing three values to constructor so the constructor with three parameters is invoked here.

employee(string, int, double);

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

employee::employee()

{

name = "";

numOfSerivceYears = 0

salary = 0.0;

}

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

employee::employee(string empName, int years, double sal) {

name = empName;

numOfSerivceYears = years;

salary = sal; }

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 parameters

employee::employee(int years, double sal) {

numOfServiceYears = years;

salary = sal; }

User Mhradek
by
5.4k points