Need help on following program using C++ langugae. Write a program that can be u
ID: 3686930 • Letter: N
Question
Need help on following program using C++ langugae.
Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows: If the taxable income is:
Between $0 and $15,000, the tax rate is 15%.
Between $15,001 and $40,000, the tax is $2,250 plus 25% of the taxable income over $15,000.
Over $40,000, the tax is $8,460 plus 35% of the taxable income over $40,000.
Prompt the user to enter the following information:
Marital status
If the marital status is ‘‘married,’’ ask for the number of children under the age of 14
Gross salary (If the marital status is ‘‘married’’ and both spouses have income, enter the combined salary.)
Percentage of gross income contributed to a pension fund
To calculate the taxable income, subtract the sum of the standard exemption, the amount contributed to a pension plan, and the personal exemption, which is $1,500 per person. (Note that if a married couple has two children under the age of 14, then the personal exemption is $1,500 * 4 = $6,000.). Display the adjusted income, base tax, additional tax, and tax amount owed.
Design with functions and provide test data which shows that your program is working correctly.
write source code which should be commented as follows:
Analysis at the top of the file including your test data sets and predicted results.
Function analysis, preconditions, and postconditions after each function prototype
Major tasks identified as comments in main function
Comments in functions as needed
Explanation / Answer
#include <iostream> //Input and output
void getInfo(int &numPerson, int &salary, int &standardExemption, int &pretaxSavings);
int taxAmount(int numPerson, int salary, int standardExemption,
int pretaxSavings, int &taxableIncome, int &baseTax, int &marginTax);
// Main function
int main ()
{
int numPerson, salary, standardExemption, pretaxSavings, taxableIncome, baseTax, marginTax;
int totalTax;
//get getInfo
getInfo(numPerson, salary, standardExemption, pretaxSavings);
//get taxableIncome, baaseTax, marginTax, and totalTax.
totalTax = taxAmount(numPerson, salary, standardExemption, pretaxSavings, taxableIncome, baseTax, marginTax);
// Output adjusted income
std::cout << " Adjusted income: $" << taxableIncome << std::endl;
// Output base tax
std::cout << "Base tax: $" << baseTax << std::endl;
// Output additional tax
std::cout << "Addtional tax: $" << marginTax << std::endl;
// Output total tax owed
std::cout << "Total tax owed: $" << totalTax << std::endl;
return 0;
}
// Gets the input and stores them
void getInfo(int &numPerson, int &salary, int &standardExemption, int &pretaxSavings)
{
char maritalStatus, answer, rAnswer;
int numChildren;
int pensionPlan;
// Ask if single or married
std::cout << "What is your marital status?" << std::endl;
std::cout << " M for Married and S for Single: ";
std::cout << "=====> ";
std::cin >> maritalStatus;
std::cout << std::endl;
// If married, standard exemption is 7000, and asks for kids
if (maritalStatus == 'm' || maritalStatus == 'M')
{
std::cout << "Please enter number of Children: " << std::endl;
std::cout << " Must be under the age of 14"<< std::endl;
std::cout << "=====> ";
std::cin >> numChildren;
std::cout << std::endl;
// stanardExemption for married couple
standardExemption = 7000;
// If both earn income, then combine income.
std::cout << "Do both spouses earn income?" << std::endl;
std::cout << " Y or y for Yes" << std::endl;
std::cout << " Any other key for No : "<< std::endl;
std::cout << "====> ";
std::cin >> answer;
std::cout << std::endl;
// Enter combined salary:
if (answer == 'y' || answer == 'Y' )
{
std::cout << " Your combined salary is: $" << std::endl;
std::cout << "=====> $";
std::cin >> salary;
std::cout << std::endl;
}
// Enter just your salary
else
{
std::cout << "Enter your salary: " << std::endl;
std::cout << "=====> $";
std::cin >> salary;
std::cout << std::endl;
}
// Personal Exemption equals couple plus the number of children
numPerson = 2 + numChildren;
// Retirement contribution for married couple
std::cout << "Did you contribute to your retirement account?" << std::endl;
std::cout << " Enter y or Y, for Yes" << std::endl;
std::cout << " Anything else for No." << std::endl;
std::cout << "=====> ";
std::cin >> rAnswer;
// If answer is yes, put the percentage up to 6%
if (rAnswer == 'y' || rAnswer == 'Y')
{
std::cout << " Enter the percentage you put into the pension plan: " << std::endl;
std::cout << " 6% is max" << std::endl;
std::cout << "=====> ";
std::cin >> pensionPlan;
// If above 0 and below 6% contributed
if (pensionPlan >0 && pensionPlan <=6)
{
pretaxSavings = pensionPlan * salary/100;
// Output pretax Savings from pension contribution
std::cout << " Pre-tax saving from retirement account: $" << pretaxSavings << std::endl;
}
// If entered something beside 1 through 6
else
{
std::cout << " Please put int 1-6%" << std::endl;
std::cin >>pensionPlan;
pretaxSavings = pensionPlan * salary/100;
std::cout << " Pre-tax saving from retirement account: " << pretaxSavings << std::endl;
}
}
// If answer is no, didn't contribute to retirement
else
{
std::cout << "You didn't contribute to your retirement account." << std::endl;
pensionPlan = 0;
pretaxSavings = pensionPlan * salary/100;
std::cout << "Pre-tax saving from retirement account: " << pretaxSavings << std::endl;
}
}
// Single
else
{
// Input salary
std::cout << "Enter your salary: $";
std::cin >> salary;
std::cout << std::endl;
standardExemption = 4000;
numPerson = 1;
// Asks if contributed to retirement account
std::cout << "Did you contribute to your retirement account?" << std::endl;
std::cout << " Type y or Y, for Yes" << std::endl;
std::cout << " Anything else for No." << std::endl;
std::cout << "=====> ";
std::cin >> rAnswer;
// if Yes
if (rAnswer == 'y' || rAnswer == 'Y')
{
std::cout << " Enter the percentage you put into the pension plan: ";
std::cout << " 6% is max" << std::endl;
std::cout << "=====> " << std::endl;
std::cin >> pensionPlan;
if (pensionPlan >0 && pensionPlan <=6)
{
pretaxSavings = pensionPlan * salary/100;
std::cout << " Pre-tax saving from retirement account: $" << pretaxSavings << std::endl;
}
else
{
std::cout << " Please put int 1-6%" << std::endl;
std::cout << "=====> ";
std::cin >>pensionPlan;
pretaxSavings = pensionPlan * salary/100;
std::cout << " Pre-tax saving from retirement account: $" << pretaxSavings << std::endl;
}
}
// if No
else
{
std::cout << " You didn't contribute to your retirement account." << std::endl;
pensionPlan = 0;
pretaxSavings = pensionPlan * salary/100;
std::cout << " Pre-tax saving from retirement account: $" << pretaxSavings << std::endl;
}
}
}
// Calculate taxes owed
int taxAmount(int numPerson, int salary, int standardExemption, int pretaxSavings, int &taxableIncome, int &baseTax, int &marginTax)
{
int marginalIncome;
int totalTax;
// Taxable income
taxableIncome = salary - (1500 * numPerson) - standardExemption - pretaxSavings;
// Bracket 1
if (taxableIncome >= (0) && taxableIncome <= 15000)
{
baseTax =.15 * taxableIncome;
marginTax = 0;
totalTax = baseTax+marginTax;
}
// Bracket 2
else if (taxableIncome >= (15001) && taxableIncome <= 40000)
{
marginalIncome = taxableIncome - 15000;
marginTax = .25 * marginalIncome;
baseTax = 2250;
totalTax = baseTax+marginTax;
}
// Bracket 3
else if (taxableIncome > (40000))
{
marginalIncome = taxableIncome - 40000;
marginTax = .35 * taxableIncome;
baseTax = 8460;
totalTax = baseTax + marginTax;
}
// Returns the total tax owed
return totalTax;
}
sample output
What is your marital status?
M for Married and S for Single:
=====> M
Please enter number of Children:
Must be under the age of 14
=====> 2
Do both spouses earn income?
Y or y for Yes
Any other key for No :
====> Y
Your combined salary is: $ 15000
=====> $
Did you contribute to your retirement account?
Enter y or Y, for Yes
Anything else for No.
=====> Y
Enter the percentage you put into the pension plan:
6% is max 6
=====> Pre-tax saving from retirement account:
Adjusted income: $-1100
Base tax: $165
Addtional tax: $0
Total tax owed: $-165
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.