Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Page of 4 ZOOM+ NOTE: You don\'t have to include a header and comments in your p

ID: 3912890 • Letter: P

Question

Page of 4 ZOOM+ NOTE: You don't have to include a header and comments in your program. NOTE: Have all your code in a single file. Structure of your code should be as follows 1. Class Employee Interface 2. Class Employee Implementation (even though they will be in the same file, you will still need to include class scope resolution for functions) 3. Class EmployeeList Interface 4. Class Employee List Implementation (even though they will be in the same file, you will still need to include class scope resolution for functions) 5. Main function. Write a payroll program that would allow user to compute the gross pay salary of hourly based employee, average salary in the company, and find employees with highest and lowest salaries. Employee salaries should be computed using hourly rate with consideration of number of hours worked per week. Regular time: 40 hours or less per week, pay rate hourly pay. Overtime: more than 40 hours per week, pay rte # 1.5 of hourly pay. INPUT: Your program should read employee information from a text file provided on Midterm Lab Exam assignment page. PROCESS: For each line in the file, your program should . calculate employee salary . create an instance of the Employee class with employee name and salary add that Employee to the EmployeeList After input file is processed your program should · find employee with highest salary . find employee with lowest salary compute average salary for the company. OUTPUT: List of employees: name and salary (formatted) .

Explanation / Answer

ScreenShot

---------------------------------------------------------------

Program

//Header files
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<stdlib.h>
#include<sstream>
using namespace std;
//Class employee(.h file)
class Employee {
   //Member variables
private:
   string name;
   double salary;
//Member function
public:
   Employee(string name, double salary);
   void printEmployee();
   friend class EmployeeList;
   };
//Class Employee meber functions implementation(.cpp file)
//Constructor definition
Employee::Employee(string name, double salary) {
   name = name;
   salary = salary;
}
//Print employee details
void Employee::printEmployee() {
   cout << name << " " << salary << endl;
}
//Class employee list(.h file)
class EmployeeList {
   //Member variable
private:
   vector<Employee>employeeList;
   //Member functions
public:
   void addEmployee(Employee employee);
   void printList();
   Employee highestSalary();
   Employee lowestSalary();
   double averageSalary();
};
//Class employee list implementation(.cpp file)
//Add employee details from file to vector and calculate salary
void EmployeeList :: addEmployee(Employee employee) {
   ifstream in;
   string line = "",namefirst="",nameLast="";
   int hours=0;
   double payment = 0;
   //open file
   in.open("C:/Users/deept/Desktop/employees.txt");
   //Check open and then read and create vector
   if (!in) {
       cout << "File not found" << endl;
       exit(0);
   }
   else {
       while (!in.eof()) {
           getline(in, line, ' ');
           istringstream line_stream(line);
           line_stream >>namefirst>>nameLast>>hours>>payment;
           employee.name =namefirst+" "+nameLast;
           if (hours <= 40) {
               employee.salary = hours * payment;
           }
           else {
               employee.salary = hours * (1.5*payment);
           }
           employeeList.push_back(employee);
       }
   }
}
//Print employee list
void EmployeeList::printList() {
   cout << "List of employees in the company" << endl;
   cout << "       NAME SALARY" << endl;
   for (unsigned int i = 0; i < employeeList.size(); i++) {
       cout << employeeList[i].name<<" "<<employeeList[i].salary << endl;
   }
}
//Find highest salaried persion
Employee EmployeeList::highestSalary() {
   double sal = employeeList[0].salary;
   for (unsigned int i = 0; i < employeeList.size(); i++)
       if (employeeList[i].salary > sal)
           sal = employeeList[i].salary;
   for (unsigned int i = 0; i < employeeList.size(); i++)
       if (employeeList[i].salary == sal)
           return employeeList[i];
}
//Find lowest salaried persion
Employee EmployeeList::lowestSalary() {
   double sal = employeeList[0].salary;
   for (unsigned int i = 0; i < employeeList.size(); i++)
       if (employeeList[i].salary < sal)
           sal = employeeList[i].salary;
   for (unsigned int i = 0; i < employeeList.size(); i++)
       if(employeeList[i].salary==sal)
           return employeeList[i];
}
//Find average salary of employees
double EmployeeList::averageSalary() {
   int count = employeeList.size();
   double total = 0;;
   for (int i = 0; i < count; i++) {
       total += employeeList[i].salary;
   }
   return total/count;
}
//main method
int main()
{
   //Object creation
   EmployeeList el;
   Employee e("",0);
   //Call employee list add function
   el.addEmployee(e);
   //Print vector values
   el.printList();
   ////Print highest value holder
   cout << "Highest Salary=";
   el.highestSalary().printEmployee();
   //Print lowest value holder
   cout << "Lowest Salary=";
   el.lowestSalary().printEmployee();
   //Print average
   cout << "Average salary=" << el.averageSalary() << endl;;
   return 0;
}

----------------------------------------------------

Output

List of employees in the company
       NAME SALARY
Dario Waters 330
Jerry Hebert 798.6
Trevor Hill 33.75
Tessa Berger 484
Miles Oneal 295
Mariah Garner 792
Byron Lopez 435.6
Nathaly Boone 330
Helena Hughes 590
Trevom Davenport 17.5
Aiyana Gill 254.1
Chain Gallagher 330
Paris Cabrera 715
Melany Craig 590
Alexandra Berry 590
Hallie Elyse 484
Randy Forster 792
Lawson Snow 590
Alyson Hawkins 577.5
Elyse Smith 590
Highest Salary=Jerry Hebert 798.6
Lowest Salary=Trevom Davenport 17.5
Average salary=480.952
Press any key to continue . . .