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, department, 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, create a three Employee objects (3 separate instances), in your main function, to hold the following data.
This is my code: It compiles, but can't get (Name,ID Number,Department,Position) to show up beside each entry!
EmployeeClass.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
ifndef Employee_Header
#define Employee_Header
#include <string>
using namespace std;
class Employee
{
private:
string name;
int idnumber;
string department;
string position;
public:
Employee(string n, string id)
{
string name = "";
string idnumber = "";
string department = " ";
string position = " ";
}
Employee(string n, int id, string dept, string pos)
{
name = n;
idnumber = id;
department = dept;
position = pos;
}
void setName(string n)
{
name = n;
}
void setID(int id)
{
idnumber = id;
}
void setDEPT(string dept)
{
department = dept;
}
void setPOS(string pos)
{
position = pos;
}
string getName() const
{
return name;
}
int getID() const
{
return idnumber;
}
string getDEPT() const
{
return department;
}
string getPOS() const
{
return position;
}
};
#endif
Main.Cpp
#include "EmployeeClass.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
const int NUM_OBJECTS = 3;
Employee employee[NUM_OBJECTS] = {
Employee("Susan Meyers", 47899, "Accounting", "Vice President"),
Employee("Mark Jones", 39119, "IT", "Programmer"),
Employee("Roy Rogers", 81774, "Manufacturing", "Engineer")
};
for (int i = 0; i < NUM_OBJECTS; i++)
{
cout << employee[i].getName() << endl;
cout << employee[i].getID() << endl;
cout << employee[i].getDEPT() << endl;
cout << employee[i].getPOS() << endl;
}
cin.ignore();
cin.get();
return 0;
}
|