I'm trying to write a program. This program is two files. One is a class with constructors. The other file creates three objects to hold employee data. Here is my code so far.
When I run the program, it runs without errors, but it only displays three 0's. I'm guessing the program is reading the "0" for the idNumber three times and printing it, but it doesn't read the info I'm trying to pass into it.
Could anyone point me in the direction to get this program to run correctly? Thanks!
#ifndef EmployeeClass
#define EmployeeClass
#include <string>
using namespace std;
class Employee{
private:
string empName, department, position;
int idNumber;
public:
void setName(string name){ empName = name; }
void setIdNumber(int id) { idNumber = id; }
void setDepartment(string dept) { department = dept; }
void setPosition(string pos) { position = pos; }
Employee(string name, int id, string dept, string pos)
{
empName = "";
idNumber = 0;
department = "";
position = "";
}
string Employee::getName()
{return empName;}
int Employee::getId()
{return idNumber;}
string Employee::getDept()
{return department;}
string Employee::getPos()
{return position;}
};
#endif
#include "EmployeeClass"
#include <iostream>
#include <string>
using namespace std;
const int NUM_WORKERS = 3;
int main()
{
Employee emp[NUM_WORKERS] = {
Employee("Susan Meyers", 47899, "Accounting", "Vice President"),
Employee("Mark Jones", 39119, "IT", "Programmer"),
Employee("Joy Rogers", 81774, "Manufacturing", "Engineer")
};
for(int i = 0; i < NUM_WORKERS; i++)
{
cout << emp[i].getName() << " ";
cout << emp[i].getId() << " ";
cout << emp[i].getDept() << " ";
cout << emp[i].getPos() << endl;
}
cout << endl;
system("pause");
return 0;
}
When I run the program, it runs without errors, but it only displays three 0's. I'm guessing the program is reading the "0" for the idNumber three times and printing it, but it doesn't read the info I'm trying to pass into it.
Could anyone point me in the direction to get this program to run correctly? Thanks!