#include #include #include #include using namespace std; struct employee { string Name; int ID; char Salaried; float PayRate; string Department; string Title; }; int main(void); void menuStart(void); int menuChoice(void); void readEmployeeFile(employee personnel[]); void sortEmployee(employee personnel[], int); void sortByIdDepart(employee personnel[], int); void searchEmployeeByID(employee personnel[]); void displayEmployeeByElement(employee personnel[], int element); void printOut(employee personnel[]); void test(employee personnel[]); int main() { menuStart(); } void menuStart(void) { int choice; struct employee personnel[65]; readEmployeeFile(personnel); while(choice != 7) { choice = menuChoice(); switch(choice) //switch statement for menu items { case 1: searchEmployeeByID(personnel); break; case 2: test(personnel); break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; default: cout << "PLEASE CHOOSE FROM OPTIONS 1-7." << endl << endl; break; } } system("pause"); exit(0); } /* * Menu */ int menuChoice(void) { int choice; cout << setw(80) << setfill('*') << "" << endl; cout << "1. Search for an employee by their ID number." << endl; cout << "2. Display employees' names according to salary." << endl; cout << "3. Group employees by department." << endl; cout << "4. Sort data by ascending order of employee ID numbers." << endl; cout << "5. List of employees sorted by ID # and department." << endl; cout << "6. Display employees, by name, of a particular title." << endl; cout << "7. Quit and Print." << endl << endl; cout << setw(80) << setfill('*') << "" << endl; cout << "Choose 1-7: "; cin >> choice; cout << endl; return choice; } /* * Reads data from "empdata.txt" into an array of struct */ void readEmployeeFile(employee personnel[]) { string employeeName; int employeeID; char employeeSalaried; float employeePayRate = 0; string employeeDepartment; string employeeTitle; ifstream inFile; inFile.open("empdata.txt"); if (!inFile) { cout << "Error: Cannot open \"empdata.txt\" for input." << endl; return; } int i = 0; while(inFile.good()) { getline(inFile, employeeName); cout << employeeName << endl; personnel[i].Name = employeeName; inFile >> employeeID; cout << employeeID << endl; personnel[i].ID = employeeID; inFile >> employeeSalaried; cout << employeeSalaried << endl; cout << personnel[i].Salaried << endl; employeePayRate = inFile.get(); cout << employeePayRate << endl; personnel[i].PayRate = employeePayRate; getline(inFile, employeeDepartment); cout << employeeDepartment << endl; personnel[i].Department = employeeDepartment; getline(inFile, employeeTitle); cout << employeeTitle << endl; personnel[i].Title = employeeTitle; i++; } cout << "sizeof(personnel) is: " << sizeof(personnel) << endl; return; } void test(employee personnel[]) { displayEmployeeByElement(personnel, 0); displayEmployeeByElement(personnel, 1); displayEmployeeByElement(personnel, 2); // for(int i = 0; i < 65; i++) // { // displayEmployeeByElement(personnel, i); // } } void searchEmployeeByID(employee personnel[]) { cout << "Enter the ID of the employee you wish to view: "; int requestedID; cin >> requestedID; for (int i = 0; i < sizeof(personnel); i++) { if (personnel[i].ID == requestedID) { cout << "Match Found." << endl; displayEmployeeByElement(personnel, requestedID); } else cout << "Match NOT Found." << endl; } return; } /* * Sorts employees in Ascending order */ void sortEmployee(employee personnel[],int) { ; } /* * Sorts employees by ID # and department; */ void sortByIdDepart(employee personnel[],int) { ; } /* * Displays employees by name, of a particular title */ void displayEmployeeByElement(employee personnel[], int element) { cout << personnel[element].Name << endl; cout << personnel[element].ID << endl; cout << personnel[element].Salaried << endl; cout << personnel[element].PayRate << endl; cout << personnel[element].Department << endl; cout << personnel[element].Title << endl; } /* * Prints to output file "empoutput.txt" */ void printOut(employee personnel[]) { ; }