Please code in C++, PLEASE DO ALL THE BOLDED WORDS. PLEASE finish the codes in m
ID: 3881095 • Letter: P
Question
Please code in C++, PLEASE DO ALL THE BOLDED WORDS. PLEASE finish the codes in main, taxconstant, TaxDataType, Tax.cpp, Tax.hpp
--------------------------------------------------------------------------------------------------------
For the assignment, we will create a program that will take the annual income and tax rate for from 1 to many tax payers, and compute each payer’s amount of taxes that are due for the year. The amount is calculated by taking each payer’s income, multiply it by the tax rate, yielding their taxes ( taxes = income * taxRate ).
Here is the decomposition of tasks:
Create a structure that contains the tax payer information, the tax rate, the income, and the taxes (all floats).
Create a namespace (give your own intuitive name) that contains the constant size, which will be used in tax payer information input and output
Create a function called taxTaker that will do the input of tax payers’ information. The function should take the inputs for the income and the tax rate for each tax payer, and then calculate the taxes. This function should also use standard input validation and ensure the data is good (numeric), and that it falls with the range of 0.01 through 9.9 for rate, and income amounts are greater than zero.
Create a function called taxPrint that will print out tax information for all the payers. Make sure to format the output in accord with the sample output below. The output should be for dollar amounts. This will print for each payer, up to the size.
FILE ARRANGEMENT SUGGESTION
You can have many files (but no less than 3) files on your own with your own file names. We suggest 5 files with their names below:
Main.cpp: a file that holds main() function. Primary task for this file is doing test. We also call it test driver. It looks like attached image below. Read the comments in the image.
TaxConstants.hpp: a head file that holds constants used in the application (such as SIZE). This file can be included in many cpp files. All constants held in one place for an application is a good practice for future application maintenance. See image below and the comments within the image
TaxDataType.hpp: holds data types (i.e. the struct of tax payer). This file can be included in may cpp files wherever it is used. See image below.
A pair of Tax.cpp and Tax.hpp: holds the implementation function code and prototypes.
Tax.hpp: prototypes of functions. It can be included in many cpp files wherever functions are used
Tax.cpp: implementation of functions. Please notice that its own head file Tax.hpp is included. Tax.hpp must be included so that you don’t need to worry about the order of functions in case functions call other functions.
-------------------------------------
main:
#include <iostream>
#include "Tax.hpp"
int main()
{
//create an array or vector to hold tax payers' information
//Your code ...
taxTaker(***parameters***);
taxPrint(***parameters***);
return 0;
}
TaxConstants:
namespace TAXCONSTANTS
{
const int SIZE = 4;
}
TaxDataType:
struct taxPayer
{
float taxRate;
float income;
float taxes;
};
Tax.cpp
void taxPrint(***parameters***){
//your code ...
}
void taxTaker(***parameters***){
//your code ...
}
tax.hpp:
#include "TaxDataType.hpp"
void taxPrint(***parameters***); //must match to the same function in Tax.cpp
void taxTaker(***parameters***); //must match to the same function in Tax.cpp
Explanation / Answer
main.cpp
--------------------------------------------
#include <iostream>
#include "Tax.hpp"
using namespace std;
int main()
{
//Declare array of taxPayers
taxPayer arr[TAXCONSTANTS::SIZE];
//Take in incomes and tax rates
taxTaker(arr);
//Calculate and print tax totals
taxPrint(arr);
return 0;
}
----------------------------------------------------
Tax.cpp
--------------------------
#include <iostream>
#include <limits>
#include <cmath>
#include <iomanip>
#include "TaxConstants.hpp"
#include "Tax.hpp"
void taxTaker(taxPayer arr[TAXCONSTANTS::SIZE])
{
std::cout << "Please enter the annual income and tax rate for " << TAXCONSTANTS::SIZE << " tax payers:" << std::endl << std::endl;
//Loop to take in the values for each taxpayer up to SIZE
for(int x = 0; x < TAXCONSTANTS::SIZE; x++)
{
//Input validation
bool loopFlag = true;
do
{
std::cout << "Enter this year's income for tax payer "
<< x + 1 << ": " << std::endl;
//Take in each person's tax rate
std::cin >> arr[x].income;
if((std::cin.fail()) || (arr[x].income < 0))
{
std::cout << "The taxpayer's income must be positive" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
}
else
{
loopFlag = false;
}
}while(loopFlag);
//Input validation
loopFlag = true;
do
{
std::cout << "Enter this year's tax rate for tax payer "
<< x + 1 << ": " << std::endl;
//Take in each person's tax rate
std::cin >> arr[x].taxRate;
if((std::cin.fail()) || (arr[x].taxRate < 0.01) || (arr[x].taxRate > 9.9))
{
std::cout << "The taxpayer's tax rate must be between 0.01 and 9.9" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
}
else
{
loopFlag = false;
}
}while(loopFlag);
std::cout << std::endl;
}
}
//Calculate and print each person's tax total
void taxPrint(taxPayer arr[TAXCONSTANTS::SIZE])
{
std::cout << "Taxes due for this year:" << std::endl;
for(int x = 0; x < TAXCONSTANTS::SIZE; x++)
{
std::cout << "Tax Payer # " << x + 1 << ": $" << std::fixed << std::setprecision(2) << arr[x].income * (arr[x].taxRate * pow(10,-2)) << std::endl;
}
}
--------------------------------------------------------
Tax.hpp
-------------------------------
#ifndef TAX_HPP
#define TAX_HPP
#include "TaxDataType.hpp"
#include "TAXCONSTANTS.hpp"
//Prototypes
void taxTaker(taxPayer arr[TAXCONSTANTS::SIZE]);
void taxPrint(taxPayer arr[TAXCONSTANTS::SIZE]);
#endif // TAX_HPP
--------------------------------------------------------
TaxDataType.hpp
-----------------------------------
#ifndef TAXDATATYPE_HPP
#define TAXDATATYPE_HPP
struct taxPayer
{
float taxRate;
float income;
float taxes;
};
#endif // TAXDATATYPE_HPP
--------------------------------------------------------
TAXCONSTANTS.hpp
-------------------------------------
#ifndef TAXCONSTANTS_HPP
#define TAXCONSTANTS_HPP
namespace TAXCONSTANTS
{
const int SIZE = 2;
}
#endif