Modify Project 5

+- Modified Project 5

Signed-off-by: cdez <cdez@cdezselfhosted.pw>
This commit is contained in:
Charles Descamps 2022-10-11 20:59:48 -07:00
parent d4e725bf7c
commit b4a2c14805

View file

@ -161,7 +161,60 @@ Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: none
*/
double calculateArizonaTax(double adjustedIncome)
{
// define variables
// need a variable that holds the amount of money after the last bracket takes from it.
double incomeLeft, totalAZTax;
incomeLeft = 0;
totalAZTax = 0;
// get input
// input is passed in from the function parameter
// do calculations
// use if statements to calculate through the progressive tax brackets
if (adjustedIncome < AZ_TAX_BASELINE_LIMIT)
{
// check for baseline bracket
// calculate tax for baseline
totalAZTax = adjustedIncome * AZ_TAX_BASELINE_RATE;
return totalAZTax;
}
else if(adjustedIncome < AZ_TAX_FIRST_BRACKET_LIMIT)
{
// check for first bracket and baseline bracket
// calculate tax for first and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * AZ_TAX_BASELINE_RATE);
totalAZTax = incomeLeft * AZ_TAX_FIRST_BRACKET_RATE;
return totalAZTax;
}
else if(adjustedIncome < AZ_TAX_SECOND_BRACKET_LIMIT)
{
// check for second, first, and baseline bracket
// calculate tax for second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * AZ_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * AZ_TAX_FIRST_BRACKET_RATE);
totalAZTax = incomeLeft * AZ_TAX_SECOND_BRACKET_RATE;
return totalAZTax;
}
else
{
// otherwise, apply the max, second, first, and baseline bracket
// calculate tax for max, second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * AZ_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * AZ_TAX_FIRST_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * AZ_TAX_SECOND_BRACKET_RATE);
totalAZTax = incomeLeft * AZ_TAX_MAX_RATE;
}
// display results
// not needed, returns instead.
// return value
// returns the final calculated tax
return totalAZTax;
}
/*
Name: calculateFederalTax
@ -173,7 +226,97 @@ Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: none
*/
double calculateFederalTax(double adjustedIncome)
{
// define variables
// need a variable that holds the amount of money after the last bracket takes from it.
// as well as a variable to return the amount of tax paid.
double incomeLeft, totalFedTax;
incomeLeft = 0;
totalFedTax = 0;
// get input
// input is passed in from the function parameter
// do calculations
// use if statements to calculate through the progressive tax brackets
if (adjustedIncome < FED_TAX_BASELINE_LIMIT)
{
// check for baseline bracket
// calculate tax for baseline bracket
totalFedTax = adjustedIncome * FED_TAX_BASELINE_RATE;
return totalFedTax;
}
else if(adjustedIncome < FED_TAX_FIRST_BRACKET_LIMIT)
{
// check for first bracket and baseline bracket
// calculate tax for first and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE);
totalFedTax = incomeLeft * FED_TAX_FIRST_BRACKET_RATE;
return totalFedTax;
}
else if(adjustedIncome < FED_TAX_SECOND_BRACKET_LIMIT)
{
// check for second, first, and baseline bracket
// calculate tax for second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE);
totalFedTax = incomeLeft * FED_TAX_SECOND_BRACKET_RATE;
return totalFedTax;
}
else if(adjustedIncome < FED_TAX_THIRD_BRACKET_LIMIT)
{
// check for third, second, first, and baseline bracket
// calculate tax for third, second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE);
totalFedTax = incomeLeft * FED_TAX_THIRD_BRACKET_RATE;
return totalFedTax;
}
else if(adjustedIncome < FED_TAX_FOURTH_BRACKET_LIMIT)
{
// check for fourth, third, second, first, and baseline bracket
// calculate tax for fourth, third, second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_THIRD_BRACKET_RATE);
totalFedTax = incomeLeft * FED_TAX_FOURTH_BRACKET_RATE;
return totalFedTax;
}
else if(adjustedIncome < FED_TAX_FIFTH_BRACKET_LIMIT)
{
// check for fifth, fourth, third, second, first, and baseline bracket
// calculate tax for fifth, fourth, third, second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_THIRD_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FOURTH_BRACKET_RATE);
totalFedTax = incomeLeft * FED_TAX_FIFTH_BRACKET_RATE;
return totalFedTax;
}
else
{
// otherwise, apply the max, fifth, fourth, third, second, first, and baseline bracket
// calculate tax for max, fifth, fourth, third, second, first, and baseline bracket
incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_THIRD_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FOURTH_BRACKET_RATE);
incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIFTH_BRACKET_RATE);
totalFedTax = incomeLeft * FED_TAX_MAX_RATE;
}
// display results
// not needed, returns instead.
// return value
// returns the final calculated tax
return totalFedTax;
}
/*
Name: displayResultsTable
@ -187,3 +330,157 @@ Device Output/Monitor: table as showed in example for PA05
Dependencies: printEndline, printString, printCharacter, printStringJustified,
printDoubleJustified
*/
void displayResultsTable(double taxArizona, double taxFederal,
double incomeAfterTaxes, double effectiveTax,
double taxTotal, double incomeLocked)
{
// define variables
// no variables needed.
// get input
// input is from the parameters
// do calculations
// no calculations are done here.
// display results
// print top line
// function: printString, printEndline
printEndline();
printString( TOP_LINE );
printEndline();
// print title line
// function: printCharacter, printStringJustified, printEndline
printCharacter( PIPE );
printStringJustified( "DUMMY TAX CALCULATIONS",
TABLE_WIDTH - 2, "CENTER" );
printCharacter( PIPE );
printEndline();
// print thick divider line
// function: printString, printEndline
printString( THICK_LINE_DIVIDER );
printEndline();
// print sub title line
// function: printStringJustified, printString, printCharacter,
// printEndline
printString( PIPE_SPACE );
printStringJustified( "Data Name", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "Units", UNIT_WIDTH, "CENTER" );
printString( PIPE_SPACE );
printStringJustified( "Value", VALUE_WIDTH - 2, "CENTER" );
printString( SPACE_PIPE );
printEndline();
// print thick divider line
// function: printString, printEndline
printString( THICK_LINE_DIVIDER );
printEndline();
// print Arizona tax rate
// function: printStringJustified, printString, printCharacter,
// printEndline
printString( PIPE_SPACE );
printStringJustified( "AZ Tax Rate ", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "$", UNIT_WIDTH, "CENTER" );
printCharacter( PIPE );
printDoubleJustified( taxArizona,
PRECISION, VALUE_WIDTH -1, "RIGHT" );
printString( SPACE_PIPE );
printEndline();
// print thin divider line
// function: printString, printEndline
printString( THIN_LINE_DIVIDER );
printEndline();
// print Federal tax rate
// function: printStringJustified, printString, printCharacter,
// printEndline
printString( PIPE_SPACE );
printStringJustified( "Fed Tax Rate", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "$", UNIT_WIDTH, "CENTER" );
printCharacter( PIPE );
printDoubleJustified( taxFederal,
PRECISION, VALUE_WIDTH -1, "RIGHT" );
printString( SPACE_PIPE );
printEndline();
// print thin divider line
// function: printString, printEndline
printString( THIN_LINE_DIVIDER );
printEndline();
// print Effective tax rate
// function: printStringJustified, printString, printCharacter,
// printEndline
printString( PIPE_SPACE );
printStringJustified( "Effective Tax Rate ", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "%", UNIT_WIDTH, "CENTER" );
printCharacter( PIPE );
printDoubleJustified( effectiveTax * PERCENTAGE_CONVERSION,
PRECISION, VALUE_WIDTH - 1, "RIGHT" );
printString( SPACE_PIPE );
printEndline();
// print thin divider line
// function: printString, printEndline
printString( THIN_LINE_DIVIDER );
printEndline();
// Total tax paid
// function: printStringJustified, printString, printCharacter,
// printEndline
printString( PIPE_SPACE );
printStringJustified( "Tax To Be Paid ", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "$", UNIT_WIDTH, "CENTER" );
printCharacter( PIPE );
printDoubleJustified( taxTotal, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
printString( SPACE_PIPE );
printEndline();
// print thin divider line
// function: printString, printEndline
printString( THIN_LINE_DIVIDER );
printEndline();
printString( PIPE_SPACE );
printStringJustified( "Income After Tax ", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "$", UNIT_WIDTH, "CENTER" );
printCharacter( PIPE );
printDoubleJustified( incomeAfterTaxes,
PRECISION, VALUE_WIDTH - 1, "RIGHT" );
printString( SPACE_PIPE );
printEndline();
// print thin divider line
// function: printString, printEndline
printString( THIN_LINE_DIVIDER );
printEndline();
printString( PIPE_SPACE );
printStringJustified( "Locked in IRA ", DATA_NAME_WIDTH - 1, "LEFT" );
printCharacter( PIPE );
printStringJustified( "%", UNIT_WIDTH, "CENTER" );
printCharacter( PIPE );
printDoubleJustified( incomeLocked,
PRECISION, VALUE_WIDTH - 1, "RIGHT" );
printString( SPACE_PIPE );
printEndline();
// print thick divider line
// function: printString, printEndline
printString( THICK_LINE_DIVIDER );
printEndline();
}