I am quite new to c++ and have been struggling on a part of an assignment for the last week.
I know it's a simple thing but I can't wrap my head around the right way to go about it.
I need to create four objects for the class (Employee) that I've made and assign them to the array I've made
heres my default constructor:
Employee() // Deafault Constructor
{
empNumber = 00000;
hours, payRate = 0;
name = "Name";
}
And my attempt to create 4 objects with different data saved into the array elements:
int Employees[4];
Employees[0] = Employee(67258, 40, 35, "Craig");
Employees[1] = Employee(25387, 30, 20, "Carol");
Employees[2] = Employee(11945, 38, 30, "Suzie");
Employees[3] = Employee(90832, 28, 40, "Sam");
Like I said, basically brand new and I've been googling up a storm to no avail.
Any help or suggestions or even links are welcome!
Here's my whole code:
class Employee
{
private:
int empNumber;
string name;
double hours, payRate;
public:
Employee() // Deafault Constructor
{
empNumber = 00000;
hours = 0;
payRate = 0;
name = "Name";
}
Employee(int e_empNumber, double e_hours, double e_payRate, string e_name) // Non-Default Constructor
{
empNumber = e_empNumber;
hours = e_hours;
payRate = e_payRate;
name = e_name;
}
void getEmployeeData()
{
cout << "Employee #: " << empNumber << ' ';
cout << "Name: " << name << ' ';
cout << "Hours worked: " << hours << ' ';
cout << "Pay Rate: " << payRate << endl;
}
};
int main()
{
int Employees[4];
Employees[0] = Employee(67258, 40, 35, "Craig");
Employees[1] = Employee(25387, 30, 20, "Carol");
Employees[2] = Employee(11945, 38, 30, "Suzie");
Employees[3] = Employee(90832, 28, 40, "Sam");
system("pause");
return 0;
}
hours, payRate = 0;only assigns0to the second variable,hoursremains uninitialized.