In this lab, you complete a C++ program with the provided data files. The program calculates the amount of tax withheld from an employee’s weekly salary, the tax deduction to which the employee is entitled for each dependent, and the employee’s take- home pay. The program output includes state tax withheld, federal tax withheld, dependent tax deductions, salary, and take-home pay.

Instructions

Ensure the source code file named Payroll.cpp is open in the code editor.

Variables have been declared and initialized for you as needed, and the input and output statements have been written. Read the code carefully before you proceed to the next step.

Write the C++ code needed to perform the following:

Calculate state withholding tax (stateTax) at 6.5 percent
Calculate federal withholding tax (federalTax) at 28.0 percent.
Calculate dependent deductions (dependentDeduction) at 2.5 percent of the employee’s salary for each dependent.
Calculate total withholding (totalWithholding) as stateTax+ federalTax + dependentDeduction.
Calculate take-home pay (takeHomePay) as salary - totalWithholding.
Compile and execute your program by clicking the Run button. You should get the following output:
State Tax: $81.25
Federal Tax: $350
Dependents: $62.5
Salary: $1250
Take-Home Pay: $756.25
This is the code

/ This program calculates an employee's take home pay.
#include
using namespace std;
int main()
{
double salary = 1250.00;
double stateTax;
double federalTax;
double numDependents = 2;
double dependentDeduction;
double totalWithholding;
double takeHomePay;

// Calculate state tax here

cout << "State Tax: $" << stateTax << endl;
// Calculate federal tax here

cout << "Federal Tax: $" << federalTax << endl;
// Calculate dependent deduction here

cout << "Dependents: $" << dependentDeduction << endl;
// Calculate total withholding here

// Calculate take-home pay here

cout << "Salary: $" << salary << endl;

Respuesta :

Answer:

Following are the code to this question:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

const double STATE_TAX=6.5, FEDERAL_TAX=28.0, DEPENDENTS_DEDUCTION=2.5; //defining const variables and assign value

double salary = 1250.00, numDependents = 2; //defining double variable and assign value

double stateTax, federalTax, dependentDeduction, totalWithholding, takeHomePay; //defining double variables

stateTax=salary*(STATE_TAX/100); //Calculate stateTax using formula

federalTax=salary*(FEDERAL_TAX/100);  //Calculate federalTax using formula

dependentDeduction=salary*(DEPENDENTS_DEDUCTION/100)*numDependents; // Calculate dependentDeduction using formula

totalWithholding=stateTax+federalTax+dependentDeduction; //Calculate totalWithholding using formula

takeHomePay=salary-totalWithholding; //Calculate takeHomePay using formula

cout << "State Tax: $" << stateTax << endl; //print stateTax value

cout << "Federal Tax: $" << federalTax << endl; //print federalTax value

cout << "Dependents: $" << dependentDeduction << endl; // print Dependents value

cout << "Salary: $" << salary << endl; //print salary value

cout<<"Take-Home Pay: $"<<takeHomePay<<endl; // Calculate takeHomePay value

return 0;

}

Output:

Please find the attachment.

Explanation:

In the given C++ language program code, inside the main method three double const variable "STATE_TAX, FEDERAL_TAX, and DEPENDENTS_DEDUCTION" is declared, that assign a value, that is "6.5, 28.0, and 2.5", and other double variables that are "salary, numDependents, stateTax, federalTax, dependentDeduction, totalWithholding, takeHomePay", in which salary and numDependents variable assign a value, that is "1250.00, and 2".

  • In the next line, other variable is used, that uses defines the formula according to there values, and calculates and stores its value.
  • In the last step, the print method is used, which prints its calculated value with the message.
Ver imagen codiepienagoya