Assuming that you have a file comprising records (lines) for more than 100 emplo
ID: 3821478 • Letter: A
Question
Assuming that you have a file comprising records (lines) for more than 100 employees. Each record includes: (1) employee first name, (2) employee last name, (3) employee hourly wages, and (4) number of hours that employee worked a current week. Write an awk program that: Outputs the header information stating "The list of employees working 40 or more hours." Assigns ORS (Output Record Separator) to be a dash (i.e. "-"). Outputs last names and hours of all employees that worked 40 or more hours (note, print only the last names and number of hours worked). Outputs the number of employees that worked more than 40 hours (e.g., The total number of employees that worked 40 or more hours is ..."Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
//Read data from file and returns number of records
int readFile(string firstName[], string lastName[], float hourlyWage[], int workHour[])
{
//Creates an object of ifstream
ifstream readf;
//Opens the file for reading
readf.open ("EmployeeData.txt");
int c = 0;
//Loops till end of file
while(!readf.eof())
{
//Reads data and stores in respective array
readf>>firstName[c];
readf>>lastName[c];
readf>>hourlyWage[c];
readf>>workHour[c];
//Increase the record counter
c++;
}//End of while
//Close file
readf.close();
//Returns record counter
return c;
}//End of function
//To display employee information worked more than 40 hours
void Display(string lastName[], int workHour[], int len)
{
int counter = 0;
//Displays the file contents
cout<<" The list of employees working 40 or more hours ";
cout<<("____________________________________________________");
cout<<" Last Name Worked Hour ";
//Loops till end of employee records
for(int x = 0; x < len; x++)
{
//Checks whether worked hour is greater than or equal to 40 or not
if(workHour[x] >= 40)
{
//Displays employee name and hour worked
cout<<endl<<lastName[x]<<" "<<workHour[x];
//Increase the counter by one
counter++;
}//End of if
}//End of for loop
//Displays total employees worked more than 40 hours
cout<<" The total number of employees that worked 40 or more hours is: "<<counter;
}//End of function
//Main function
int main()
{
//Creates arrays to store data from file
string firstName[100], lastName[100];
float hourlyWage[100];
int workHour[100];
//To store number of employee records
int len;
//Call function to read file
len = readFile(firstName, lastName, hourlyWage, workHour);
//calls function to display
Display(lastName, workHour, len);
return 0;
}//End of main
Employee.txt file contents
Pyari Mohan 40 55
Suresh Sahu 30 60
Ram Padhy 30 20
Rakesh Sharma 20 25
Sinu Panda 60 70
Output:
The list of employees working 40 or more hours
____________________________________________________
Last Name Worked Hour
Mohan 55
Sahu 60
Panda 70
The total number of employees that worked 40 or more hours is: 3