Question
use program 2 below to complete the following: Create a value returning function to calculate total exemption amount. Return the total exemption amount to the
use program 2 below to complete the following:
Create a value returning function to calculate total exemption amount. Return the total exemption amount to the calling routine.
Create a value returning function to calculate the taxable income. Return the taxable income to the calling routine.
Create a value returning function to calculate tax obligation. Return the tax obligation to the calling routine.
Create a value returning function to open files. Both the input and output files may be opened using one function. The function must contain the prompt for the user to enter the input file name. You may 'hardcode' the output file names (i.e., does not need to be user-entered, they can be a literal). The value returned to the calling routine must indicate a failure for any of the files or a success for ALL files. If an open fails, the CALLING routine displays a message and exits the program.
Create a function to close all files prior to program end.
Create a function to read the data. Remember, functions may call other functions.
Create a function to display the output as indicated in Programming Assignment 2, both to the console and to an output file.
Create a function to output the error messages and data to the error file.
Each function should have a proper function prototype.
Other than constant (CONST) identifiers, NO GLOBAL variables may be used
Main should contain the function calls only, no processing other than what is specified for the file open call and any necessary local variable declarations. Remember, functions may call other functions.
You may use the SAME data file created for Programming Assignment 2
Each function must have required documentation (pre and post conditions).
program 2
#include #include #include using namespace std;
int main() { string filename; string surname; char mStatus; int noOfChildren; double grossIncome,taxObligation; double sexcemptions,personalExcemp,pensionPlan; double taxableIncome=0,federalTax;
cout<
ifstream dataIn;
ofstream dataOut,dataOut1; dataOut< cout<<"Enter the filename:"; cin>>filename;
dataIn.open(filename.c_str());
if(dataIn.fail()) { cout<<"** "<
dataOut.open("taxReport.txt");
if(dataOut.fail()) { cout<<"** taxReport.txt File Not Found **"; return 1; } dataOut1.open("errorReport.txt"); if(dataOut1.fail()) { cout<<"** errorReport.txt File Not Found **"; return 1; } cout<<"Surname\t\tGross Inc Total Exemp($) Pension Dedt Taxable Inc tax Obli"< cout<<"-------\t\t--------- -------------- ------------ ----------- --------"< dataOut<<"Surname\t\tGross Inc Total Exemp($) Pension Dedt Taxable Inc tax Obli"< dataOut<<"-------\t\t--------- -------------- ------------ ----------- --------"< int flag=0; while(!dataIn.eof()) { flag=0; dataIn>>surname>>mStatus>>noOfChildren>>grossIncome>>taxObligation; switch(mStatus) { case 'S':{ sexcemptions=2500; personalExcemp=(noOfChildren+1)*650; break; } case 'M':{ sexcemptions=5500; personalExcemp=(noOfChildren+2)*650; break; } default:{ flag=1; dataOut1<<"Invalid Marital Status"< break; } } if(taxObligation>0.04) { flag=1; dataOut1<<"Invalid Pension Percentage"< } pensionPlan=taxObligation*grossIncome; taxableIncome=grossIncome-(sexcemptions+personalExcemp+pensionPlan); if(taxableIncome>=0 && taxableIncome<=20000) { federalTax=0.15*taxableIncome; } else if(taxableIncome>20001 && taxableIncome<=50000) { federalTax=2000+0.25*(taxableIncome-20000); } else if(taxableIncome>50000) { federalTax=8000+0.35*(taxableIncome-50000); } if(flag==0) { dataOut< cout< } } } dataIn.close(); dataOut.close(); return 0; }
input file
Krauss M 0 55000.00 .02 Tennant M 2 100000.00 .05 Grant S 0 142000.00 .04 Bing Q 1 55000.00 .03 Schuster S 2 175000.00 .0 Watt S 1 152000.00 .60 Smith M 1 70000.00 .03
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started