From 7c8246c576ac821ab1ab977ee79c555ac47b44c7 Mon Sep 17 00:00:00 2001 From: cdez Date: Mon, 12 Sep 2022 13:52:18 -0700 Subject: [PATCH] Added Homework 2 - May need some further changes Might have to make some further changes later. --- PA02-0914/Console_IO_Utility.c | 590 +++++++++++++++++++++++++++++++++ PA02-0914/Console_IO_Utility.h | 289 ++++++++++++++++ PA02-0914/Project_2.c | 333 +++++++++++++++++++ PA02-0914/Project_2_PRG | Bin 0 -> 22800 bytes PA02-0914/StandardConstants.h | 54 +++ 5 files changed, 1266 insertions(+) create mode 100644 PA02-0914/Console_IO_Utility.c create mode 100644 PA02-0914/Console_IO_Utility.h create mode 100644 PA02-0914/Project_2.c create mode 100644 PA02-0914/Project_2_PRG create mode 100644 PA02-0914/StandardConstants.h diff --git a/PA02-0914/Console_IO_Utility.c b/PA02-0914/Console_IO_Utility.c new file mode 100644 index 0000000..38b9f46 --- /dev/null +++ b/PA02-0914/Console_IO_Utility.c @@ -0,0 +1,590 @@ +// Header files included +#include "Console_IO_Utility.h" + +// Function Implementations + +/* +Name: clearLeadingCharacters +Process: Clears all leading non-printable characters from the console stream +Function input/parameters: allow space return (Boolean) +Function output/parameters: none +Function output/returned: first printable character as integer +Device input/keyboard: none +Device output/monitor: none +Dependencies: getchar +*/ +int clearLeadingCharacters( bool allowSpaceReturn ) + { + // initialize data, set input character to getChar, set count to zero + // function: getchar + int intChar = getchar(); + int charCount = 0; + + // loop while non-printable characters and space if not set + // also limits looping to constant limit + while( ( intChar < (int)SPACE + || ( !allowSpaceReturn && intChar == SPACE ) ) + && charCount < MAX_STR_LEN ) + { + // update character count + charCount++; + + // get new input character + // function: getchar + intChar = getchar(); + } + + // return captured character + return intChar; + } + +/* + +Name: getChar +Process: returns next character in stream, + ignores all white space (including SPACE) prior to character +Function input/parameters: flag to accept space (Boolean) +Function output/parameters: none +Function output/returned: one character (char) is returned to calling method +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: getCharFiltered +*/ +char getChar() + { + // initialize variables, set space accept flag to false + bool dontAcceptSpace = false; + + // call filtered function with space accept flag + // function: getCharFiltered + return getCharFiltered( dontAcceptSpace ); + } + +/* +Name: getCharFiltered +Process: returns next character in stream, + ignores non printable characters prior to input character + but may accept space depending on flag +Function input/parameters: flag to accept space (boolean) +Function output/parameters: none +Function output/returned: first printable character or space (if configured) + returned (char) +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +char getCharFiltered( bool acceptSpace ) + { + //Initialize variables + int inCharInt; + + // clear leading characters, capture first usable character + // function: clearLeadingCharacters + inCharInt = clearLeadingCharacters( acceptSpace ); + + // check for input character set to end of file + if( inCharInt == EOF ) + { + // return character zero + return '0'; + } + + // return input character as character + return (char)inCharInt; + } + +/* +Name: getInputString +Process: acquires input string from keyboard, if clear white space flag set, + ignores all white space, including space character +Function input/parameters: clear white space control (Boolean) +Function output/parameters: character array (char[]) +Function output/returned: none +Device input/keyboard: user entry of a character stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +void getInputString( char inputArr[], bool clearWhiteSpace ) + { + //Initialize Variables, set character count and index to zero + int charCount = 0; + int index = 0; + int intChar; + + // check for clear white space flag + if( clearWhiteSpace ) + { + // clear leading characters, set flag to ignore space + // function: clearLeadingCharacters + intChar = clearLeadingCharacters( !clearWhiteSpace ); + } + + // otherwise, assume white space flag not set + else + { + // get first character + // function: getchar + intChar = getChar(); + } + + // loop until enter key found, limit loop to constant + while( intChar != (int)NEWLINE_CHAR && charCount < MAX_STR_LEN ) + { + // set current value to array element + inputArr[ index ] = (char)intChar; + + // increment string array index + index++; + + // add null character to end of string array + inputArr[ index ] = NULL_CHAR; + + // increment character count + charCount++; + + // get next character + // function: getchar + intChar = getchar(); + } + } + +/* +Name: printCharacter +Process: prints a single character +Function input/parameters: character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: character printed as specified +Dependencies: printCharacters +*/ +void printCharacter( char outputChar ) + { + // initialize number of characters to one + int numberOfChars = 1; + + // print one character + // function: printChars + printCharacters( numberOfChars, outputChar ); + } + +/* +Name: printCharacters +Process: prints given number of characters +Function input/parameters: number of characters (int), + character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: Number of specified characters printed +Dependencies: printf +*/ +void printCharacters( int numChars, char outputChar ) + { + // check for reminaing characters to print + if( numChars > 0 ) + { + // print one character + // function: printf + printf( "%c", outputChar ); + + // (recursive) print remaining characters + // function: printChars + printCharacters( numChars - 1, outputChar ); + } + } + +/* +Name: printDouble +Process: simple print double function +Function input/parameters: + outVal - the double value to be output (double) + precision - the number of digits to the right of the decimal point (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed +Dependencies: printDoubleJustified +*/ +void printDouble( double outVal, int precision ) + { + // initialize variables, set block size to zero and justified to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // call justified function with specified parameters + // function: printDoubleJustified + printDoubleJustified( outVal, precision, blockSize, justified ); + } + +/* +Name: printDoubleJustified +Process: the precision is set for the double value, then the pre-spaces + and post-spaces are calculated for the requested justification, + and then the pre-spaces are printed, the double value is printed, + and then the post-spaces are printed +Function input/parameters: + outVal - the double value to be output (double) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed, justified, with precision +Dependencies: formatDouble, printStringJustified +*/ +void printDoubleJustified( double outVal, int precision, + int blockSize, const char* justify ) + { + // initialize variables, create temp string for configuration string + char specStr[ MIN_STR_LEN ]; + + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // set configuration string with precision value + // function: sprintf + sprintf( specStr, "%s0.%dlf", "%", precision ); + + // set output string + // function: sprintf + sprintf( outStr, specStr, outVal ); + + // print string justified + // function: printStringJustified + printStringJustified( outStr, blockSize, justify ); + } + +/* +Name: printEndline +Process: prints single endline character to end a line or create vertical space +Function input/parameters: none +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one endline character output +Dependencies: printf +*/ +void printEndline() + { + // print one newline character + // function: printf + printf( "\n" ); + } + +/* +Name: printEndlines +Process: prints the specified number of endline characters + to end a line and/or create vertical space(s) +Function input/parameters: number of endlines (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: endline characters output as specified +Dependencies: printEndline +*/ +void printEndlines( int numEndlines ) + { + // check for number of end lines remaining + if( numEndlines > 0 ) + { + // print one endling + // function: printEndline + printEndline(); + + // (recursive) print remaining end lines + printEndlines( numEndlines - 1 ); + } + } + +/* + Name: printInteger + Process: prints integer value +Function input/parameters: outVal - the integer value to be output + Output: None + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: printIntegerJustified + */ +void printInteger( int outVal ) + { + // initialize variables, set block size to zero, justifification to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // print justified integer with specified parameters + // function: printIntegerJustified + printIntegerJustified( outVal, blockSize, justified ); + } + +/* + Name: printIntegerJustified + Process: prints integer value with the specified justification + within the specified blockSize +Function input/parameters: + outVal - the integer value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) + Output: None + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: sprintf, printStringJustified + */ +void printIntegerJustified( int outVal, int blockSize, const char *justify ) + { + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // convert integer to string + // function: sprintf + sprintf( outStr, "%d", outVal ); + + // print justified string + // function: printStringJustified + printStringJustified( outStr, blockSize, justify ); + } + +/* +Name: printLongInteger +Process: prints long integer +Function input/Parameters: outVal - the long integer value to be output +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: printLongIntJustified +*/ +void printLongInteger( long outVal ) + { + // initialize variables, set block size to zero, justification to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // print justified long integer with specified parameters + // function: printLongIntegerJustified + printLongIntegerJustified( outVal, blockSize, justified ); + } + +/* +Name: printLongIntegerJustified +Process: prints long integer with the specified justification + within the specified blockSize +Function input/Parameters: + outVal - the long integer value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: sprintf, printStringJustified +*/ +void printLongIntegerJustified( long outVal, + int blockSize, const char *justify ) + { + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // convert long integer to string + // function: sprintf + sprintf( outStr, "%ld", outVal ); + + // print justified string + // function: printStringJustified + printStringJustified( outStr, blockSize, justify ); + } + +/* + Name: printString + Process: prints string +Function input/parameters: outVal - the string value to be output +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: printStringJustified +*/ +void printString( const char *outStr ) + { + // initialize variables, set block size to zero, justification to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // print justified string with specified parameters + // function: printStringJustified + printStringJustified( outStr, blockSize, justified ); + } + +/* + Name: printStringJustified + Process: prints string within specified block size + and with specified justification +Function input/parameters: + outVal - the string value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: strlen, strcmp, printCharacters, printf +*/ +void printStringJustified ( const char *outStr, + int blockSize, const char *justify ) + { + // initialize variables, set pre-, post- spaces to zero + int preSpaces = 0, postSpaces = 0, strLength; + + // find length of string + // function: strlen + strLength = strlen( outStr ); + + // check justification for "LEFT" + // function: strcmp + if( strcmp( justify, "LEFT" ) == 0 ) + { + // set post spaces for left justification + postSpaces = blockSize - strLength; + } + + // otherwise, check justification for "RIGHT" + // function: strcmp + else if( strcmp( justify, "RIGHT" ) == 0 ) + { + // set pre spaces for right justification + preSpaces = blockSize - strLength; + } + + // Otherwise, assume "CENTER" justification + else + { + // set pre spaces for centered + preSpaces = blockSize / 2 - strLength / 2; + + // set post spaces for centered + postSpaces = blockSize - strLength - preSpaces; + } + + // print pre spaces + // function: printChars + printCharacters( preSpaces, SPACE ); + + // print string + // function: printf + printf( "%s", outStr ); + + // print post spaces + // function: printChars + printCharacters( postSpaces, SPACE ); + } + +/* +Name: promptForCharacter +Process: prompts user for character, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: None +Function output/returned: one character (chars +Device input/keyboard: user entry of a character +Device output/monitor: prompt string displayed +Dependencies: printf, getChar +*/ +char promptForCharacter( const char *promptString ) + { + // initialize variables + char outChar; + + // print prompt string + // function: printf + printf( "%s", promptString ); + + // get character from stream + // function: getChar + outChar = (char)getChar(); + + // return captured character + return outChar; + } + +/* +Name: promptForDouble +Process: prompts user for double, then returns it +Function input/parameters: test to prompt user (c-string) +Function output/parameters: None +Function output/returned: value (double) +Device input/keyboard: user entry of an integer value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf + */ +double promptForDouble( const char *promptString ) + { + // initialize variables + double outDouble; + + // print prompt string + // function: printf + printf( "%s", promptString ); + + // get double value + // function: scanf + scanf( "%lf", &outDouble ); + + // return captured double + return outDouble; + } + +/* +Name: promptForInteger +Process: prompts user for integer, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: none +Function output/returned: integer value (int) +Device input/keyboard: user entry of a double value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf +*/ +int promptForInteger( const char *promptString ) + { + // initialize variables + int outInt; + + // print prompt string + // function: printf + printf( "%s", promptString ); + + // input integer + // function: scanf + scanf( "%d", &outInt ); + + // return captured integer + return outInt; + } + +/* +Name: promptForString +Process: prompts user for string, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: input string from user(c-string) +Function output/returned: none +Device input/keyboard: user entry of a string value +Device output/monitor: prompt string displayed +Dependencies: printf, getInputString +*/ +void promptForString( const char *promptString, char returnStr[] ) + { + // initialize variables, don't allow white space capture + bool dontClearWhitespace = false; + + // pring prompt string + // function: printf + printf( "%s", promptString ); + + // get input string from user (returned via parameter) + // function: getInputString + getInputString( returnStr, dontClearWhitespace ); + } + + diff --git a/PA02-0914/Console_IO_Utility.h b/PA02-0914/Console_IO_Utility.h new file mode 100644 index 0000000..cb76f1c --- /dev/null +++ b/PA02-0914/Console_IO_Utility.h @@ -0,0 +1,289 @@ +// Preprocessor directive +#ifndef CONSOLE_IO_UTILITY_H +#define CONSOLE_IO_UTILITY_H + +//Header Files +#include +#include +#include +#include "StandardConstants.h" + +//Global Constants + + // none + +//Function Prototypes + +/* +Name: clearLeadingCharacters +Process: Clears all leading non-printable characters from the console stream +Function input/parameters: allow space return (bool) +Function output/parameters: none +Function output/returned: first printable character as integer +Device input/keyboard: none +Device output/monitor: none +Dependencies: getchar +*/ +int clearLeadingCharacters( bool allowSpaceReturn ); + +/* +Name: getChar +Process: returns next character in stream, + ignores all white space (including SPACE) prior to character +Function input/parameters: flag to accept space (bool) +Function output/parameters: none +Function output/returned: one character (char) is returned to calling method +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: +*/ +char getChar(); + +/* +Name: getCharFiltered +Process: returns next character in stream, + ignores non printable characters prior to input character + but may accept space depending on flag +Function input/parameters: flag to accept space (bool) +Function output/parameters: none +Function output/returned: first printable character or space (if configured) + returned (char) +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +char getCharFiltered( bool acceptSpace ); + +/* +Name: getInputString +Process: acquires input string from keyboard, if clear white space flag set, + ignores all white space, including space character +Function input/parameters: clear white space control (bool) +Function output/parameters: character array (char[]) +Function output/returned: none +Device input/keyboard: user entry of a character stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +void getInputString(char inputArr[], bool clearWhiteSpace ); + +/* +Name: printCharacter +Process: prints a single character +Function input/parameters: character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: character printed as specified +Dependencies: printCharacters +*/ +void printCharacter( char outputChar ); + +/* +Name: printCharacters +Process: prints given number of characters +Function input/parameters: number of characters (int), + character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: Number of specified characters printed +Dependencies: printf +*/ +void printCharacters( int numChars, char outputChar ); + +/* +Name: printDouble +Process: simple print double function +Function input/parameters: + outVal - the double value to be output (double) + precision - the number of digits to the right of the decimal point (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed +Dependencies: printDoubleJustified +*/ +void printDouble( double outVal, int precision ); + +/* +Name: printDoubleJustified +Process: the precision is set for the double value, then the pre-spaces + and post-spaces are calculated for the requested justification, + and then the pre-spaces are printed, the double value is printed, + and then the post-spaces are printed +Function input/parameters: + outVal - the double value to be output (double) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed, justified, with precision +Dependencies: formatDouble, printStringJustified +*/ +void printDoubleJustified( double outVal, int precision, + int blockSize, const char* justify ); + +/* +Name: printEndline +Process: prints single endline character to end a line or create vertical space +Function input/parameters: none +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one endline character output +Dependencies: printEndline +*/ +void printEndline(); + +/* +Name: printEndlines +Process: prints the specified number of endline characters + to end a line and/or create vertical space(s) +Function input/parameters: number of endlines (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: endline characters output as specified +Dependencies: printEndline +*/ +void printEndlines( int numEndlines ); + +/* + Name: printInteger + Process: prints integer value + Function input/parameters: outVal - the integer value to be output + Function output/parameters: None + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: printIntegerJustified + */ +void printInteger( int outVal ); + +/* + Name: printIntegerJustified + Process: prints integer value with the specified justification + within the specified blockSize + Function input/parameters: + outVal - the integer value to be output (int) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) + Function output/parameters: none + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: sprintf, printStringJustified + */ +void printIntegerJustified( int outVal, int blockSize, const char *justify ); + +/* +Name: printLongInteger +Process: prints long integer +Function input/Parameters: outVal - the long integer value to be output +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: printLongIntJustified +*/ +void printLongInteger( long outVal ); + +/* +Name: printLongIntegerJustified +Process: prints long integer with the specified justification + within the specified blockSize +Function Input/Parameters: + outVal - the long integer value to be output (long int) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: sprintf, printStringJustified +*/ +void printLongIntegerJustified( long outVal, + int blockSize, const char *justify ); + +/* + Name: printString + Process: prints string +Function input/parameters: outVal - the string value to be output +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: printStringJustified +*/ +void printString( const char *outStr ); + +/* + Name: printStringJustified + Process: prints string within specified block size + and with specified justification +Function input/parameters: + outStr - the string value to be output (c-string) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: strlen, strcmp, printCharacters, printf +*/ +void printStringJustified( const char *outStr, + int blockSize, const char *justify ); + +/* +Name: promptForCharacter +Process: prompts user for character, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: None +Function output/returned: one character (chars +Device input/keyboard: user entry of a character +Device output/monitor: prompt string displayed +Dependencies: printf, getChar +*/ +char promptForCharacter( const char *promptString ); + +/* +Name: promptForDouble +Process: prompts user for double, then returns it +Function input/parameters: test to prompt user (c-string) +Function output/parameters: None +Function output/returned: value (double) +Device input/keyboard: user entry of an integer value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf + */ +double promptForDouble( const char *promptString ); + +/* +Name: promptForInteger +Process: prompts user for integer, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: none +Function output/returned: integer value (int) +Device input/keyboard: user entry of a double value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf +*/ +int promptForInteger( const char *promptString ); + +/* +Name: promptForString +Process: prompts user for string, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: input string captured (c-string) +Function output/returned: none +Device input/keyboard: user entry of a string value +Device output/monitor: prompt string displayed +Dependencies: printf, getInputString +*/ +void promptForString( const char *promptString, char returnStr[] ); + +#endif // end CONSOLE_IO_UTILITY_H diff --git a/PA02-0914/Project_2.c b/PA02-0914/Project_2.c new file mode 100644 index 0000000..2d19829 --- /dev/null +++ b/PA02-0914/Project_2.c @@ -0,0 +1,333 @@ +// header files +#include "Console_IO_Utility.h" + +// global constants +const double ABSOLUTE_BASE = 0.0000001; +const double BOOSTING_VALUE = 5.55; +const double DRYWALL_PRICE = 3.00; +const double PLYWOOD_PRICE = 3.125; // per square foot +const double ROOFING_PRICE = 3.535525; // per square foot +const double SIDE_WALL_RATIO = 0.67; +const double SQUARE_ROOT_PRECISION = 0.000001; +const double TWO_BY_FOUR_PRICE = 7.50; // per board + +const int HOUSE_HEIGHT = 10; +const int NUM_2x4_PER_FOOT = 6; +const int TRIMMING_VALUE = 10; +const int TWO_ENDLINES = 2; + +// constants for table +const int DESCRIPTION_WIDTH = 16; +const int TABLE_WIDTH = 39; +const int UNIT_WIDTH = 9; +const int VALUE_WIDTH = 10; + +const char THICK_LINE = '='; +const char THIN_LINE = '-'; + +// prototypes +double findAbsolute( int value ); +double findSquareRoot( double value ); +void printDividedLine( char thickness ); +void printHeavyDividedLine(); +void printLightDividedLine(); +void printTopLine(); + +// main program +int main() + { + // Define Variables Needed: desiredArea (int) actualArea (int) houseWidth (int) houseDepth (int) + // roofingCost (double) plywoodCost (double) twoByFourCost (double) drywallCost (double) + // totalEstimate (double) + int desiredArea, actualArea, houseWidth, houseDepth; + double roofingCost, plywoodCost, twoByFourCost, drywallCost, totalEstimate; + + // Print the house cost estimator headline + printString("House Cost Estimator"); + printEndline(); + + // Print a dividing line, use printCharacters(). + printCharacters(20, '='); + + // Print 2 blank lines for formatting nicely. + printEndlines(2); + + // Ask user for input about the desired floor sq.ft.-age. + desiredArea = promptForInteger("Enter the desired floor square footage: "); + + // Calculate the house width(2/3 rounded of the area) (formula: sqrt((desiredSQFT/0.67))) + // then divide by trimmed value, cast to int, and then multiply by trimmed value to get result. + houseWidth = ((findSquareRoot(desiredArea/SIDE_WALL_RATIO)) + BOOSTING_VALUE); + houseWidth = houseWidth / TRIMMING_VALUE; + houseWidth = (int) houseWidth * TRIMMING_VALUE; + printEndline(); + // Calculate the house depth(1/3 rounded of the area) (formula: desiredArea/houseWidth) + houseDepth = desiredArea / houseWidth; + // Calculate the actual area (houseWidth * houseDepth) + actualArea = houseWidth * houseDepth; + + // Calculate the roofing cost(using the equation provided on BBLearn) + roofingCost = actualArea * ROOFING_PRICE; + // Calculate the plywood cost(sums up all the walls and floors of the house.) + plywoodCost = ((houseWidth * HOUSE_HEIGHT) + (houseWidth * HOUSE_HEIGHT)) * PLYWOOD_PRICE; + plywoodCost = plywoodCost + ((houseDepth * HOUSE_HEIGHT) + (houseDepth * HOUSE_HEIGHT)) * PLYWOOD_PRICE; + plywoodCost = plywoodCost + (houseWidth * houseDepth) * PLYWOOD_PRICE; + // Calculate the 2x4 cost(using the equation provided on BBLearn) + twoByFourCost = (NUM_2x4_PER_FOOT * houseWidth); + twoByFourCost = twoByFourCost + (NUM_2x4_PER_FOOT * houseDepth); + twoByFourCost = twoByFourCost * TWO_BY_FOUR_PRICE; + // Calculate the drywall cost(using the equation provided on BBLearn) + drywallCost = (((houseWidth * HOUSE_HEIGHT)*2) + ((houseDepth * HOUSE_HEIGHT)*2)) * DRYWALL_PRICE; + // Calculate the Total Estimate cost(add up using the previous values) + totalEstimate = roofingCost + plywoodCost + twoByFourCost + drywallCost; + + // Print a blank line for formatting. + printEndline(); + + // Print a dividing line, use the printTopLine(). + printTopLine(); + printEndline(); + + // Print the table header. (Description, centered; Value, Centered; Unit, centered.) + printCharacter(PIPE); + printStringJustified("Description", DESCRIPTION_WIDTH, "CENTER"); + printCharacter(PIPE); + printStringJustified("Value", VALUE_WIDTH, "CENTER"); + printCharacter(PIPE); + printStringJustified("Unit", UNIT_WIDTH, "CENTER"); + printCharacter(PIPE); + printEndline(); + + // Divider for the table header and data, using '='. uses printHeavyDividedLine() + printHeavyDividedLine(); + printEndline(); + + // Printed output of the desired area + printCharacter(PIPE); + printStringJustified(" Desired Area", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printIntegerJustified(desiredArea, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" sq ft", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the actual area, using the houseWidth * houseDepth + printCharacter(PIPE); + printStringJustified(" Actual Area", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printIntegerJustified(actualArea, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" sq ft", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the house's width + printCharacter(PIPE); + printStringJustified(" House Width", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printIntegerJustified(houseWidth, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" feet", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the house's depth + printCharacter(PIPE); + printStringJustified(" House Depth", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printIntegerJustified(houseDepth, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" feet", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the roofing cost + printCharacter(PIPE); + printStringJustified(" Roofing Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printDoubleJustified(roofingCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the plywood cost + printCharacter(PIPE); + printStringJustified(" Plywood Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printDoubleJustified(plywoodCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the 2x4 cost + printCharacter(PIPE); + printStringJustified(" 2 X 4 Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printDoubleJustified(twoByFourCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the drywall cost + printCharacter(PIPE); + printStringJustified(" Drywall Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printDoubleJustified(drywallCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // Printed output of the Total Estimate + printCharacter(PIPE); + printStringJustified(" Total Estimate", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(PIPE); + printDoubleJustified(totalEstimate, PRECISION, VALUE_WIDTH, "RIGHT"); + printCharacter(PIPE); + printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(PIPE); + printEndline(); + printLightDividedLine(); + printEndline(); + + // End the table + + // Print 2 blank lines for formatting. + printEndlines(2); + // Print end program + printString("End Program"); + // Print a blank line for formatting. + printEndline(); + + // return program success + return 0; + } + + +// supporting functions + +double findAbsolute( int value ) + { + // test for value less than negative precision + if( value < -ABSOLUTE_BASE ) + { + // return negated value + return -value; + } + + // otherwise, assume positive value, return unchanged + return value; + } + +double findSquareRoot( double value ) + { + // initialize function/variables + double testSquare, mid, high = value, low = 0; + + // set initial mid value + mid = ( high + low ) / 2.0; + + // set initial test square value + testSquare = mid * mid; + + // loop while difference between test square and value + // is greater than desired precision + // function: findAbsolute + while( findAbsolute( testSquare - value ) > SQUARE_ROOT_PRECISION ) + { + // test for calculated value too high + if( testSquare > value ) + { + // change low to the mid value + high = mid; + } + + // otherwise, assume value was too low + else + { + low = mid; + } + + // calculate new mid + mid = ( high + low ) / 2.0; + + // calculate new test square + testSquare = mid * mid; + } + + // return estimated square root + return mid; + } + +void printDividedLine( char thickness ) + { + // print first pipe + // function: printCharacter + printCharacter( PIPE ); + + // print description line + // function: printCharacters + printCharacters( DESCRIPTION_WIDTH, thickness ); + + // print divider pipe + // function: printCharacter + printCharacter( PIPE ); + + // print description line + // function: printCharacters + printCharacters( VALUE_WIDTH, thickness ); + + // print divider pipe + // function: printCharacter + printCharacter( PIPE ); + + // print description line + // function: printCharacters + printCharacters( UNIT_WIDTH, thickness ); + + // print last pipe + // function: printCharacter + printCharacter( PIPE ); + } + +void printHeavyDividedLine() + { + // call print divided line with heavy character + // function: printDividedLine + printDividedLine( THICK_LINE ); + } + +void printLightDividedLine() + { + // call print divided line with heavy character + // function: printDividedLine + printDividedLine( THIN_LINE ); + } + +void printTopLine() + { + // print top line + // function: printCharacters + printCharacters( TABLE_WIDTH, THIN_LINE ); + } + diff --git a/PA02-0914/Project_2_PRG b/PA02-0914/Project_2_PRG new file mode 100644 index 0000000000000000000000000000000000000000..0b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kfi5lZLs;E`?f&qWrFI<(4 zbu~?1!&m8QH1s(|W4)}7Bygrs#=*`gdNjT=5>*0KlLF2t!JCy7f%*ndl_9)t&uU+d zXEkC$M4TeV3u6ftiQD2dAqtd1p`s!)wwXfc2fKi=SG_Ce{eQQ0{UboE=YERXTszDg^2&Fn|Ngw8v zg{qHz%Hr9NXYvJN5nr1horR;DFp^{OK&Zoq?}`J|an!n%p)dk~vW%ZM(piIUwT?TQ z7@|2G^haxgept7fF^P#rPqpD&>#C{oHMqQ4s8wvf&mFuZ8TOjc{D{fl=AY4+WYUx!LoJS4*_E0mbkHiTX&e7UZhM^+Lu=uxQ zP3J4f|BBMSTpm8S{ga9JO_=h&oEA%6&J(>1AKD9Jd){ARI**hr376BXMEAE=`;-P^ z>dev}dzNE0s&7xm_|Fb( zMTYu>?RnpcX`fc)`t9xihPJQNdb~fy^ihjF-Fn*X?*@-z!uz?nrBX>#eY>ieWBWe| ziPhez?U-&iEmg(_FYd9~Kcp3yvcC+&Wv1V^+4J)O(_e6f8o*W*58Lc{|C}kk=VVRP zSJw1X6sY~&fBam;bjUW~?DhY`W^X^&lh5(wI_>p8W3xB+_w)_A+h)LVW4z~)DZ+>5 z5GCH<;qyN2`dns8`$Z0X*q-+bhgJ|;X1u9Vrp)$lKtN-U?Rj63&r==L@#FEyb{xn1 zVM{7(&-;%9`oXIdGHYUcrY9k^+KYOvU7;u!HP@U!Z2tiSR(pOPuh;hMr`?{*A0b0n z>_0y*-BO`6xE@tfb#b2PS$wGeaw=F7+w(pGi%6G}m6~H$iRAyC6{>J}s-koqD#M5U o;q{m12m7ux)&Ke%6 + +// global constants + +// constant for end of c-string null character +#define CARRIAGE_RETURN_CHAR '\r' + +//constant for a COLON +#define COLON ':' + +//constant for a COMMA +#define COMMA ',' + +//Constant to print a dash +#define DASH '-' + +// constant for huge string length +#define HUGE_STR_LEN 256 + +// constant for end of c-string null character +#define NEWLINE_CHAR '\n' + +// constant for small string length +#define MIN_STR_LEN 32 + +// constant for maximum string length +#define MAX_STR_LEN 128 + +// constant for end of c-string null character +#define NULL_CHAR '\0' + +//Constant for printing a pipe +#define PIPE '|' + +//Constant for a period +#define PERIOD '.' + +//Constant for PRECISION +#define PRECISION 2 + +// constant for space character +#define SPACE ' ' + +// constant for standard string length +#define STD_STR_LEN 64 + +#endif // STANDARD_CONSTANTS + +