Thanks for the response.
If I remove the user prompts from the set-functions, I can get both of the objects to display correctly... but ONLY if I initialize the three attributes of each object. While this is good because it helped me understand what was going on with the object, the constructor and the attributes, I would still like to be able to prompt the user for the first name, last name and salary of each object (employee).
I can do it structurally inside of main, but main starts to grow in size. For instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void main()
{
string firstName;
string lastName;
int salary = 0;
//Prompt user to input the three variable values
cout << "Employee001 first name: " << endl;
getline (cin, firstName);
cout << "Employee001 last name: " << endl;
getline (cin, lastName);
cout << "Employee001 annual salary: " << endl;
cin >> salary;
//Create the first object and pass these values to the constructor
Employee employeeOne(firstName, lastName, salary);
}
|
While this will work, I must create those user prompt lines (8 - 13) for each employee so that the values can be passed to the constructor with the creation of a new object. Main will start to get huge.
My goal is: When I create a new object, there are existing functions or code that will execute (regardless of object) that will prompt the user to input the first name, last name and salary so that when I want to display that information... it's a simple call to that object's attribute get member function.
Should I create three more member functions whose goal is to prompt the user for first name, last name and salary?
Then call these functions (returning the value) from the set function? Or would this be bad practice?