I am trying to pass 4 different values to each element of my fixed array. However, when I try to output the console outputs memory locations rather than the values I want to see. The aim of the program is to use an array to store Employee data and using a for loop cycle through the data and print it to the console. What must I add in order to convert the array's output from memory location to the desired values?
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
class Employee
{
int empNumber;
string name;
double hours, payRate;
public:
Employee()
{
int empNumber = 0;
double hours=0, payRate = 0;
string name = "Name";
}
Employee(int empNmb, double hrs, double payRT, string nm)
{
empNumber = empNmb;
hours = hrs;
payRate = payRT;
name = nm;
}
void getEmployeeData()
{
for (int i = 0; i < 4; i++)
{
cout << empNumber;
cout << hours;
cout << payRate;
cout << name;
}
}
};
int main()
{
Employee e;
Employee list[4];
list[0] = Employee(9991, 25, 15, "Jeff");
list[1] = Employee(8791, 21, 15, "Mohamed");
list[2] = Employee(9211, 15, 35, "Mary");
list[3] = Employee(5271, 35, 15, "Bob");
e.getEmployeeData();
system("Pause");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire