#include #include #include #include #include "Employee.h" #include "SalaryEmployee.h" #include "WageEmployee.h" #include "simpleMenu.h" const int SIZE = 3; //call the toString void printEmployees( Employee * p[], int size) { for ( int i=0; i < size; ++i ) std::cout << p[i]->toString() << std::endl; } //sorts by name void sortEmployees( Employee * p[], int size) { // Sort the array of pointers to Employee objects std::sort(p, p + size, [](Employee* a, Employee* b) { // Compare the names of the employees return strcmp(a->getName(), b->getName()) < 0; }); } //sorts by name void sortEmployeesByPay( Employee * p[], int size) { std::sort(p, p + size, [](Employee* a, Employee* b) { return a->computePay() < b->computePay(); }); } // read from the user void deleteEmployees( Employee* p[], int size) { std::vector menuItems; for (int i = 0; i < size; ++i) { menuItems.emplace_back(p[i]->getName()); } int selection = simpleMenu(menuItems, "Select an employee to eliminate."); delete[] p[selection]; } bool isValid(std::string name, std::string salaryInput, std::string wageInput) { bool isValid = false; if ((std::atof(salaryInput.c_str()) > 0.0) && name.length() > 0 && std::atof(wageInput.c_str()) > 0.0) { isValid = true; } if (!isValid) { printf("Invalid input! Please try again!\n"); } return isValid; } void readEmployees( Employee* p[], int size) { std::vector menuOptions = {"Wage Employee", "Salary Employee"}; std::string name, salaryInput, wageInput, bonusInput; double salary, wage, bonus; for (int i = 0; i < size; ++i) { int employeeType = simpleMenu(menuOptions, "What type of employee will this be?"); switch (employeeType) { case 0: { do { printf("Enter a name for Employee %i of %i:", (i + 1), size); std::getline(std::cin, name); printf("Enter salary for %s: ", name.c_str()); std::getline(std::cin, salaryInput); printf("Enter wage for %s: ", name.c_str()); std::getline(std::cin, wageInput); } while (!isValid(name, salaryInput, wageInput)); salary = std::atof(salaryInput.c_str()); wage = std::atof(wageInput.c_str()); char *empName = strdup(name.c_str()); p[i] = new WageEmployee(empName, wage, salary); free(empName); break; } case 1: { do { printf("Enter a name for Employee %i of %i:", (i + 1), size); std::getline(std::cin, name); printf("Enter salary for %s: ", name.c_str()); std::getline(std::cin, salaryInput); printf("Enter bonus for %s: ", name.c_str()); std::getline(std::cin, bonusInput); } while (!isValid(name, salaryInput, bonusInput)); salary = std::atof(salaryInput.c_str()); bonus = std::atof(wageInput.c_str()); char *empName = strdup(name.c_str()); p[i] = new SalaryEmployee(empName, salary, bonus); free(empName); break; } } } } // What is even the purpose for these methods... void poly1( Employee * p ) { std::cout << p->computePay() << std::endl; std::cout << p->weeklyPay() << std::endl; } void poly2( Employee &e ) { std::cout << e.computePay() << std::endl; std::cout <