Write a program that can be used to calculate the federal tax. You are provided
ID: 3645906 • Letter: W
Question
Write a program that can be used to calculate the federal tax. You are provided an input file from which data should be read and processed into an output file. Output file should be labeled as Project4.out.1. The tax is calculated as follows:
1.1. For single people, the standard exemption is $4000
1.2. For married people, the standard exemption is $7000.
2. A person is allowed to contribute 0-6% of his or her gross income in a pension plan.
3. The tax rates are as follows:
3.1. If the taxable income is:
3.1.1. Between $0 and $15,000, the tax rate is 15%.
3.1.2. Between $15,001 and $40,000, the tax is $2,250 plus 25% of the taxable income over $15,000
3.1.3. Over $40,000, the tax is $8,460 plus 35% of the taxable income over $40,000.
4. The input file has the following information:
4.1. Marital Status (M or m for married, s or S for Single)
4.2. This is followed by the number of children under age of 14.
4.3. Gross salary (if married, then the data found is the combined salary of the couple.)
4.4. Last is the percentage of gross income contributed to the pension fund. This is between 0 and 6%.
5. Your program must read data from the input file provided. (Project4.txt is provided)
6. You program must consists of at least the following functions:
6.1. Function getData: This void function reads the data from the input file.
6.2. Function taxAmount: This value returning function computes and returns the tax amount. It must return a double which is the tax.
7. To calculate the taxable income, subtract the sum of standard exemption, the amount contributed to a pension plan, and a personal exemption, which is $1500 per person. (For example if a married couple had two children under the age of 14, then the personal exemption is $1500 X 4 = $6000.)
Input file:
Sample Data 1:
Married, 2 children, gross income - $125000 and pension contribution 5%.
Tax calculation
125000 - 7000- (125000*.05) - (4 * 1500)
= 125000 - 7000 - 6250 - 6000
=105750
105750 is over 40000
Tax = 8460+((105750-40000)*0.35)
= 8460 + (65750 * 0.35)
= 8460 +23012.50
=31472.50
Sample Data 9:
Single, 0 children, gross income - $43650 and pension contribution 4%
Tax calculation:
43650 - 4000-(43650*0.04) -(1500*1) = 43650 - 4000-1746 -1500 = 36404
36404 is between 15001 and 40000
Tax = 2250 +((36404-15000) *0.25) = 2250 +(21404 * 0.25) = 2250+5351 = 7601.00
Explanation / Answer
please rate - thanks
you didn't specify what the output file should look like
I've included copies of my input and output files
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void getData( ifstream&,char&,int&,double&,double& );
double taxAmount( char,int,double,double);
void putData(ofstream&,char,int,double,double,double);
int main()
{
ofstream out;
ifstream in;
char status;
int kids;
double gross,pension,tax;
in.open("Project4.txt");
if(in.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
out.open("Project4.out");
out<<"Status kids gross pension tax ";
getData(in,status,kids,gross,pension);
while(kids>=0)
{tax=taxAmount(status,kids,gross,pension);
putData(out,status,kids,gross,pension,tax);
getData(in,status,kids,gross,pension);
}
in.close();
out.close();
return 0;
}
void getData( ifstream& in,char& status,int& kids,double& gross,double& pension )
{in>>status;
if(in)
{in>>kids>>gross>>pension;
}
else kids=-5;
}
void putData( ofstream& out,char status,int kids,double gross,double pension,double tax)
{out<<status<<" "<<kids<<" "<<gross<<" "<<pension<<" "<<
setprecision(2)<<fixed<<tax<<endl;
}
double taxAmount( char status,int kids,double gross,double pension)
{double tax,exempt,taxable,pen,amt,end,rate;
int people;
if(toupper(status)=='S')
{exempt=4000;
people=1;
}
else
{exempt=7000;
people=2;
}
taxable=gross-exempt;
pen=gross*(pension/100.);
people+=kids;
taxable=gross-exempt- pen-people*1500;
if(taxable>40000)
{rate=.35;
tax=8460;
end=40000;
}
else if(taxable>15000)
{rate=.25;
tax=2250;
end=15000;
}
else
{rate=.15;
tax=0;
end=0;
}
tax=tax+(taxable-end)*rate;
return tax;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.