Write a program that calculates and prints the monthly paycheck for an employee.
ID: 3733023 • Letter: W
Question
Write a program that calculates and prints the monthly paycheck for an employee. The net pay iS calculated after taking the following deductions Federal Income Tax: 15% State Tax: 3.5% Social Security Tax: 5.75% Medicare/Medicaid Tax: 2.75% Pension Plan: 5% Health Insurance: $75.00 Your program should read the input (the gross amount and the employee name) for 5 employers from a file 8111 Robinson June Tausan ema1 Hessian Omar Ahmed Raj Bhatnagar 785.87 6789.89 7864.90 6789.78 The output will be stored in a file. Format your output to have two decimal places. A sample output follows: Emp,Output Natepad Robinson Bi11 575.74 Gross Amount Federal Tax: State Tax: Social Security Tax: Medicare/Medicaid Tax: 98.33 Health Insurance: Net Salary Tausan June 2356.50 Gross Amount: Federal Tax: State Tax: Socfal Security Tax: Medicare/Medicaid Tax: Health Insurance: Net Salary Hessian Jemal 3859.39 6789.89 Gross Amount: Federal Tax: State Tax: Social Security Tax: Medicare/Medi caid Tax:186.72 Pension Plan: Health Insurance: 1018,48 -237.65 390.42 339.4 5.00 4542.13 Net Salary Ahmed Omar Gross Amount: 7864.90Explanation / Answer
---------------------------------------ans.cpp-----------------
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;
//string to integer
int stoi(string s){
float b;
int i=0;
while(i<s.size()){
b= b*10 + (s[i]-'0');
i++;
}
return b;
}
// convert string to float
float stof(string s){
float a=0, b = 0;
int i=0;
while(s[i] != '.'){
b= b*10 + (s[i]-'0');
i++;
}
i++;
// cout<<b<<endl;
int count = 0;
while(i<s.size()){
a = a*10 + (s[i]-'0');
i++;
count++;
}
// cout<<a<<endl;
int k = pow(10,count);
float c = a/k;
float val = b + a/k;
//cout<<val<<endl;
return val;
}
int main()
{
vector <string> words; // Vector to hold our words we read in.
string str; // Temp string to
// cout << "Read from a file!" << std::endl
;
ifstream fin("emp.txt"); // Open input file
ofstream myfile;
while (fin >> str) // Will read up to eof() and stop at every
{ // whitespace it hits. (like spaces!)
words.push_back(str);
}
fin.close(); // closed the input file
myfile.open("Emp_output.txt"); // opening file to add the data
if(myfile.is_open()){
for (int i = 0; i < words.size(); i=i+3){
string name = words[i] + " " + words[i+1];
//name = name + words[i+1];
float val = stof(words[i+2]);
//cout<<name<<" "<<val<<endl;
cout << fixed;
cout << setprecision(2);
float fed_tax = 0.15*val*-1;
float state_tax = 0.035*val*-1;
float secu_tax = 0.0575*val*-1;
float med_tax = 0.0275*val*-1;
float pension = .05*val*-1;
float health = 75.00*-1;
myfile<< name<<endl<<endl;
myfile<<"Gross Amount: "<<val<<" ";
myfile<<"Federal Tax: "<<fed_tax<<" ";
myfile<<"State Tax: "<<state_tax<<" ";
myfile<<"Social Security Tax: "<<secu_tax<<" ";
myfile<<"Medicare/Medicaid Tax: "<<med_tax<<" ";
myfile<<"Pension Plan: "<<pension<<" ";
myfile<<"Health Insurence: "<<health<<" ";
float net = val + fed_tax + state_tax + secu_tax + med_tax + pension + health;
myfile<<"Net Salary: "<<net<<" ";
}
}else{ // if any problem in opening or creating the output file
cout<<"Unable to open file "<<endl;
}
cout<<" Done open Emp_output.txt file ";
myfile.close(); //closed the output file
return 0;
}
------------------------------end-------------------------
------------------emp.txt--------------------------
Bill Robinson 3575.74
June Tausan 5785.87
Jamal Hessian 6789.89
Omar Ahmed 7864.90
Raj Bhatnagar 6789.78
---------------------------------------end----------------------
----------------------------------Emp_output.txt-----------------------------------
Bill Robinson
Gross Amount: 3575.74
Federal Tax: -536.361
State Tax: -125.151
Social Security Tax: -205.605
Medicare/Medicaid Tax: -98.3328
Pension Plan: -178.787
Health Insurence: -75
Net Salary: 2356.5
June Tausan
Gross Amount: 5785.87
Federal Tax: -867.88
State Tax: -202.505
Social Security Tax: -332.688
Medicare/Medicaid Tax: -159.111
Pension Plan: -289.294
Health Insurence: -75
Net Salary: 3859.39
Jamal Hessian
Gross Amount: 6789.89
Federal Tax: -1018.48
State Tax: -237.646
Social Security Tax: -390.419
Medicare/Medicaid Tax: -186.722
Pension Plan: -339.495
Health Insurence: -75
Net Salary: 4542.13
Omar Ahmed
Gross Amount: 7864.9
Federal Tax: -1179.73
State Tax: -275.271
Social Security Tax: -452.232
Medicare/Medicaid Tax: -216.285
Pension Plan: -393.245
Health Insurence: -75
Net Salary: 5273.13
Raj Bhatnagar
Gross Amount: 6789.78
Federal Tax: -1018.47
State Tax: -237.642
Social Security Tax: -390.412
Medicare/Medicaid Tax: -186.719
Pension Plan: -339.489
Health Insurence: -75
Net Salary: 4542.05
-----------------------------end------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.