Modified Project 5 File, Added Project 6 Files
+- Project 5 File ++ Project 6 Files (Utils and Main)
This commit is contained in:
parent
8651123e1e
commit
5119f73add
14 changed files with 3021 additions and 39 deletions
143
PA06-1019/Project_6.c
Normal file
143
PA06-1019/Project_6.c
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
// header files
|
||||
#include "StandardConstants.h"
|
||||
#include "Console_IO_Utility.h"
|
||||
#include "File_Input_Utility.h"
|
||||
#include "File_Output_Utility.h"
|
||||
#include "Arizona_Tax_Utility.h"
|
||||
|
||||
// constants
|
||||
// none
|
||||
|
||||
// function prototypes
|
||||
|
||||
/*
|
||||
Name: createOutputString
|
||||
Process: creates string to be displayed and output to file;
|
||||
only one string can be assembled in the function
|
||||
Function input/parameters: the output string pointer, tax year and tax
|
||||
Function output/parameters: the generated output string (char *)
|
||||
Function output/returned: none
|
||||
Function input/keyboard: none
|
||||
Device output/file: none
|
||||
Dependencies: sprintf
|
||||
*/
|
||||
void createOutputString(char *outputString, int taxYear, double totalTax);
|
||||
|
||||
/*
|
||||
Name: outputResultsToFile
|
||||
Process: opens file for output, writes string to file with endline,
|
||||
closes file
|
||||
Function input/parameters: file name (const char *),
|
||||
output string (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Function input/keyboard: none
|
||||
Device output/file: none
|
||||
Dependencies: File Output Utility tools
|
||||
*/
|
||||
void outputResultsToFile(const char *outputFileName, const char *outputString);
|
||||
|
||||
// main program
|
||||
int main()
|
||||
{
|
||||
// show title
|
||||
// Functions: printf
|
||||
printf("\nDUMMY TAX CALCULATOR V0.4\n=========================\n\n");
|
||||
|
||||
// initialize variables
|
||||
char taxInformationFile[STD_STR_LEN];
|
||||
char outputString[STD_STR_LEN], outputFileName[STD_STR_LEN];
|
||||
double taxArizona, currentIncome;
|
||||
int yearCount, currentYear;
|
||||
yearCount = 0;
|
||||
|
||||
// get user input
|
||||
// Functions: promptForString
|
||||
promptForString("Enter file name containing tax information: ",
|
||||
taxInformationFile);
|
||||
// conduct calculations
|
||||
// Functions: calculateArizonaTax, outputResultsToFile
|
||||
|
||||
// open input file
|
||||
openInputFile(taxInformationFile);
|
||||
|
||||
// use a while loop to iterate over the numbers of years, prime with
|
||||
// first year.
|
||||
currentYear = readIntegerFromFile();
|
||||
currentIncome = readDoubleFromFile();
|
||||
yearCount = yearCount + 1;
|
||||
while (!checkForEndOfInputFile()) {
|
||||
sprintf(outputFileName, "Tax_Report_%d.txt", currentYear);
|
||||
taxArizona = calculateArizonaTax(currentIncome);
|
||||
createOutputString(outputString, currentYear, taxArizona);
|
||||
outputResultsToFile(outputFileName, outputString);
|
||||
yearCount = yearCount + 1;
|
||||
currentYear = readIntegerFromFile();
|
||||
currentIncome = readDoubleFromFile();
|
||||
}
|
||||
|
||||
// display results
|
||||
// Functions: sprintf, printf
|
||||
printf("\nArizona tax for %d years has been calculated.\n", yearCount - 1);
|
||||
printf("\nThe results can be viewed in the report files.\n");
|
||||
|
||||
// end program, return success
|
||||
printf("\nEnd Program\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// supporting functions
|
||||
|
||||
/*
|
||||
Name: createOutputString
|
||||
Process: creates string to be displayed and output to file;
|
||||
only one string can be assembled in the function
|
||||
Function input/parameters: the output string pointer, tax year and tax
|
||||
Function output/parameters: the generated output string (char *)
|
||||
Function output/returned: none
|
||||
Function input/keyboard: none
|
||||
Device output/file: none
|
||||
Dependencies: sprintf
|
||||
*/
|
||||
|
||||
void createOutputString(char *outputString, int taxYear, double totalTax)
|
||||
{
|
||||
// initialize variables
|
||||
// none
|
||||
// get user input
|
||||
// input is passed into function by parameters.
|
||||
// conduct calculations
|
||||
// none
|
||||
// display results
|
||||
sprintf(outputString, "For the tax year %d total"
|
||||
" AZ tax to be paid is $%.2f.", taxYear, totalTax);
|
||||
}
|
||||
|
||||
/*
|
||||
Name: outputResultsToFile
|
||||
Process: opens file for output, writes string to file with endline,
|
||||
closes file
|
||||
Function input/parameters: file name (const char *),
|
||||
output string (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Function input/keyboard: none
|
||||
Device output/file: none
|
||||
Dependencies: File Output Utility tools
|
||||
*/
|
||||
|
||||
void outputResultsToFile(const char *outputFileName, const char *outputString)
|
||||
{
|
||||
// initialize variables
|
||||
// none
|
||||
// get user input
|
||||
// input is passed into function by parameters.
|
||||
// conduct calculations
|
||||
// none
|
||||
// display results
|
||||
// outputs a file
|
||||
openOutputFile(outputFileName);
|
||||
writeStringToFile(outputString);
|
||||
closeOutputFile();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue