/* employee3.cpp
   	use a struct to store employee info. into an array of instances.

	Pass structure elements to functions, showing both pass by reference
	and pass by value.  

	Output is:
      Please enter name, wage for employee 0:Sunil 3
      Please enter name, wage for employee 1:Nipa 6
      Please enter name, wage for employee 2:George 4
      Employee information is:
      Sunil 3
      Nipa 6
      George 4
 */

#include <iostream>
using namespace std;

// global constants
const int ArraySize = 3;
const int NameSize = 15;

struct Employee{
   char name[ NameSize];
   int wage;
};


// Read in employee information for a particular employee.
void readIn( int i, Employee *theEmployee)
{
   cout << "Please enter name, wage for employee " << i << ":";
   // theEmployee already is a pointer, and -> implements the * for us
   cin >> theEmployee->name >> (*theEmployee).wage;
}


// Function to display information for an employee
void display( Employee theEmployee)
{
   cout << theEmployee.name << " " << theEmployee.wage << "\n";   
}


main()
{
   int i;		                   // Loop counter 
   Employee people[ ArraySize];   // array of employees, declared using the typedef

   for (i=0; i< ArraySize; i++)  {
      readIn( i, &people[ i]);	 // pass address of Employee
   }

   cout << "Employee information is: \n";
   for (i=0; i< ArraySize; i++)  {
      display( people[ i]);	
   }
   cout << "\n";

   return 0;
}

