/* Filename: employee.cpp Author: Br. David Carlson Date: January 24, 1998 Last Modified: November 21, 2001 This file implements the functions ReadEmployee, PrintEmployee, and EmpCompare that are prototyped in employee.h. */ #include #include #include "employee.h" /* Given: Nothing. Task: To read from the keyboard data for one employee. Return: Employee A structure containing the data just read. In the function name return FailFlag or OKFlag to indicate how input behaved. */ int ReadEmployee(EmployeeType & Employee) { cout << "Enter employee's last name (no spaces allowed): "; cin >> Employee.LastName; if (cin.fail()) return FailFlag; cout << "Enter employee's first name (no spaces allowed): "; cin >> Employee.FirstName; if (cin.fail()) return FailFlag; cout << "Enter employee's ID number: "; cin >> Employee.ID; if (cin.fail()) return FailFlag; cout << "Enter employee's wage rate: "; cin >> Employee.WageRate; if (cin.fail()) return FailFlag; return OKFlag; } /* Given: Employee A structure containing info on one employee. Task: To print the data from Employee on the screen. Return: Nothing. */ void PrintEmployee(const EmployeeType & 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 EmployeeType & First, const EmployeeType & 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; }