/* employee2.cpp
Use a struct to store employee info. into an array of instances.
Show how an instance can be declared along with the struct declaration, 
and assignment can be done between structs.
Additionally use a struct pointer to retrieve the information.

Additionally, array instance declared with the struct declaration.
Output uses a pointer, with one example of the "long" way, and an
example using ->.

Output is:

Please enter name, wage for employee 0: Dale 3
Please enter name, wage for employee 1: Muhammad 6
Please enter name, wage for employee 2: Fernando 4
Employee information is:
Dale 3
Muhammad 6
Fernando 4
*/

#include <iostream>
using namespace std;

// global constants
const int ArraySize = 3;
const int NameSize = 15;

// global structs
struct Employee{
    char name[ NameSize];
    int wage;
} sampleEmployee;     // declare an instance using the struct, just to show we can do it

int main()
{
    int i;		                        // Loop counter 
    Employee people[ ArraySize]; // array of employees
    Employee *pEmployee;	      // pointer to a struct 

    // enter information into array of structs
    for (i=0; i< ArraySize; i++)  {
        cout << "Please enter name, wage for employee " << i << ": ";
        cin >> sampleEmployee.name >> sampleEmployee.wage;
        people[i] = sampleEmployee;   // assign all fields at once
    }

    // echo information from array of structs
    cout << "Employee information is: \n";
    for (i=0; i< ArraySize; i++)  {
        pEmployee = &people[ i];
        // In next line note that arrow is shortcut for * and .
        cout << (*pEmployee).name << " " << pEmployee->wage << "\n";   
    }
    cout << "\n";

    return 0;
}
