In: Computer Science
Must use codeblocks
C++
An IRS agent is checking taxpayer’s returns in the $30,000.00 to $40,000.00 income bracket (gross earnings). Each record of the data file contains a tax identification number (four digits), gross earnings, and the amount of taxes paid for the year. If the taxes paid are below 20.5% of the gross earnings, you are to compute the taxes due (assume all taxes are in the bracket of 20.5% of gross earnings). If there are taxes due a penalty charge of 4% is added to the amount. If the taxes due exceed $1,300.00 an additional 2.0% penalty charge is added to the amount over $1,300.00. For those that paid more than the 20.5%, compute the refund due and leave a message to that effect. Records of gross earnings outside the range of $30,000.00 to $40,000.00 are not checked and an appropriate message must be printed to that effect.
Your program must also generate a summary report containing the following information:
1. The total number of records in the data file.
2. The total number of taxpayer’s checked in range.
3. The total number of taxpayer’s receiving refunds.
4. The total dollar amount refunded.
5. The total number of taxpayer’s that owe taxes.
6. The total dollar amount of taxes due.
7. The total dollar amount of penalties due.
8. The average dollar amount refunded.
9. The average dollar amount of taxes due.
10. The average dollar amount of the penalties due.
Note: You must use functions for the following:
1. The headings.
2. One function to compute the averages. (called three times)
3. Print the summary report.
4. Other functions may be used were you deemed appropriate.
Submit your source code and algorithm or flowchart in blackboard.
All values must be clearly labeled in the output.
You are required to demonstrate your output in Lab.
#include
#include
using namespace std;
const int size=100;
//read tax data from file and save into parallel
arrauys
int readFromFile(int taxid[size],double earnings[size],double
tax[size])
{
int n=0;
int tmp;
ifstream myfile ("earnings.txt");
if (myfile.is_open())
{
while(myfile>>tmp)
{
n++;
taxid[n]=tmp;
myfile>>earnings[n];
myfile>>tax[n];
}
myfile.close();
}
else
cout << "Unable to open file";
return n;
}
//calculate tax based on conditions provided
void calTax(int n,int taxid[],double earnings[],double tax[],double
refund[],double penalty[])
{
cout<<"\n******Calculating
tax*********\n";
//loop though each tax payer
for(int i=0;i<=n;i++)
{
//display the detils ofe
ach tx payer
cout<<"\nID: "<
if(earnings[i]>30000
&& earnings[i]<=40000)
{
cout<<"\nYou are currently outside the tax cal bracket.
Hence,no tax ia calauclated.";
}
//else actual tax
calculation comes into picture
else
{
//calculate taxtobe paid based on income and check if
refund/penalty has to be initiated
double taxToBePaid=earnings[i]*0.205;
//if he has paid less tax
if(tax[i]
//caculate tax due
double taxDue=taxToBePaid-tax[i];
if(taxDue>1300)
{
penalty[i]+=0.02*(taxDue-1300);
}
penalty[i]+=taxDue*.04;
tax[i]+=penalty[i];
cout<<"\nPenalty of "<
//else calculate refund amt
else if(tax[i]>taxToBePaid)
{
refund[i]=tax[i]-taxToBePaid;
cout<<"\nRefund of "<
}
}
cout<<"\n******Calculating tax DONE*********";
}
//get count of tax payers
int getTaxPayerinRange(int n,double penalty[])
{
int count=0;
for(int i=0;i<=n;i++)
{
if(penalty[i]==0)
count++;
}
return count;
}
//get count of tax payers who has refund
int getTaxPayerRefund(int n,double refund[])
{
int count=0;
for(int i=0;i<=n;i++)
{
if(refund[i]>0)
count++;
}
return count;
}
//get amt of refund amount
double getRefundAmt(int n,double refund[])
{
double amt=0;
for(int i=0;i<=n;i++)
{
if(refund[i]>0)
amt+=refund[i];
}
return amt;
}
//get count of tax payers who pay penalty
int getTaxPayerPenalty(int n,double penalty[])
{
int count=0;
for(int i=0;i<=n;i++)
{
if(penalty[i]>0)
count++;
}
return count;
}
//get penalty amount
double getPenaltyAmt(int n,double penalty[])
{
double amt=0;
for(int i=0;i<=n;i++)
{
if(penalty[i]>0)
amt+=penalty[i];
}
return amt;
}
//get tax amt paid
double getTaxAmt(int n,double tax[])
{
double amt=0;
for(int i=0;i<=n;i++)
{
if(tax[i]>0)
amt+=tax[i];
}
return amt;
}
//takes size of array and value and then computes average
double computeAvg(int n,double value)
{
return value/n;
}
//display the report
void print(int n,double earnings[],double tax[],double
refund[],double penalty[])
{
cout<<"\nThe total number of records in
the data file: "<
//main function
int main()
{
//declare variables needed
int n=-1;
int taxid[size];
double earnings[size];
double tax[size];
double refund[size];
double penalty[size];
//call required funcitons
n=readFromFile(taxid,earnings,tax);
calTax(n,taxid,earnings,tax,refund,penalty);
print(n,earnings,tax,refund,penalty);
return 0;
}