/* Filename: EmployeeSimple.cpp Author: Br. David Carlson Date: January 24, 1998 Last Modified: September 24, 2017 This file implements the functions ReadEmployee, PrintEmployee, and EmpCompare that are prototyped in EmployeeSimple.h. */ #include "EmployeeSimple.h" /* Given: Nothing. Task: To read from the keyboard data for one employee. Return: Employee A structure containing the data just read. */ void ReadEmployee(EmployeeSimpleType & Employee) { cout << "Enter employee's last name: "; cin.getline(Employee.LastName, NameMax); // NameMax is max characters in string plus 1 (for NULL) marking end of string. cout << "Enter employee's first name: "; cin.getline(Employee.FirstName, NameMax); cout << "Enter employee's ID number: "; cin >> Employee.ID; cout << "Enter employee's wage rate: "; cin >> Employee.WageRate; cin.get(); // Since a number was read last, the newline has not been read in. This will read it in. // If we left the newline in the input buffer, if a string is read next, it would get the empty string. } /* Given: Employee A structure containing info on one employee. Task: To print the data from Employee on the screen. Return: Nothing. */ void PrintEmployee(const EmployeeSimpleType & Employee) { cout << "Name:" << setw(17) << Employee.LastName << setw(17) << Employee.FirstName << setw(6) << "ID:" << setw(8) << Employee.ID << setw(13) << "Wage rate:" << setw(10) << Employee.WageRate << endl; } /* Given: First An employee record. Second Another employee record. Task: To decide if, based on last name then first name, First is less than, equal to, or greater than Second. Return: In the function name return: -1 if First < Second 0 if First == Seond 1 if First > Second */ int EmpCompare(const EmployeeSimpleType & First, const EmployeeSimpleType & Second) { int Value; Value = strcmp(First.LastName, Second.LastName); if (Value < 0) return -1; if (Value > 0) return 1; // If reach this line, LastNames are the same. Value = strcmp(First.FirstName, Second.FirstName); if (Value < 0) return -1; if (Value > 0) return 1; // If reach this line, both first and last names are same. return 0; }