Project Description Write a C++ program that processes a payroll. Your program w
ID: 3835647 • Letter: P
Question
Project Description
Write a C++ program that processes a payroll. Your program will calculate the wages for each employee, given the number of hours worked and the payrate per hour. It will search for two employees by number, one with a binary search (see page 462) and one with a linear search (see page 459). A selection sort (see page 476) will sort the arrays so that the employee numbers are in ascending order.
Project Specifications
Input for this project has two sources. The user must enter the names of the input and output files from the keyboard. The user will enter two employee numbers from the keyboard in response to prompts. The input file should have one line for each employee with the 3 required items: employeeID, hoursWorked, and payRate (separated by whitespace on the file) The last line of the file must always have only -1.
Output also has two sources. The program title and the programmer name should appear on both the console and the file. If the input file does not open, an error message should appear on the console and no attempt should be made to open the output file for any output or processing. The message "Processing complete" should appear on the console after the programmer name and just before the main program ends (make it the last statement before "return;"). The console output will show the prompts with the search numbers. The file output should show the unsorted table of the input items with the wages, followed by the sorted table with the same 4 columns. The column numbers with decimal amounts should line up on the decimal point under the column headings.
Processing Requirements
Your program should use the following one-dimensional arrays:
empId: an array of long integers to hold employee identification numbers. Assume there will be no more than 20 identification numbers, but your code should check that the file doesn't attempt to enter more. If an attempt is made to enter 21, process only the first 20.
hours: an array of doubles to hold the number of hours worked by each employee. Fractional hours are possible.
payRate: an array of doubles to hold each employee's hourly pay rate.
wages: an array to hold each employee's gross wages.
The program should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the empId array. That same employee's pay rate should be stored in element 0 of the payRate array.
1) Calculate the wages for each employee and place into an array with the related subscript.
2) Write the unsorted arrays on the output file.
3) Prompt for and input from the keyboard an empID to use for the linear search.
4) Next sort the empID long integers using the selection sort algorithm. If an exchange is made for empID, be sure to make the corresponding exchanges in the three associated items.
5) Write the sorted arrays on the output file.
6) Prompt for and input from the keyboard an empID to use for the binary search.
The Selection sort algorithm, Binary Search and Linear Search algorithms should be three separate functions that will be called from the function main(). Modify the code in your text for this project. Do NOT use any output statements in these functions. You may use more functions in your design.
You may assume that the input file is constructed correctly, and will always contain -1 at the end. Be sure to test for an empty file (one that contains ONLY -1) and a file with more than 20 employees. Print an error message to the screen if there are no employees, and do NOT attempt to open the output file. If your file has more than 20 employees, just
process the first 20 (without an error message.)
To input the file items without reading past the end of the file (-1 is the sentinel), use a while loop with two conditions: the empID in a temporary variable that is not negative and the number of employees less than 20. Inside your loop body: Store the "good" employee number, input the number of hours and the payRate in the arrays. The last item in your loop should be the next employee number from the file.
Explanation / Answer
I have developed the C++ program for processing of a payroll. The program will calculate the wages for each employee, and it provides the number of hours they have worked and finally the payrate per hour. I have included the comments for each part of the code for a better understanding.
Program:-
// This is the header files which are used to assign properties and methods to each respective classes
#include<iostream>
#include<string>
using namespace std;
// The main method is the starting point of the program
int main()
{
// The All variables are declared over here.
int emp_list_count, check_another_emp;
double empHoursWorked, empPayScaleRate, empNormalPayScaleRate, empOTPayScaleRate, empGrossPayScale, empNetPayScale, empTotalGrossPayScale, empTotalNetPayScale, empAvgGrossPayScale,
empAvgNetPayScale;
const double empNormalWorkingHours=55;
string emp_Name;
emp_list_count=0;
// using do statements to check all the conditions which satisfies the requirement
do
{
cout <<"We are heartly welcome to the Employee payroll site :" << endl;
cout <<"Kindly enter the employee name which you want to access the payroll:"<<endl;
cin >> emp_Name;
cout <<"How many hours you have worked over this complete week.? :";
cin>> empHoursWorked;
cout<<endl;
cout<<"You're overall complete payslip is:";
cin>>empPayScaleRate;
// Here, The if-else statement is calculating the employee Gross and Net pay scale based on the employee hours worked.
if (empHoursWorked>empNormalWorkingHours)
{
empOTPayScaleRate=empHoursWorked*1.5*empPayScaleRate;
empGrossPayScale=empOTPayScaleRate-(empHoursWorked*empPayScaleRate);
empNetPayScale=empGrossPayScale-(empGrossPayScale*.03625);
}
else
{
empGrossPayScale=empHoursWorked*empPayScaleRate;
empNetPayScale=empGrossPayScale-(empGrossPayScale*.03265);
}
empTotalGrossPayScale += empGrossPayScale;
++emp_list_count;
empTotalNetPayScale += empNetPayScale;
++emp_list_count;
empAvgGrossPayScale += empTotalGrossPayScale/++emp_list_count;
empAvgNetPayScale += empTotalNetPayScale/++emp_list_count;
// The output will display here by the No. of Gross pay and Net pay earned by the employee
cout<< emp_Name <<"You're Complete Gross pay scale is as follows:" << empGrossPayScale <<endl;
cout<< emp_Name <<"You're Complete Net pay scale is as follows:"<< empNetPayScale <<endl;
cout<< endl;
cout<<" Now, You can try looking for another employee from your organization" <<endl;
cout<<" If Yes, then please enter 1 or press 0 for No."<<endl;
cin<< check_another_emp;
}
// This will display the details of the another employee
while(check_another_emp==1)
cout<<" You're Complete Gross pay scale is as follows: " <<empTotalNetPayScale;
cout<<endl;
cout<<"You're Complete Net pay scale is as follows:"<<empTotalGrossPayScale;
cout<<endl;
cout<<"You're Average Gross pay scale is as follows:"<<empAvgGrossPayScale;
cout<<endl;
cout<<"You're Average Net pay scale is as follows:"<<empAvgNetPayScale;
cout<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.