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

PLEASE WRITE THE CODE USING THE TEMPLATE GIVEN BELOW. // Chapter 13, Programming

ID: 3837211 • Letter: P

Question

PLEASE WRITE THE CODE USING THE TEMPLATE GIVEN BELOW.

// Chapter 13, Programming Challenge 2: Employee Class
#include <iostream>
#include <string>
using namespace std;

// Employee Class Declaration

class Employee
{
private:
string name; // Employee's name
int idNumber; // ID number
string department; // Department name
string position; // Employee's position

public:
// TODO: Constructors

// TODO: Accessors

// TODO: Mutators
};

// Constructor #1
Employee::Employee(string n, int i, string d, string p)
{
// TODO
}

// Constructor #2
Employee::Employee(string n, int i)
{
// TODO
}

// Constructor #3, default constructor
Employee::Employee()
{
// TODO

}

// Function prototype
void displayEmployee(Employee);

// Driver program to demonstrate the class
int main()
{
// TODO: Create an Employee object to test constructor obj #1.

// TODO: Create an Employee object to test constructor obj #2.

// TODO: Create an Employee object to test constructor obj #3.

// Display each employee's data.
displayEmployee(/** TODO: obj #1 */);
displayEmployee(/** TODO: obj #2 */);
displayEmployee(/** TODO: obj #2 */);

return 0;
}

//**************************************************
// The displayEmployee function displays the data *
// in the Employee object passed as an argument. *
//**************************************************

void displayEmployee(Employee e)
{
// TODO
}

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 I 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. e The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them t 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 departme 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 ha written the class, write a separate program that creates three Employee objects to hold the following data ID Number Department Position Name 47899 Vice President Susan Meyers Accounting Programmer 39 119 Mark Jones 81774 Manufacturing Engineer loy Rogers The program should store this data in the three objects and then display the data for each employee on the screen

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
// Employee Class Declaration
class Employee
{
private:
string name; // Employee's name
int idNumber; // ID number
string department; // Department name
string position; // Employee's position

public:
// TODO: Constructors
Employee();
Employee(string n, int i, string d, string p);
Employee(string n, int i);
// TODO: Accessors
int getIdNumber() {
return idNumber;
}
string getName(){
return name;
}
string getDepartment() {
return department;
}
string getPosition(){
return position;
}// TODO: Mutators
void setIdNumber(int id){
idNumber = id;
}
void setName(string n) {
name = n;
}
void setDepartment(string d) {
department = d;
}
void setPosition(string p) {
position = p;
}
};
// Constructor #1
Employee::Employee(string n, int i, string d, string p)
{
// TODO
name = n;
idNumber = i;
department = d;
position = p;
}
// Constructor #2
Employee::Employee(string n, int i)
{
// TODO
name = n;
idNumber = i;

  
}
// Constructor #3, default constructor
Employee::Employee()
{
// TODO
}
// Function prototype
void displayEmployee(Employee);
// Driver program to demonstrate the class
int main()
{
// TODO: Create an Employee object to test constructor obj #1.
Employee e1("Susam Meyers",47899, "Accounting", "Vice Precident");
// TODO: Create an Employee object to test constructor obj #2.
Employee e2("Mark Jones",39119);
e2.setDepartment("IT");
e2.setPosition("Programmer");
// TODO: Create an Employee object to test constructor obj #3.
Employee e3;
e3.setName("Joy Rogers");
e3.setIdNumber(81774);
e3.setDepartment("Manufacturing");
e3.setPosition("Enginner");
// Display each employee's data.
displayEmployee(e1);
displayEmployee(e2);
displayEmployee(e3);

return 0;
}
//**************************************************
// The displayEmployee function displays the data *
// in the Employee object passed as an argument. *
//**************************************************
void displayEmployee(Employee e)
{
// TODO
cout<<e.getName()<<" "<<e.getIdNumber()<<" "<<e.getDepartment()<<" "<<e.getPosition()<<endl;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Susam Meyers    47899   Accounting      Vice Precident                                                                                                                                                                                                                 

Mark Jones      39119   IT      Programmer                                                                                                                                                                                                                             

Joy Rogers      81774   Manufacturing   Enginner

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