(I NEED C++ CODE)Write a class named Employee that has the following member vari
ID: 3846895 • Letter: #
Question
(I NEED C++ CODE)Write a class named Employee that has the following member variables:
name: The name attribute holds an employee’s first and last name
idNumber: The idNumber attribute is a string variable that holds an employee’s ID number
department: The department attribute holds the name of the employee’s department
position: The position attribute holds the name of the employee’s job title
yearsWorked: This attribute holds the number of years the employee has worked at the company
The class should have the following overloaded constructors:
A constructor that accepts the following values as arguments and assigns them to the appropriate data members (attributes): employee’s name and employee’s ID number, employee’s department, employee’s position, and the number of years the employee has worked at the company.
A constructor that accepts the fallowing values as arguments and assigns them to the appropriate data members (attributes): employee’s name and employee’s ID number. The department and positionattributes should be initialized to the empty string (“”) and the yearsWorked attribute should be initialized to zero.
A default constructor (accepts no arguments) that initializes the name, idNumber, department, andposition attributes to the empty string (“”). The yearsWorked attribute should be initialized to zero.
Write Get and Set methods for each attribute: name, idNumber, department, position, and yearsWorked.
Do not allow the yearsWorked attribute to be set to values less than zero. If an attempt is made to setyearsWorked to less than zero, do not set the attribute and communicate the problem to the calling program. Do not use cin or cout in the set method.
Remember that the class declaration (.h file) will contain the class attributes and function prototypes. Name the class declaration file employee.h. The class implementation file (.cpp) will contain the function definitions (don’t forget to include the employee.h file). Name the class implementation file employee.cpp.
Next create a program to utilize the Employee class you created in the following manner:
1. CREATE AN ARRAY OF SIZE THREE OF THE DATA TYPE EMPLOYEE. Add the three following Employee objects to your array:
Name
ID Number
Department
Position
Years Worked
Jenny Jacobs
JJ8990
Accounting
President
15
Myron Smith
MS7571
IT
Programmer
5
Chris Raines
CR6873
Manufacturing
Engineer
30
2. Display the data for each of the three employees to the screen (you do not need to display the lines in the table)
The program utilizing the employee class should be in a separate .cpp file. Name this program employeeTest.cpp.
Name
ID Number
Department
Position
Years Worked
Jenny Jacobs
JJ8990
Accounting
President
15
Myron Smith
MS7571
IT
Programmer
5
Chris Raines
CR6873
Manufacturing
Engineer
30
Explanation / Answer
employeeTest.cpp
#include <string
#include "Employee.h"
using namespace std;
Employee::Employee(string name,string idNumber,string department,string position,int yearsWorked)
{
this->name = name ;
this-> idNumber = idNumber;
this->department = department;
this->position = position;
this->yearsWorked >= yearsWorked;
}
Employee::Employee(string name,string idNumber)
{
this->name = name ;
this-> idNumber = idNumber;
department = "";
position = "";
yearsWorked = 0;
}
Employee::Employee()
{
name = "" ;
idNumber = "";
department = "";
position = "";
yearsWorked = 0;
}
void Employee::setName(string name)
{
this->name = name;
}
void Employee:: setIdNumber(string idNumber)
{
this->idNumber = idNumber;
}
void Employee:: setDepartment(string department)
{
this->department = department;
}
void Employee:: setPosition(string position)
{
this->position = position;
}
bool Employee::setYearsWorked(int yearsWorked)
{
if(yearsWorked >=0)
{
this->yearsWorked = yearsWorked;
return true;
}
else
return false;
}
string Employee::getName()
{
return name;
}
string Employee::getIdNumber()
{
return idNumber;
}
string Employee::getDepartment()
{
return department;
}
string Employee::getPosition()
{
return position;
}
int Employee::getYearsWorked()
{
return yearsWorked;
}
Employee.cpp
#include <string
#include "Employee.h"
using namespace std;
Employee::Employee(string name,string idNumber,string department,string position,int yearsWorked)
{
this->name = name ;
this-> idNumber = idNumber;
this->department = department;
this->position = position;
this->yearsWorked >= yearsWorked;
}
Employee::Employee(string name,string idNumber)
{
this->name = name ;
this-> idNumber = idNumber;
department = "";
position = "";
yearsWorked = 0;
}
Employee::Employee()
{
name = "" ;
idNumber = "";
department = "";
position = "";
yearsWorked = 0;
}
void Employee::setName(string name)
{
this->name = name;
}
void Employee:: setIdNumber(string idNumber)
{
this->idNumber = idNumber;
}
void Employee:: setDepartment(string department)
{
this->department = department;
}
void Employee:: setPosition(string position)
{
this->position = position;
}
bool Employee::setYearsWorked(int yearsWorked)
{
if(yearsWorked >=0)
{
this->yearsWorked = yearsWorked;
return true;
}
else
return false;
}
string Employee::getName()
{
return name;
}
string Employee::getIdNumber()
{
return idNumber;
}
string Employee::getDepartment()
{
return department;
}
string Employee::getPosition()
{
return position;
}
int Employee::getYearsWorked()
{
return yearsWorked;
}
Employee.h
using namespace std;
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee
{
private:
string name;
string idNumber;
string department;
string position;
int yearsWorked;
public:
Employee(string name,string idNumber,string department,string position,int yearsWorked);
Employee(string name,string idNumber);
Employee();
void setName(string name);
void setIdNumber(string idNumber);
void setDepartment(string department);
void setPosition(string position);
bool setYearsWorked(int yearsWorked);
string getName();
string getIdNumber();
string getDepartment();
string getPosition();
int getYearsWorked();
};
#endif
Output:
employeeTest.cpp
#include <string
#include "Employee.h"
using namespace std;
Employee::Employee(string name,string idNumber,string department,string position,int yearsWorked)
{
this->name = name ;
this-> idNumber = idNumber;
this->department = department;
this->position = position;
this->yearsWorked >= yearsWorked;
}
Employee::Employee(string name,string idNumber)
{
this->name = name ;
this-> idNumber = idNumber;
department = "";
position = "";
yearsWorked = 0;
}
Employee::Employee()
{
name = "" ;
idNumber = "";
department = "";
position = "";
yearsWorked = 0;
}
void Employee::setName(string name)
{
this->name = name;
}
void Employee:: setIdNumber(string idNumber)
{
this->idNumber = idNumber;
}
void Employee:: setDepartment(string department)
{
this->department = department;
}
void Employee:: setPosition(string position)
{
this->position = position;
}
bool Employee::setYearsWorked(int yearsWorked)
{
if(yearsWorked >=0)
{
this->yearsWorked = yearsWorked;
return true;
}
else
return false;
}
string Employee::getName()
{
return name;
}
string Employee::getIdNumber()
{
return idNumber;
}
string Employee::getDepartment()
{
return department;
}
string Employee::getPosition()
{
return position;
}
int Employee::getYearsWorked()
{
return yearsWorked;
}
Employee.cpp
#include <string
#include "Employee.h"
using namespace std;
Employee::Employee(string name,string idNumber,string department,string position,int yearsWorked)
{
this->name = name ;
this-> idNumber = idNumber;
this->department = department;
this->position = position;
this->yearsWorked >= yearsWorked;
}
Employee::Employee(string name,string idNumber)
{
this->name = name ;
this-> idNumber = idNumber;
department = "";
position = "";
yearsWorked = 0;
}
Employee::Employee()
{
name = "" ;
idNumber = "";
department = "";
position = "";
yearsWorked = 0;
}
void Employee::setName(string name)
{
this->name = name;
}
void Employee:: setIdNumber(string idNumber)
{
this->idNumber = idNumber;
}
void Employee:: setDepartment(string department)
{
this->department = department;
}
void Employee:: setPosition(string position)
{
this->position = position;
}
bool Employee::setYearsWorked(int yearsWorked)
{
if(yearsWorked >=0)
{
this->yearsWorked = yearsWorked;
return true;
}
else
return false;
}
string Employee::getName()
{
return name;
}
string Employee::getIdNumber()
{
return idNumber;
}
string Employee::getDepartment()
{
return department;
}
string Employee::getPosition()
{
return position;
}
int Employee::getYearsWorked()
{
return yearsWorked;
}
Employee.h
using namespace std;
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee
{
private:
string name;
string idNumber;
string department;
string position;
int yearsWorked;
public:
Employee(string name,string idNumber,string department,string position,int yearsWorked);
Employee(string name,string idNumber);
Employee();
void setName(string name);
void setIdNumber(string idNumber);
void setDepartment(string department);
void setPosition(string position);
bool setYearsWorked(int yearsWorked);
string getName();
string getIdNumber();
string getDepartment();
string getPosition();
int getYearsWorked();
};
#endif
Output:
jenny Jacobs JJ8990 Accounting President 15
Myron Smith MS7571 IT Programmer 5
Chris Raines CR6873 Manufacturing Engineering
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.