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

Create a Biweekly Payroll Program in C++ using an If-Then-Else structure that wi

ID: 3710979 • Letter: C

Question

Create a Biweekly Payroll Program in C++ using an If-Then-Else structure that will test if any overtime were earned (hours earned > 80). Any hours earned greater than 80 will be calculated at time and half the rate.

Calculate gross income, taxes (deductions), and the net pay.

The enduser will be prompted to input: - Employee number, first name, last name

                                                        - Hours earned and rate per hour

Set up an if-then-else structure to calculate overtime and regular pay.

Use the following rates for deduction- initialize them as constants:

     - Federal Tax = 3.2%

     - State Tax = 2.5%

     - Medical = 2%

The program will output the following to a file:

   Employee number, Total hours, Rate per hour, Gross pay, Deductions (federal tax, state tax, medical tax), and Net Pay.

Set variable data types and name them accordingly.

Use indentation, comments, and spacing where they apply. Set decimal places to two with trailing zeros.

Show the use of setw, newline operator, lines, and justification in your output.

Explanation / Answer

#include <iostream>

#include<iomanip>


#include<fstream>
using namespace std;


const float fedtax=3.2;
    //constant declarations
const float statetax=2.5;

const float medtax=2;


int main()

{


int emp_no;

char fname[20],
lname[20];

float hours, rate;

float gross, deduct,netpay;

float extra;

//Input Employee details
cout<<" Enter Employee Number";

cin>>emp_no;

cout<<" Enter First Name";

cin>>fname;

cout<<" Enter Last Name";

cin>>lname;

cout<<" Enter Hours earned";

cin>>hours;

cout<<" Enter rate per hour";

cin>>rate;

// caclulate over rate if it is there
if(hours>80)

{
extra =hours-80;

gross = 80*rate+(extra*rate/2);


}


else


{

gross=hours*rate;

}
// calculte deductions and net pay

deduct=(gross*fedtax/100)+(gross*medtax/100)+(gross*statetax/100);


netpay=gross-deduct;


// writing to file and ouput on screen
ofstream myfile ("emp.txt");
if (myfile.is_open())
{
myfile<<emp_no<<setw(10)<<fname<<" "<<lname<<setw(10)<<hours<<setw(10)<<std::setprecision(2)<<rate<<setw(10)<<std::setprecision(2)<<gross<<setw(10)<<std::setprecision(2)<<deduct<<setw(10)<<std::setprecision(2)<<netpay;

    myfile.close();
cout<<" "<<"Employee Number"<<setw(10)<<"Employee Name "<<setw(10)<<"Total Hours "<<setw(10)<<"Rate per Hour"<<setw(10)<<"Gross Pay "<<setw(10)<<"Deductions "<<setw(10)<<"Net Pay";

cout<<emp_no<<setw(10)<<fname<<" "<<lname<<setw(10)<<hours<<setw(10)<<std::setprecision(2)<<rate<<setw(10)<<std::setprecision(2)<<gross<<setw(10)<<std::setprecision(2)<<deduct<<setw(10)<<std::setprecision(2)<<netpay;

}
else
cout << "Unable to open file";
}