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

IN C++ Output should be: 2. Employee Class Write a class named Employee that has

ID: 3889697 • Letter: I

Question

IN C++

Output should be:

2. 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, depart ment, 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 Susan Meyers Mark Jones Joy Rogers D Number 47899 39119 81774 Department Accounting IT Manufacturing Position Vice President Programmer ngineer The program should store this data in the three objects and then display the data for each employee on the screen.

Explanation / Answer

// Header files section
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class Employee
{
private:
   // member variables
   string name;
   int idNumber;
   string department;
   string position;

public:
   // constructors
   Employee(string aName, int anIDNumber, string aDepartment, string aPosition);
   Employee(string aName, int anIDNumber);
   Employee();

   // mutator functions
   void setName(string aName);
   void setIdNumber(int anIDNumber);
   void setDepartment(string aDepartment);
   void setPosition(string aPosition);

   // accessor functions
   string getName() const;
   int getIdNumber() const;
   string getDepartment() const;
   string getPosition() const;
};
#endif

File: Employee.cpp

// Employee class implementation
#include "Employee.h"

// four arguments constructor
Employee::Employee(string aName, int anIDNumber, string aDepartment, string aPosition)
{
   name = aName;
   idNumber = anIDNumber;
   department = aDepartment;
   position = aPosition;
} // end of constructor

// two arguments constructor
Employee::Employee(string aName, int anIDNumber)
{
   name = aName;
   idNumber = anIDNumber;
   department = "";
   position = "";
} // end of constructor

// default constructor
Employee::Employee()
{
   name = "";
   idNumber = 0;
   department = "";
   position = "";
} // end of constructor

// setName function implementation
void Employee::setName(string aName)
{
   name = aName;
}

// setIdNumber function implementation
void Employee::setIdNumber(int anIDNumber)
{
   idNumber = anIDNumber;
}

// setDepartment function implementation
void Employee::setDepartment(string aDepartment)
{
   department = aDepartment;
}

// setPosition function implementation
void Employee::setPosition(string aPosition)
{
   position = aPosition;
}

// getName function implementation
string Employee::getName() const
{
   return name;
}

// getIdNumber function implementation
int Employee::getIdNumber() const
{
   return idNumber;
}

// getDepartment function implementation
string Employee::getDepartment() const
{
   return department;
}

// getPosition function implementation
string Employee::getPosition() const
{
   return position;
}

File: Driver.cpp

// Header files section
#include "Employee.h"

// start main function
int main()
{
   // create the first object for Employee class
   Employee empObj1("Susan Meyers", 47899, "Accounting", "Vice President");

   // create the second object for Employee class
   Employee empObj2("Mark Jones", 39119);
   empObj2.setDepartment("IT");
   empObj2.setPosition("Programmer");

   // create the third object for Employee class
   Employee empObj3;
   empObj3.setName("Joy Rogers");
   empObj3.setIdNumber(81774);
   empObj3.setDepartment("Manufacturing");
   empObj3.setPosition("Engineer");


   // display the details of three employees
   cout << "--------------------------------------------------------" << endl;
   cout << left << setw(15) << "Name"
       << setw(12) << "ID Number"
       << setw(15) << "Department"
       << setw(15) << "Position" << endl;
   cout << "--------------------------------------------------------" << endl;
   cout << setw(15) << empObj1.getName()
       << setw(12) << empObj1.getIdNumber()
       << setw(15) << empObj1.getDepartment() << setw(15) << empObj1.getPosition()
       << endl;
   cout << setw(15) << empObj2.getName()
       << setw(12) << empObj2.getIdNumber()
       << setw(15) << empObj2.getDepartment() << setw(15) << empObj2.getPosition()
       << endl;
   cout << setw(15) << empObj3.getName()
       << setw(12) << empObj3.getIdNumber()
       << setw(15) << empObj3.getDepartment() << setw(15) << empObj3.getPosition()
       << endl;
   cout << "--------------------------------------------------------" << endl;

   // pause the system for a while
   system("pause");
   return 0;
} // end of main function