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

I need this in C++. In the solutions they show how to add the getters and setter

ID: 3596889 • Letter: I

Question

I need this in C++. In the solutions they show how to add the getters and setters in a seperate CPP file, but I would like to have it all in the .h file for my class

Employee Class

Write a class named Employee that has the following member variables:

name. A string that holds the employee’s name.

idNumber. An int variable that holds the employee’s ID number.

department. A string that holds the name of the department where the employee works.

position. A string that holds the employee’s job title.

The class should have the following constructors:

A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name, employee’s ID number, department, and position.

A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name and ID number. The department and position fields should be assigned an empty string ("").

A default constructor that assigns empty strings ("") to the name, department, and position member variables, and 0 to the idNumber member variable.

Write appropriate mutator functions that store values in these member variables and accessor functions that return the values in these member variables. Once you have written the class, write a separate program that creates three Employee objects to hold the following data.

Name ID Number Department Position Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineer

Explanation / Answer


Employee.hpp

---------------------------------------------------------------------------------------------------

#include <string>

class Employee

{

private :

std :: string employeeName;

int employeeIdNumber;

std :: string employeeDept;

std :: string employeePos;

public :

/* constructors */

Employee(std :: string name, std :: string dept, std :: string pos, int id);

Employee(std :: string name, int id);

Employee();

/* setter methods for variables */

void setName(std :: string name);

void setId(int id);

void setDept(std :: string dept);

void setPos(std :: string pos);

/* getter methods */

std :: string getName();

std :: string getDept();

std :: string getPos();

int getId();

};

Employee.hpp

----------------------------------------------------------------------------------------

#include <string>

#inlcude <iostream>

Employee :: Employee( std :: string name, std :: string dept, std :: string pos, int id)

{

employeeName = name;

employeeDept = dept;

employeePos = pos;

employeeIdNumber = id;

}

Employee :: Employee( std :: string name, int id)

{

employeeName = name;

employeeIdNumber = id;

employeePos = "";

employeeDept = "";

}

Employee :: Employee()

{

employeeName = "";

employeeIdNumber = 0;

employeePos = "";

employeeDept = "";

}

void Employee :: setName( std :: string name )

{

employeeName = name;

}

void Employee :: setId( int id )

{

employeeIdNumber = id;

}

void Employee :: setDept( std :: string dept )

{

employeeDept = dept;

}

void Employee :: setPos( std :: string pos )

{

employeePos = pos;

}

std :: string Employee :: getName()

{

return employeeName;

}

std :: string Employee :: getDept()

{

return employeeDept;

}

std :: string Employee :: getPos()

{

return employeePos;

}

int Employee :: getId()

{

return employeeId;

}

Main.cpp

------------------------------------------------------------------------------------------------------------------

#include <iostream>

#include <string>

int main()

{

/* declaring the instances of Employees */

Employee e1 = new Employee("Susan Meyers","Accounting","Vice President",47899);
Employee e2 = new Employee("Mark Jones","IT","Programmer",39119);
Employee e3 = new Employee("Joy Rogers","Manufacturing","Engineer",81774);

/* printing the details */
std :: cout << "Name " << "ID Number " << "Department " << "Position ";
std :: cout << e1.getName() << " " << e1.getId() << " " << e1.getDept() << " " << e1.getPos() << " ";
std :: cout << e2.getName() << " " << e2.getId() << " " << e2.getDept() << " " << e2.getPos() << " ";
std :: cout << e3.getName() << " " << e3.getId() << " " << e3.getDept() << " " << e3.getPos() << " ";

return 0;
}

/* hope this helps */

/* if any queries, please comment */

/* thank you */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote