Question

4. Define a class named TaxReturn that contains a tax ID number, last name, first name, annual income, number of dependents, and amount of tax owed for a taxpayer Include constant static fields that hold the tax rates for the situations shown in the following table Income (S) 0-10,000 0,001-30,000 0,001-60,000 60,001 and up 0 dependents 0.10 0.12 0.18 0.25 1 dependent 0.08 0.11 0.15 0.22 2 or more dependents 0.07 0.09 0.13 0.19 Include a static function that displays the tax table. Write a main) function that contains a single statement that displays the tax table Add two public functions to the TaxReturn class: setAllO, which can set the field values and display), which can display them. The setAllOfunction accepts arguments for the tax ID number, last and first names, annual income, and number of dependents The setAllOfunction should then call a private function that computes the tax owed. Create an array of 10 TaxReturnobiects. In a loop, prompt the user for ID number, first and last name, annual income, and number of dependents, then use these values to set a TaxReturns fields. At the end of the loop, display all the values for all 10 TaxReturn objects, including the tax owed a) Draw a flowchart illustrating the program design to solve this problem. (4 Marks)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ program to define a class to store attributes for a tax payer and calculate tax owed

#include <iostream>

#include <iomanip>

#include<limits>

using namespace std;

class TaxReturn{

private:

               // class fields

               int taxId;

               string lastname;

               string firstname;

               double annualIncome;

               int dependents;

               double taxOwed;

               const static float income_10k_0_dep = 0.10;

               const static float income_10k_1_dep = 0.08;

               const static float income_10k_2_dep = 0.07;

               const static float income_30k_0_dep = 0.12;

               const static float income_30k_1_dep = 0.11;

               const static float income_30k_2_dep = 0.09;

               const static float income_60k_0_dep = 0.18;

               const static float income_60k_1_dep = 0.15;

               const static float income_60k_2_dep = 0.13;

               const static float income_60k_up_0_dep = 0.25;

               const static float income_60k_up_1_dep = 0.22;

               const static float income_60k_up_2_dep = 0.19;

               // function to calculate the tax owed

               void setTaxOwed()

               {

                              if(annualIncome<=10000)

                              {

                                             if(dependents == 0)

                                                            taxOwed = income_10k_0_dep*annualIncome;

                                             else if(dependents == 1)

                                                            taxOwed = income_10k_1_dep*annualIncome;

                                             else

                                                            taxOwed = income_10k_2_dep*annualIncome;

                              }else if(annualIncome <=30000)

                              {

                                             if(dependents == 0)

                                                            taxOwed = income_30k_0_dep*annualIncome;

                                             else if(dependents == 1)

                                                            taxOwed = income_30k_1_dep*annualIncome;

                                             else

                                                            taxOwed = income_30k_2_dep*annualIncome;

                              }else if(annualIncome <= 60000)

                              {

                                             if(dependents == 0)

                                                            taxOwed = income_60k_0_dep*annualIncome;

                                             else if(dependents == 1)

                                                            taxOwed = income_60k_1_dep*annualIncome;

                                             else

                                                            taxOwed = income_60k_2_dep*annualIncome;

                              }else{

                                             if(dependents == 0)

                                                            taxOwed = income_60k_up_0_dep*annualIncome;

                                             else if(dependents == 1)

                                                            taxOwed = income_60k_up_1_dep*annualIncome;

                                             else

                                                            taxOwed = income_60k_up_2_dep*annualIncome;

                              }

               }

public:

               // function to set all fields of a class

               void setAll(int taxId,string lastname,string firstname,double annualIncome,int dependents)

               {

                              this->taxId = taxId;

                              this->lastname = lastname;

                              this->firstname = firstname;

                              this->annualIncome = annualIncome;

                              this->dependents = dependents;

                              setTaxOwed();

               }

               // function to display the fields

               void display()

               {

                              cout<<" Tax ID : "<<taxId<<endl;

                              cout<<" First Name : "<<firstname<<endl;

                              cout<<" Last Name : "<<lastname<<endl;

                              cout<<" Annual Income : $"<<annualIncome<<endl;

                              cout<<" Number of dependents "<<dependents<<endl;

                              cout<<" Tax owed : $"<<taxOwed<<endl;

               }

               // methdo to print the tax table

               static void printTaxTable()

               {

                              cout<<"\n"<<left<<setw(15)<<"Income($)"<<left<<setw(15)<<"0 dependents"<<left<<setw(15)<<"1 dependents"<<left<<"2 or more dependents"<<endl;

                              cout<<left<<setw(15)<<"0-10,000"<<left<<setw(15)<<income_10k_0_dep<<left<<setw(15)<<income_10k_1_dep<<left<<income_10k_2_dep<<endl;

                              cout<<left<<setw(15)<<"10,001-30,000"<<left<<setw(15)<<income_30k_0_dep<<left<<setw(15)<<income_30k_1_dep<<left<<income_30k_2_dep<<endl;

                              cout<<left<<setw(15)<<"30,001-60,000"<<left<<setw(15)<<income_60k_0_dep<<left<<setw(15)<<income_60k_1_dep<<left<<income_60k_2_dep<<endl;

                              cout<<left<<setw(15)<<"60,001and up"<<left<<setw(15)<<income_60k_up_0_dep<<left<<setw(15)<<income_60k_up_1_dep<<left<<income_60k_up_2_dep<<endl;

               }

};

int main() {

               TaxReturn::printTaxTable(); // print tax table

               TaxReturn taxReturn[10];

               int id,dependents;

               string fname,lname;

               double income;

               // loop to input the details of 10 tax payers and display the details

               cout<<"\n Enter details for 10 tax payers : ";

               for(int i=0;i<10;i++)

               {

                              cout<<"\n Tax ID : ";

                              cin>>id;

                              std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); //cin leaves \n in the input so remove it

                              cout<<" Firstname :";

                              getline(cin,fname);

                              cout<<" Lastname :";

                              getline(cin,lname);

                              cout<<" Annual income :";

                              cin>>income;

                              cout<<" Number of dependents : ";

                              cin>>dependents;

                              taxReturn[i].setAll(id,lname,fname,income,dependents);

                              cout<<endl;

                              taxReturn[i].display();

               }

               return 0;

}

//end of program

Output:

Income($) 0-10,000 10,001-30,000 0.12 30,001-60,000 0.18 60,001and up 0.25 0 dependents 1 dependents 2 or more dependents 0.08 0.11 0.15 0.22 0.07 0.09 0.13 0.19 Enter details for 10 tax payers: Tax ID 1 Firstname :Chris Lastname:Fallon Annual income:8000 Number of dependents: 0 Tax ID 1 First Name : Chris Last Name: Fallon Annual Income : $8000 Number of dependents 0 Tax owed: $800 Tax ID 2 Firstname :Lynda Lastname:Ann Annual income : 8000 Number of dependents 1 Tax ID 2 First Name Lynda Last Name Ann Annual Income : $8000 Number of dependents 1 Tax owed : $640

Flowchart :

Add a comment
Know the answer?
Add Answer to:
4. Define a class named TaxReturn that contains a tax ID number, last name, first name,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class named Poem that contains the following fields: title - the name of the...

    Create a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a...

  • *** C++ *** Create a class called Student that contains a first name ( string) and...

    *** C++ *** Create a class called Student that contains a first name ( string) and an student id number (type long).     1. Include a member function called get_data( ) to get data from the user for insertion into the object,     2. Also include a function called display_data( ) that displays the student data. Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of...

  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

  • a) Create an abstract class Student. The class contains fields for student Id number, name, and...

    a) Create an abstract class Student. The class contains fields for student Id number, name, and tuition. Includes a constructor that requires parameters for the ID number and name. Include get and set method for each field; setTuition() method is abstract. b) The Student class should throw an exception named InvalidNameException when it receives an invalid student name (student name is invalid if it contains digits). c) Create three student subclasses named UndergradStudent, GradeStudent, and StudentAtLarge, each with a unique...

  • Graded Exercise Create a class named Student. A Student has fields for an ID number, number...

    Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...

  • Design a class named EmployeeRecord that holds an employee’s ID number, name, and payrate. Include mutator...

    Design a class named EmployeeRecord that holds an employee’s ID number, name, and payrate. Include mutator methods to set the values for each data field and output the values for each data field. Create the class diagram and write the code that defines the class and implements the mutator methods. need help please with this question

  • c/c++ Last name: First name: ID: Sec: The name, ID and section number that appear at...

    c/c++ Last name: First name: ID: Sec: The name, ID and section number that appear at the beginning of the output of the program should be your own, not the ones used in the sample Note: results printed must show the data entered at run time, not the data shown in the sample run below! Sample run: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24...

  • a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number,...

    a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...

  • java Invoice class

    Create a class named Invoice that contains fields for an item number, name, quantity, price, and total cost. Create insurance methods that set the item name, quantity,and price. Whenever the price for quantity is set, recalculate the total (price times quantity). Also include a display Line() method that displays the item number,name, quantity, price, and total cost. Make sure you include a class named TestInvoice whose main method () declares three Invoice items. Create a method that prompts the user...

  • A class allows a group of one or more member objects to have a series of...

    A class allows a group of one or more member objects to have a series of common characteristics and functions. Create a class (student) that contains the member characteristics: Student ID (string) Student Last Name (string) Student First Name (string) GPA (float) Number of enrolled classes (integer) The class functions are: setID (string passed to function to set Student ID) setLastName (string passed to function to set Student Last Name) setFirstName (string passed to function to set Student First Name)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT