The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 312 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Hi, I need help with the following:
Â
Write a class named Employee that has the following member variables:
The class should have the following constructors:
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;
}
Â
Â
Â
THANK YOU FOR YOUR HELP!!
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly