#include #include #include #include #define MAXEMPLOYEES 130 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); int readEmployeeFile(employee personnel[]); void displayEmployeeByElement(employee personnel[], int element); void searchEmployeeByID(employee personnel[], int numEmployees); void searchEmployeeBySalary(employee personnel[], int numEmployees); void groupEmployeesByDepartment(employee personnel[], int numEmployees); void sortEmployeesByIDandDisplay(employee personnel[], int numEmployees); void sortEmployeesByIDandDisplayByGroup(employee personnel[], int numEmployees); void printOut(employee personnel[]); /* *Function Prototypes for bubblesort and sort functions go here */ /* * Main function */ int main() { menuStart(); } /* * Function to start the menu */ void menuStart(void) { int choice, numEmployees; struct employee personnel[MAXEMPLOYEES]; numEmployees = readEmployeeFile(personnel); while(choice != 7) { choice = menuChoice(); // switch statement for menu items switch(choice) { case 1: searchEmployeeByID(personnel, numEmployees); break; case 2: searchEmployeeBySalary(personnel, numEmployees); break; case 3: groupEmployeesByDepartment(personnel, numEmployees); break; case 4: sortEmployeesByIDandDisplay(personnel, numEmployees); break; case 5: sortEmployeesByIDandDisplayByGroup(personnel, numEmployees); break; case 6: break; case 7: break; default: cout << "PLEASE CHOOSE FROM OPTIONS 1-7." << endl << endl; break; } } system("pause"); exit(0); } /* * Reads data from "empdata.txt" into an array */ int readEmployeeFile(employee personnel[]) { ifstream inFile; inFile.open("empdata.txt"); if (!inFile) { cout << "Error: Cannot open \"empdata.txt\" for input." << endl; return -1; } int i = 0; while(inFile.good()) { getline(inFile, personnel[i].Name); inFile >> personnel[i].ID; inFile >> personnel[i].Salaried; inFile >> personnel[i].PayRate; inFile.ignore(); getline(inFile, personnel[i].Department); getline(inFile, personnel[i].Title); i++; } return i; } /* * 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 employee ID numbers, display names and IDs." << 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; } /* * Displays a particular employee by using their position in the array. */ 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; } /* * Loops through the struct to find an employee matching a certain ID number */ void searchEmployeeByID(employee personnel[], int numEmployees) { cout << "Enter the ID of the employee you wish to view: "; int requestedID; cin >> requestedID; for (int i = 0; i < numEmployees; i++) { if (personnel[i].ID == requestedID) { cout << personnel[i].Name << ", " << personnel[i].Department << ", " << personnel[i].Title << "\n\n"; return; } } return; } /* * Loops throught he struct to find employees matching certain salary levels. */ void searchEmployeeBySalary(employee personnel[], int numEmployees) { // ******* NEED TO SORT THE ARRAY HERE ****** // If pers[x].PayRate > pers[x + 1].PayRate // - swap the two elements cout << "Enter the lowest salary you wish to view: "; int lowestSalary; cin >> lowestSalary; for (int i = 0; i < numEmployees; i++) { if (personnel[i].PayRate >= lowestSalary) { displayEmployeeByElement(personnel, i); } } return; } void groupEmployeesByDepartment(employee personnel[], int numEmployees) { } /* * Sorts employees in Ascending order and displays each employee's name and ID number */ void sortEmployeesByIDandDisplay(employee personnel[], int numEmployees) { ; } /* * Sorts employees in ascending order by ID number and displays names, * ID numbers, and bi-weekly pay... all grouped by department */ void sortEmployeesByIDandDisplayByGroup(employee personnel[], int numEmployees) { ; } /* * Prints to output file "empoutput.txt" */ void printOut(employee personnel[]) { ; } /* Needs to be put in the correct space, just putting here for the time being */ /* *Prototypes for bubble sort and sorting functions, both are needed for bubble sorting */ int switchum (ID&, ID&); int bubblesort (int, ID []); int bubblesort (int number, ID structarray []) { int outer, inner; for (outer = 0; outer < number - 1; outer++) for (inner = 0; inner < number - 1; inner++) if (structarray [inner] . ID > structarray [inner + 1] . ID) switchum (structarray [inner], structarray [inner + 1]); int switchum (ID& first, ID& second) { date temp; temp = first; first = second; second = temp; return 0; }