SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Inheritance
Exercise:
Self-test Exercises
Question:6 | ISBN:9780321531346 | Edition: 7

Question

Give the definitions of the constructors for the class TitledEmployee that you gave as the answer to Self-Test Exercise 5. Also, give the redefinition of the member function set_name. The function set_name should insert the title into the name.

Do not bother with #include directives or namespace details.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

namespace employees

{

TitledEmployee::TitledEmployee( )

: SalariedEmployee( ), title("No title yet")

{


}

TitledEmployee::TitledEmployee(string the_name,

string the_title,

string the_ssn, double the_salary)

: SalariedEmployee(the_name, the_ssn, the_salary),

title(the_title)

{

}

void TitledEmployee::set_name(string the_name)

{

Employee::set_name(title + the_name);

}

}

0 0

Discussions

Post the discussion to improve the above solution.