Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Referring to the code bellow bellow, create a class with four private member variables and five member functions; write a program that will read in

Referring to the code bellow bellow, create a class with four private member variables and five member functions; write a program that will read in each record from an input file, calculate the total pay for the thirty (30) employees and storing the data into an array. The data is to then be printed to an output file.

image text in transcribed

Total pay should be calculated by multiplying the hours worked by pay rate plus 10% of total pay for every five (5) hours over forty (40). (i.e. a person working 50 hours with a total pay of $100 would have ((50-40)/5)*(100*.1) added to total pay.

Note: _jd represents the initials of the programmer. Your function names should be named by replacing the initials jd with your first and last initials. Excluding the main function, your program should have five additional functions that will get the hours worked and payrate, calculate the total pay, sort the data and display your output.

image text in transcribed

Data file should be named data2_jd.txt

Code

#include

using namespace std;

struct payroll

{

int emp_id;

double hrsworked;

double pay_rate;

double TotalAmount;

};

payroll admin[10], office[10], field[10];

//function to get number of hours worked

double getHrWorked(int i)

{

double val;

cout

cin >> val;

return val;

}

//function to get pay rate

double getPayRate(int i)

{

double val;

cout

cin >> val;

return val;

}

//function to calculate pay

double calculatePay(int i, double hrs, double rate)

{

double val;

val = hrs*rate;

if (hrs>40)

{

val = val + ((hrs - 40) / 5)*(val*0.1);

}

return val;

}

//function to sort the employees by the id

void sort(struct payroll* temp)

{

struct payroll swap;

for (int i = 0; i

{

for (int j = i + 1; j

{

if (temp[i].emp_id > temp[j].emp_id)

{

swap = temp[i];

temp[i] = temp[j];

temp[j] = swap;

}

}

}

}

//function to display the employee payroll structure

void display(struct payroll* temp)

{

for (int i = 0; i

{

cout

}

cout

}

//main function

int main()

{

//admin details....

for (int i = 0; i

{

cout

cin >> admin[i].emp_id;

admin[i].hrsworked = getHrWorked(i);

admin[i].pay_rate = getPayRate(i);

admin[i].TotalAmount = calculatePay(i, admin[i].hrsworked, admin[i].pay_rate);

}

cout

display(admin);

sort(admin);

cout

display(admin);

//office details

for (int i = 0; i

{

cout

cin >> office[i].emp_id;

office[i].hrsworked = getHrWorked(i);

office[i].pay_rate = getPayRate(i);

office[i].TotalAmount = calculatePay(i, office[i].hrsworked, office[i].pay_rate);

}

cout

display(office);

sort(office);

cout

display(office);

//field details

for (int i = 0; i

{

cout

cin >> field[i].emp_id;

field[i].hrsworked = getHrWorked(i);

field[i].pay_rate = getPayRate(i);

field[i].TotalAmount = calculatePay(i, field[i].hrsworked, field[i].pay_rate);

}

cout

display(field);

sort(field);

cout

display(field);

system("pause");

return 0;

}

Description Employee IDs Hours Worked Pay Rate Total Pay DataType of INT of DOUBLE of DOUBLE of Double Members employees_id hrworked_jd , payratejd total_pay Class name Member Functions calcPay getinfo putinfo results private private private public pass computed Total Pay and store into array get information from datafile. output data to datafile array of thirty (30), used to access private function getinfo and calcPay to retrieve data from input file and calculate Total Pay used to access private function putinfo to write the array of data to an output file results2 public

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago