[Solved] Write a class named Employee

$25

File Name: Write_a_class_named_Employee.zip
File Size: 263.76 KB

SKU: [Solved] Write a class named Employee Category: Tag:
5/5 - (1 vote)

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

  • name. a string that holds the employees name.
  • idNumber. an int variable that holds the emlpoyees ID number.
  • department. a string that holds the name of the department where the employee works.
  • position. a string that holds the employees 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: employees name, employees ID number, department, and position.
  • A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employees 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 values. 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

The program should store this data in three objects and then display the data for each employee on the screen.

I have included my codes in text below:

Main

#include stdafx.h

#include employee.h

#include

#include

#include

using namespace std;

int main()

{

//create 1st object for empployee class

Employee worker1;

worker1.setNameOfEmployee(Susan Meyers);

worker1.setIdNumberOfEmployee(47899);

worker1.setDepartmentOfEmployee(Accounting);

worker1.setPositionOfEmployee(Vice President);

//create 2nd object for employee class

Employee worker2;

worker2.setNameOfEmployee(Mark Jones);

worker2.setIdNumberOfEmployee(39119);

worker2.setDepartmentOfEmployee(IT);

worker2.setPositionOfEmployee(Programmer);

//create 3rd object for employee class

Employee worker3;

worker3.setNameOfEmployee(Joy Rogers);

worker3.setIdNumberOfEmployee(81774);

worker3.setDepartmentOfEmployee(Maufacturing);

worker3.setPositionOfEmployee(Engineer);

//display 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) << worker1.getNameOfEmployee()

<< setw(12) << worker1.getNumberOfEmployee()

<< setw(15) << worker1.getDepartmentOfEmployee()

<< setw(15) << worker1.getPositionOfEmployee() << endl;

cout << setw(15) << worker2.getNameOfEmployee()

<< setw(12) << worker2.getNumberOfEmployee()

<< setw(15) << worker2.getDepartmentOfEmployee()

<< setw(15) << worker2.getPositionOfEmployee() << endl;

cout << setw(15) << worker3.getNameOfEmployee()

<< setw(12) << worker3.getNumberOfEmployee()

<< setw(15) << worker3.getDepartmentOfEmployee()

<< setw(15) << worker3.getPositionOfEmployee() << endl;

cout << << endl;

system(pause);

return 0;

}

Employee.h

//Empployee class declaration

//Employee.h

#pragma once

#ifndef EMPLOYEE_H

#define EMPLOYEE_H

#include

using namespace std;

class Employee

{

private:

//declaration of member variables to store the data of an employee

string name;

int idNumber;

string department;

string position;

public:

//declaration of constructors to initialize the member variables with appropriate values

Employee(string, int, string, string);

Employee(string, int);

Employee();

//declaration of mutator function to store the specified values in the member variables

void setNameOfEmployee(string);

void setIdNumberOfEmployee(int);

void setDepartmentOfEmployee(string);

void setPositionOfEmployee(string);

//declaration of accessor functions to return the current values in the member variables

string getNameOfEmployee() const;

int getIdNumberOfEmployee() const;

string getDepartmentOfEmployee() const;

string getPositionOfEmployee() const;

};

#endif

Employee.cpp

//Employee class implementation

//Employee.cpp

#include Employee.h

#include

using namespace std;

//constructor with four arguments

Employee::Employee(string newNameOfEmployee, int newIdNumberOfEmployee,

string newDepartmentOfEmployee, string newPositionOfEmployee)

{

name = newNameOfEmployee;

idNumber = newIdNumberOfEmployee;

department = ;

position = ;

}

//constructor with no arguments

Employee::Employee()

{

name = ;

idNumber = 0;

department = ;

position = ;

}

//setNameOfEmployee implementation

void Employee::setNameOfEmployee(string newNameOfEmployee)

{

name = newNameOfEmployee;

}

//setIdNumberOfEmployee implementation

void Employee::setIdNumberOfEmployee(int newIdNumberOfEmployee)

{

idNumber = newIdNumberOfEmployee;

}

//setDepartmentOfEmployee implementation

void Employee::setDepartmentOfEmployee(string newDeparmentOfEmployee)

{

department = newDepartmentOfEmployee;

}

//setPositionOfEmployee implementation

void Employee::setPositionOfEmployee(string newPositionOfEmployee)

{

position = newPositionOfEmployee;

}

//getNameOfEmployee implementation

string Employee::getNameOfEmployee() const

{

return name;

}

//getIdNumberOfEmployee implementation

int Employee::getIdNumberOfEmployee() const

{

return idNumber;

}

//getDepartmentOfEmployee implementation

string Employee::getDepartmentOfEmployee() const

{

return department;

}

//getPositionOfEmployee

string Employee::getPositionOfEmpoyee() const

{

return position;

}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Write a class named Employee
$25