Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this project, you will use your programming skills to write a program that do

ID: 3846246 • Letter: I

Question

In this project, you will use your programming skills to write a program that does the following:

1. Reads the contents of a file called "taxdata.txt"

2. Create a class called Taxpayer to store and keep track of each individual taxpayer

3. Store the data in a single list of Taxpayers

4. Write to a file called "taxesdue.txt" that contains each Taxpayer's name, social security number, and the remaining amount they owe (rounded to the nearest cent). The file should be formatted in organized columns and the entries should be sorted by the remaining tax owed.

In order to do this assignment, you must create a user-defined class called Taxpayer. The class definition and member function definitions should be contained in a single file called Taxpayer.h. IMPORTANT: for this assignment, you are turning in two files: the class definition Taxpayer.h, as well as hw6.cpp, the source file that creates your program. You do NOT turn in any text files! We will test your program on our own version of "taxdata.txt".

Details:

Taxpayer class details:

Taxpayer class should hold private variables for: social security number (stored as an int), last name and first name (stored as strings), filing status (stored as a bool), and gross income and taxes paid (stored as doubles). You are free to use any additional private variables if you would like.

It should have a default constructor as well as a regular constructor so that each of the above private variables may be set.

It should have any accessor or mutator member functions necessary for the assignment. It should have an overloaded < operator to compare remaining taxes owed of two Taxpayers. (payer1 < payer2 if remaining taxes owed of payer1 < remaining taxes owed of payer2).

In order to do the above operator overload, your Taxpayer class should have built within it a way to compute the total tax owed according to the gross income of the individual. The implementation details are left up to you, but you should follow good programming practices as outlined in class. Taxes should be computed according to the following basic tax tiers:

For Taxpayers filing with single status:

1. If the gross income is above $0 and no larger than $37,650, the taxpayer owes a total of 15% of his/her gross income.

2. If the gross income is above $37,650 and no larger than $91,150, the taxpayer owes a total of 25% of his/her gross income.

3. If the gross income is above $91,150, the taxpayer owes a total of 28% of his/her gross income.

For Taxpayers filing with married status:

1. If the gross income is above $0 and no larger than $75,300, the taxpayer owes a total of 15% of his/her gross income.

2. If the gross income is above $75,300 and no larger than $151,900, the taxpayer owes a total of 25% of his/her gross income.

3. If the gross income is above $151,900, the taxpayer owes a total of 28% of his/her gross income.

The remaining tax owed of each Taxpayer is the difference between his/her total tax owed and taxes paid. (Note that this number could be negative, which would indicate that that Taxpayer is owed a tax refund.)

Note:  When working on this assignment in the PIC Lab, you should be sure to store your project in your own personal Z: directory, NOT on the desktop. The file read/write operations will not work correctly if your project is not in Z:.

taxdata.txt details:

The file "taxdata.txt" contains a listing for each person on its own line. Data is given in the following order with a space between entries: social security number, last name, first name, filing status ("s" for single, "m" for married), gross income, taxes paid. An example file is provided.

Sample run:

An example of the input file "taxdata.txt" and corresponding output file "taxesdue.txt" are provided. Note that your code must be able to adapt to different contents of the file "taxdata.txt" (including a possibly different number of entries). The format of the entries will remain the same.

Submission:

As noted above, this submission requires two files: Taxpayer.h, and hw6.cpp. (You should not provide the text files -- we will test your program on our own text file!) If your files are not named and submitted exactly like this, your homework will not be graded. Your code should contain useful comments as well as your name, the date, and a brief description of what the program does. Your grade will not only depend on your program running successfully and providing correct output -- it will also depend on readability and good programming practices followed in your code (including encapsulation). Upload your files to the CCLE website. The files will be automatically collected at date and time described in the submission summary below.

taxdata (1).txt 1656666666 Barrymore Christina s 55212 1022.66 222353222 Doe Jane m 22352.10 212.55 333535333 Simpson Homer m 49212. 12 11542.22 111111111 Smith Tim s 23550211. 12 2055. 21 700009000 Coen Seymour s 90222 100 787878787 Daniels Beryl m 10335.22 368.22 999999999 McDonald Ronald s 655502.26 1252.22

Explanation / Answer

Here is the code for the question. The program creates an output file name taxdue.txt . Sample contents of output file also attached. Please don't forget to rate the answer if it helped. Thank you very much.

Taxpayer.h

#include <iostream>
using std::string;
class Taxpayer
{
private:
int ssn;
string firstname, lastname;
bool married;
double income, taxpaid, total_tax, tax_due;

public:
//default constructor
Taxpayer()
{
ssn = 0;
firstname = lastname = "";
married = false;
income = taxpaid = 0;
total_tax = 0;
}
//constructor with parameters
Taxpayer(int ssn_in, string firstname_in, string lastname_in, bool married_in, double income_in, double taxpaid_in)
{
ssn = ssn_in;
firstname = firstname_in;
lastname = lastname_in;
married = married_in;
income = income_in;
taxpaid = taxpaid_in;
total_tax = 0;
}

void setSSN(int ssn_in)
{
ssn = ssn_in;
}

void setFirstname(string name)
{
firstname = name;
}
void setLastname(string name)
{
lastname = name;
}

void setMarried(bool status)
{
married = status;
}
void setGrossIncome(double amount)
{
income = amount;
}
void setTaxpaid(double amount)
{
taxpaid = amount;
}

int getSSN()
{
return ssn;
}

string getFirstname()
{
return firstname;
}

string getLastname()
{
return lastname;
}

double getTaxPaid()
{
return taxpaid;
}

double getTaxDue()
{
return tax_due;
}

bool operator <(Taxpayer other)
{
return tax_due < other.tax_due;
}

void calculate_tax()
{
if(!married)
{
if(income > 0 && income <= 37650)
total_tax = 0.15 * income;
else if (income <= 91150)
total_tax = 0.25 * income;
else
total_tax = 0.28 * income;
}
else
{
if(income > 0 && income <= 75300)
total_tax = 0.15 * income;
else if (income <= 151900)
total_tax = 0.25 * income;
else
total_tax = 0.28 * income;
}

tax_due = total_tax - taxpaid;
}
};

hw6.cpp

#include <iostream>
#include <fstream>
#include <iomanip>
#include "Taxpayer.h"

#define MAX_RECORDS 100
using namespace std;

//selection sort the payers list using the overloaded < operator
void sort(Taxpayer payers[], int n)
{
int minIdx;
for(int i = 0 ; i < n; ++i)
{
minIdx = i;
for(int j = i+1; j < n; ++j)
{
if(payers[j] < payers[minIdx])
minIdx = j;
}
if(minIdx != i)
{
Taxpayer temp;
temp = payers[i];
payers[i] = payers[minIdx];
payers[minIdx] = temp;
}
}
}
int main()
{
ifstream infile("taxdata.txt");

if(infile.fail())
{
cout<<"Error opening input file! "<<endl;
exit(1);
}

Taxpayer payers[MAX_RECORDS];
int count = 0;
int ssn;
string first, last;
double gross, taxpaid;
char status;

while(infile>>ssn)
{
infile >> first >> last >> status >> gross >> taxpaid;
payers[count].setSSN(ssn);
payers[count].setFirstname(first);
payers[count].setLastname(last);
payers[count].setMarried(status == 'm');
payers[count].setGrossIncome(gross);
payers[count].setTaxpaid(taxpaid);

payers[count].calculate_tax();
count++;
}
infile.close();

sort(payers, count);

ofstream outfile("taxdue.txt");
if(outfile.fail())
{
cout<<"Error opening output file!"<<endl;
exit(1);
}

outfile << "SSN Last Name First Name Tax Due"<<endl;

for(int i = 0; i < count; i++)
{
outfile << setw(15) << left << payers[i].getSSN ();
outfile << setw(20) << left << payers[i].getFirstname();
outfile << setw(20) << left << payers[i].getLastname();
outfile << setw(15) << right << fixed << setprecision(2) << payers[i].getTaxDue() << endl;

}
outfile.close();

}

input file taxdata.txt

656666666 Barrymore Christina s 55212 1022.66
222353222 Doe Jane m 22352.10 212.55
333535333 Simpson Homer m 49212.12 11542.22
111111111 Smith Tim s 23550211.12 2055.21
700009000 Coen Seymour s 90222 100
787878787 Daniels Beryl m 10335.22 368.22
999999999 McDonald Ronald s 655502.26 1252.22

output file taxdue.txt

SSN                    Last Name                    First Name                            Tax Due
333535333 Simpson Homer -4160.40
787878787 Daniels Beryl 1182.06
222353222 Doe Jane 3140.26
656666666 Barrymore Christina 12780.34
700009000 Coen Seymour 22455.50
999999999 McDonald Ronald 182288.41
111111111 Smith Tim 6592003.90

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote