Question
QUESTION 2 Consider the class definition for Employee shown below. Write the implementations for the three constructors as they would be written in the implementation
QUESTION 2
Consider the class definition for Employee shown below. Write the implementations for the three constructors as they would be written in the implementation file. Assume that the parameters to the constructors are intended to initialize the similarly named member variables. Choose reasonable default values for member variables that do not have a corresponding parameter given. You may assume that any required system libraries have been included, and that "using namespace std;" is in place. Give only the function implementations.
class Employee { private: std::string name; // Employee's name int numOfServiceYears; // Employee's years of service double salary; // Employee's annual salary public: Employee(); Employee(std::string initName, int initServiceYears, double initSalary); Employee(std::string initName, double initSalary); void setName (std::string empName); void setServiceyears (int empServiceYears); void setSalary (double empSalary); // Accessor functions go here... };
QUESTION 3
Consider, again, the Employee class definition from the previous question. Write three accessor functions called getName, getServiceYears, and getSalary to retrieve the values of the similarly named private member variables. Write your three functions inline, as if your code is to be inserted at the location of the comment, "Accessor functions go here".
Again for the Employee class declaration, declare three Employee objects named emp1, emp2, and emp3, as they might be declared in a main function. For emp1, use the default constructor. For emp2, declare the object making use of the second constructor. For emp3, declare the object making use of the third constructor. Use any sample values for initialization. Give only the code for the variable declarations.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started