CS136-Projects/PA09-1118/Project_9.c
cdez deffe66afe Modify Project 8, Upload Project 9 Files
+- Project_8.c modified, subject to 80 char limit.
++ Project 9 Files Added
2022-11-17 13:42:25 -07:00

194 lines
5.8 KiB
C

// header files
#include <stdio.h>
#include <stdlib.h>
#include "Console_IO_Utility.h"
#include "File_Output_Utility.h"
#include "File_Input_Utility.h"
// global constants
// enumerator for column indexes
typedef enum { COLUMN_A, COLUMN_B, COLUMN_C, COLUMN_D, COLUMN_E } TableColumns;
// enumarator for filing type
typedef enum { MARRIED, SINGLE, NONE } FilingFlag;
// conversion into percent rate
const double PERCENT_CONVERSION = 0.01;
// tax table properties
const char TAX_TABLE_R_COUNT = 4;
const char TAX_TABLE_C_COUNT = 5;
// on demand data files
const char MARRIED_TAX_DATA[] = "married.csv";
const char SINGLE_TAX_DATA[] = "single.csv";
const int TAX_DATA_TITLE_SIZE = 60;
// output table columns size
const int OUT_TABLE_COLUMN_SIZE = 15;
// A linked list node
typedef struct Node
{
// TODO
} singleLinkNode;
// function prototypes
double calculateTax(double taxDataArray[TAX_TABLE_R_COUNT][TAX_TABLE_C_COUNT],
double totalIncome);
/*
Name: calculateTax
Process: identifies correct tax bracket using tax data from array and income
calculates tax using tax data from array as well as with
formula presented below
TT = ((TI + Col_C) * Col_D %) + Col_E
, where
TT - Total Tax
TI - Total Income
Col_C - COLUMN_C (same as maximum limit of previous tax bracket)
Col_D - COLUMN_D (same as rate, must be converted into %)
Col_E - COLUMN_E (same as max possible tax for all previous brackets)
Function Input/Parameters: tax data aray and total income
Function Output/Parameters: none
Function Output/Returned: total tax
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: none
*/
double calculateTax(double taxDataArray[TAX_TABLE_R_COUNT][TAX_TABLE_C_COUNT],
double totalIncome)
{
// initialize variables
double totalTax = 0;
int rowValue;
// get user input
// input passed in though parameters
// do calculations
// check total income valid.
if (totalIncome <= 0)
{
return 0;
}
// totalTax should use the process above to calculate.
// column a is the tax bracket minimum
// column b is the tax bracket maximum
// check to see where total income falls to figure out what rate to use.
for (rowValue = 0; rowValue < TAX_TABLE_R_COUNT; rowValue++)
{
if ((totalIncome >= taxDataArray[rowValue][COLUMN_A]) || (taxDataArray[rowValue][COLUMN_B] <= totalIncome))
{
totalTax = ((totalIncome + taxDataArray[rowValue][COLUMN_C]) * taxDataArray[rowValue][COLUMN_D] * PERCENT_CONVERSION) + taxDataArray[rowValue][COLUMN_E];
}
}
// display results
// none
// return value
return totalTax;
}
/*
Name: calculateTotal
Process: given header to linked lists, traverses list, accsses data (income)
adds income to the total sum of incomes, returns total income
Function Input/Parameters: pointer to the head of income list
Function Output/Parameters: none
Function Output/Returned: total income
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: none
*/
// TODO
/*
Name: displayCorrectTable
Process: displays tax data table
Function Input/Parameters: table containing tax data
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: iteratively prints table as shown in examples
Dependencies: printCharacter, printDoubleJustified, printf
*/
// TODO
/*
Name: displayTaxTable
Process: based on filling type prints apropriate title for table
and calls for table to be displayed
Function Input/Parameters: table containing tax data and filing type
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: title for table
Dependencies: displayCorrectTable, printf
*/
// TODO
/*
Name: getTaxReturnType
Process: ask user for input and based on input assigns appropriate filing type
Function Input/Parameters: none
Function Output/Parameters: none
Function Output/Returned: returns filling type either SINGLE or MARRIED
Device Input/Keyboard: character either m/M/s/S
Device Output/Monitor: none
Dependencies: promptForCharacter
*/
// TODO
/*
Name: printProgramTitle
Process: displays program title
Function Input/Parameters: none
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: title displayed as specified
Dependencies: Console IO Utilities tools OR stdio.h
*/
// TODO
/*
Name: skipOneRow
Process: skips one line of input file
Function Input/Parameters: none
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: readStringToDelimiterFromFile OR readStringToLineEndFromFile
*/
// TODO
/*
Name: uploadDataIntoLL
Process: opens file for input, uploads values and assigns them linked list,
closes files, returns head pointer to the list
Function Input/Parameters: file name and
Function Output/Parameters: none
Function Output/Returned: head pointer to the list
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: openInputFile, readIntegerFromFile, checkForEndOfInputFile
readCharacterFromFile, closeInputFile
*/
// TODO
/*
Name: uploadTaxTable
Process: uploads table from file into 2d array
Function Input/Parameters: accepts name of the file which stores tax table
and reference to tax data array in which to store
tax data (use constants to set size of array)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: openInputFile, readDoubleFromFile, skipOneRow, readCharacterFromFile
*/
// TODO
// TODO MORE :)