PA04 Initialization
++ Project 4 Files ++ Makefile for Project 4
This commit is contained in:
parent
82bf795c15
commit
6f74d5bb92
29 changed files with 445293 additions and 0 deletions
135
PA04-0927/BasicUtilities.c
Normal file
135
PA04-0927/BasicUtilities.c
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
// header file
|
||||
#include "BasicUtilities.h"
|
||||
|
||||
/*
|
||||
Name: compareStrings
|
||||
Process: compares text quantities (c-style strings) without case sensitivity
|
||||
with the following outcomes:
|
||||
- for equal sized strings, if the first parameter is alphabetically
|
||||
greater than the second parameter, returns positive number
|
||||
- for equal sized strings, if the first parameter is alphabetically
|
||||
less than the second parameter, returns negative number
|
||||
- for equal sized strings, if the first parameter is alphabetically
|
||||
equal to the second parameter, returns zero
|
||||
- for unequal sized strings with common letters up to the length
|
||||
of the shortest string, returns difference in the length
|
||||
of the strings
|
||||
Function input/parameters: strings to be compared(const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: processed result as specified (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: getStringLength, toLowerCaseLetter
|
||||
*/
|
||||
int compareStrings( const char *leftStr, const char *rightStr )
|
||||
{
|
||||
int diff, index = 0;
|
||||
int leftStrLen = getStringLength( leftStr );
|
||||
int rightStrLen = getStringLength( rightStr );
|
||||
|
||||
while( index < leftStrLen && index < rightStrLen )
|
||||
{
|
||||
diff = toLowerCaseLetter( leftStr[ index ] )
|
||||
- toLowerCaseLetter( rightStr[ index ] );
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
return diff;
|
||||
}
|
||||
|
||||
index = index + 1;
|
||||
}
|
||||
|
||||
return leftStrLen - rightStrLen;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: copyString
|
||||
Process: copies characters from source string to destination string
|
||||
up to NULL_CHAR
|
||||
Function input/parameters: source string (const char *)
|
||||
Function output/parameters: destination string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
void copyString( char *destStr, const char *srcStr )
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
while( srcStr[ index ] != NULL_CHAR )
|
||||
{
|
||||
destStr[ index ] = srcStr[ index ];
|
||||
|
||||
index++;
|
||||
|
||||
destStr[ index ] = NULL_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Name: getStringLength
|
||||
Process: finds the number of characters in (length of) a c-style string
|
||||
Function input/parameters: string to be processed (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: length of string (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
int getStringLength( const char *str )
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
while( str[ index ] != NULL_CHAR )
|
||||
{
|
||||
index = index + 1;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: printSpaces
|
||||
Process: recursively prints the given number of spaces to the screen
|
||||
Function input/parameters: number of spaces to print (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: spaces printed as specified
|
||||
Dependencies: none
|
||||
*/
|
||||
void printSpaces( int numSpaces )
|
||||
{
|
||||
if( numSpaces > 0 )
|
||||
{
|
||||
printf( "%c", SPACE );
|
||||
|
||||
printSpaces( numSpaces - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Name: toLowerCaseLetter
|
||||
Process: if character is upper case letter,
|
||||
returns associated lower case letter,
|
||||
otherwise has no effect
|
||||
Function input/parameters: character to be processed (char)
|
||||
Function output/parameters: none
|
||||
Function output/returned: character processed as specified (char)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
char toLowerCaseLetter( char testChar )
|
||||
{
|
||||
if( testChar >= 'A' && testChar <= 'Z' )
|
||||
{
|
||||
return testChar - 'A' + 'a';
|
||||
}
|
||||
|
||||
return testChar;
|
||||
}
|
||||
|
||||
|
||||
83
PA04-0927/BasicUtilities.h
Normal file
83
PA04-0927/BasicUtilities.h
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#ifndef BASIC_UTILITIES_H
|
||||
#define BASIC_UTILITIES_H
|
||||
|
||||
// header files
|
||||
#include <stdio.h>
|
||||
#include "StandardConstants.h"
|
||||
|
||||
/*
|
||||
Name: compareStrings
|
||||
Process: compares text quantities (c-style strings) without case sensitivity
|
||||
with the following outcomes:
|
||||
- for equal sized strings, if the first parameter is alphabetically
|
||||
greater than the second parameter, returns positive number
|
||||
- for equal sized strings, if the first parameter is alphabetically
|
||||
less than the second parameter, returns negative number
|
||||
- for equal sized strings, if the first parameter is alphabetically
|
||||
equal to the second parameter, returns zero
|
||||
- for unequal sized strings with common letters up to the length
|
||||
of the shortest string, returns difference in the length
|
||||
of the strings
|
||||
Function input/parameters: strings to be compared(const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: processed result as specified (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: getStringLength, toLowerCaseLetter
|
||||
*/
|
||||
int compareStrings( const char *leftStr, const char *rightStr );
|
||||
|
||||
/*
|
||||
Name: copyString
|
||||
Process: copies characters from source string to destination string
|
||||
up to NULL_CHAR
|
||||
Function input/parameters: source string (const char *)
|
||||
Function output/parameters: destination string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
void copyString( char *destStr, const char *srcStr );
|
||||
|
||||
/*
|
||||
Name: getStringLength
|
||||
Process: finds the number of characters in (length of) a c-style string
|
||||
Function input/parameters: string to be processed (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: length of string (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
int getStringLength( const char *str );
|
||||
|
||||
/*
|
||||
Name: printSpaces
|
||||
Process: recursively prints the given number of spaces to the screen
|
||||
Function input/parameters: number of spaces to print (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: spaces printed as specified
|
||||
Dependencies: none
|
||||
*/
|
||||
void printSpaces( int numSpaces );
|
||||
|
||||
/*
|
||||
Name: toLowerCaseLetter
|
||||
Process: if character is upper case letter,
|
||||
returns associated lower case letter,
|
||||
otherwise has no effect
|
||||
Function input/parameters: character to be processed (char)
|
||||
Function output/parameters: none
|
||||
Function output/returned: character processed as specified (char)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
char toLowerCaseLetter( char testChar );
|
||||
|
||||
|
||||
#endif // BASIC_UTILITIES_H
|
||||
|
||||
590
PA04-0927/Console_IO_Utility.c
Normal file
590
PA04-0927/Console_IO_Utility.c
Normal file
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
289
PA04-0927/Console_IO_Utility.h
Normal file
289
PA04-0927/Console_IO_Utility.h
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
// Preprocessor directive
|
||||
#ifndef CONSOLE_IO_UTILITY_H
|
||||
#define CONSOLE_IO_UTILITY_H
|
||||
|
||||
//Header Files
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
139
PA04-0927/CourseUtilities.c
Normal file
139
PA04-0927/CourseUtilities.c
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
// header file
|
||||
#include "CourseUtilities.h"
|
||||
#include "BasicUtilities.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// function implementations
|
||||
|
||||
/*
|
||||
Name: addCourseWithData
|
||||
Process: adds course data struct to array and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: course data array (CourseArrayType *),
|
||||
course name (const char *),
|
||||
course size (int), course availability (bool)
|
||||
Function output/parameters: updated course data array (CourseArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with copyString
|
||||
*/
|
||||
bool addCourseWithData( CourseArrayType *courseData, const char *courseName,
|
||||
int courseSize, bool courseAvailability )
|
||||
{
|
||||
if( courseData->size < courseData->capacity )
|
||||
{
|
||||
copyString( courseData->array[ courseData->size ].courseName,
|
||||
courseName );
|
||||
courseData->array[ courseData->size ].size = courseSize;
|
||||
|
||||
courseData->array[ courseData->size ].available = courseAvailability;
|
||||
|
||||
courseData->size = courseData->size + 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: addCourseWithCourse
|
||||
Process: adds course data to array and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: source course data array (const CourseArrayType *)
|
||||
Function output/parameters: destination course data array (CourseArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: addCourseWithData - one line of code
|
||||
*/
|
||||
void addCourseWithCourse( CourseArrayType *destCourse,
|
||||
const CourseDataType srcCourse )
|
||||
{
|
||||
addCourseWithData( destCourse, srcCourse.courseName,
|
||||
srcCourse.size, srcCourse.available );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: clearCourseArray
|
||||
Process: frees CourseArrayType memory, along with array memory, returns NULL
|
||||
Function input/parameters: course array structure (CourseArrayType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: NULL (CourseArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: free
|
||||
*/
|
||||
CourseArrayType *clearCourseArray( CourseArrayType *courseData )
|
||||
{
|
||||
free( courseData->array );
|
||||
|
||||
free( courseData );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: createCourseArray
|
||||
Process: allocates CourseArrayType memory, along with array memory,
|
||||
returns pointer to new course
|
||||
Function input/parameters: initial capacity
|
||||
Function output/parameters: none
|
||||
Function output/returned: created course (CourseArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: malloc, with keyword sizeof
|
||||
*/
|
||||
CourseArrayType *createCourseArray( int initCapacity )
|
||||
{
|
||||
CourseArrayType *newCourse
|
||||
= (CourseArrayType *)malloc( sizeof( CourseArrayType ) );
|
||||
|
||||
newCourse->array
|
||||
= (CourseDataType *)malloc( initCapacity * sizeof( CourseDataType ) );
|
||||
|
||||
newCourse->capacity = initCapacity;
|
||||
|
||||
newCourse->size = 0;
|
||||
|
||||
return newCourse;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: deepCopyCourse
|
||||
Process: copies source course data into destination course
|
||||
Function input/parameters: source course data (const CourseDataType)
|
||||
Function output/parameters: destination course data (CourseDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including copyString
|
||||
*/
|
||||
void deepCopyCourse( CourseDataType *destCourse,
|
||||
const CourseDataType srcCourse )
|
||||
{
|
||||
copyString( destCourse->courseName, srcCourse.courseName );
|
||||
destCourse->size = srcCourse.size;
|
||||
destCourse->available = srcCourse.available;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: setCourseDataString
|
||||
Process: course data into string, in format:
|
||||
"Course Name: <course name>, Course Size: <course size>"
|
||||
Function input/parameters: course data (const CourseDataType)
|
||||
Function output/parameters: loaded c-style string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: sprintf
|
||||
*/
|
||||
void setCourseDataString( char *dataStr, const CourseDataType courseData )
|
||||
{
|
||||
sprintf( dataStr, "Course Name: %s, Course Size: %3d",
|
||||
courseData.courseName, courseData.size );
|
||||
}
|
||||
|
||||
|
||||
108
PA04-0927/CourseUtilities.h
Normal file
108
PA04-0927/CourseUtilities.h
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#ifndef COURSE_UTILITIES_H
|
||||
#define COURSE_UTILITIES_H
|
||||
|
||||
// header files
|
||||
#include <string.h>
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// data structure
|
||||
typedef struct CourseDataStruct
|
||||
{
|
||||
char courseName[ TINY_STR_LEN ];
|
||||
int size;
|
||||
bool available;
|
||||
} CourseDataType;
|
||||
|
||||
typedef struct CourseArrayStruct
|
||||
{
|
||||
CourseDataType *array;
|
||||
|
||||
int size, capacity;
|
||||
} CourseArrayType;
|
||||
|
||||
// function specifications/prototypes
|
||||
|
||||
/*
|
||||
Name: addCourseWithData
|
||||
Process: adds course data struct to array and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: course data array (CourseArrayType *),
|
||||
course name (const char *),
|
||||
course size (int), course availability (bool)
|
||||
Function output/parameters: updated course data array (CourseArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with copyString
|
||||
*/
|
||||
bool addCourseWithData( CourseArrayType *courseData, const char *courseName,
|
||||
int courseSize, bool courseAvailability );
|
||||
|
||||
/*
|
||||
Name: addCourseWithCourse
|
||||
Process: adds course data to array and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: source course data array (const CourseArrayType *)
|
||||
Function output/parameters: destination course data array (CourseArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: addCourseWithData - one line of code
|
||||
*/
|
||||
void addCourseWithCourse( CourseArrayType *destCourse,
|
||||
const CourseDataType srcCourse );
|
||||
|
||||
/*
|
||||
Name: clearCourseArray
|
||||
Process: frees CourseArrayType memory, along with array memory, returns NULL
|
||||
Function input/parameters: course array structure (CourseArrayType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: NULL (CourseArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: free
|
||||
*/
|
||||
CourseArrayType *clearCourseArray( CourseArrayType *courseData );
|
||||
|
||||
/*
|
||||
Name: createCourseArray
|
||||
Process: allocates CourseArrayType memory, along with array memory,
|
||||
returns pointer to new course
|
||||
Function input/parameters: initial capacity
|
||||
Function output/parameters: none
|
||||
Function output/returned: created course (CourseArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: malloc, with keyword sizeof
|
||||
*/
|
||||
CourseArrayType *createCourseArray( int initCapacity );
|
||||
|
||||
/*
|
||||
Name: deepCopyCourse
|
||||
Process: copies source course data into destination course
|
||||
Function input/parameters: source course data (const CourseDataType)
|
||||
Function output/parameters: destination course data (CourseDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including strcpy
|
||||
*/
|
||||
void deepCopyCourse( CourseDataType *destCourse,
|
||||
const CourseDataType srcCourse );
|
||||
|
||||
/*
|
||||
Name: setCourseDataString
|
||||
Process: course data into string, in format:
|
||||
"Course Name: <course name>, Course Size: <course size>"
|
||||
Function input/parameters: course data (const CourseDataType)
|
||||
Function output/parameters: loaded c-style string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: sprintf
|
||||
*/
|
||||
void setCourseDataString( char *dataStr, const CourseDataType courseData );
|
||||
|
||||
|
||||
#endif // COURSE_UTILITIES_H
|
||||
|
||||
717
PA04-0927/File_Input_Utility.c
Normal file
717
PA04-0927/File_Input_Utility.c
Normal file
|
|
@ -0,0 +1,717 @@
|
|||
/*
|
||||
Formatted file input utility, function implementations
|
||||
|
||||
Copyright (c) 2021 by Michael E. Leverington
|
||||
|
||||
Code is free for use in whole or in part and may be modified for other
|
||||
non-commercial use as long as the above copyright statement is included.
|
||||
*/
|
||||
|
||||
// header files
|
||||
#include "File_Input_Utility.h"
|
||||
#include <stdlib.h> //////////////////////////test
|
||||
|
||||
// local global constants, used only in this file
|
||||
|
||||
// dummy file pointer for accessInputFilePointer
|
||||
const FILE *DUMMY_INPUT_FILE_PTR = NULL;
|
||||
|
||||
// dummy Boolean for accessEndOfInputFileFlag, accessOpenFlag
|
||||
const char DUMMY_INPUT_FLAG = false;
|
||||
|
||||
// control code for accessing file pointer, accessInputFilePointer
|
||||
const int GET_INPUT_FILE_PTR = 3003;
|
||||
|
||||
// control code for accessing flag value,
|
||||
// accessEndOfInputFileFlag, accessOpenFlag
|
||||
const int GET_INPUT_FLAG = 2002;
|
||||
|
||||
// control code for setting file pointer, accessInputFilePointer
|
||||
const int SET_INPUT_FILE_PTR = 4004;
|
||||
|
||||
// control code for setting flag value, accessEndOfInputFileFlag,
|
||||
// accessOpenFlag
|
||||
const int SET_INPUT_FLAG = 1001;
|
||||
|
||||
|
||||
/*
|
||||
Name: accessEndOfInputFileFlag
|
||||
process: allows accessing or modifying end of file flag state;
|
||||
note: flag is maintained (static) value initialized to false
|
||||
Function input/parameters: control code (int), flag state (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of flag state (bool)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: none
|
||||
*/
|
||||
bool accessEndOfInputFileFlag( int ctrlCode, bool setFlag )
|
||||
{
|
||||
// initialize end of file flag to false
|
||||
static bool endOfFileFlag = false;
|
||||
|
||||
// test for set flag
|
||||
if( ctrlCode == SET_INPUT_FLAG )
|
||||
{
|
||||
// set flag to given state
|
||||
endOfFileFlag = setFlag;
|
||||
}
|
||||
|
||||
// return flag state
|
||||
return endOfFileFlag;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: accessInputFilePointer
|
||||
process: allows setting or accessing file pointer;
|
||||
note: pointer is maintained (static) value initialized to NULL
|
||||
Function input/parameters: control code (int), file pointer (FILE *)
|
||||
DUMMY_INPUT_FILE_PTR used
|
||||
if not setting file pointer
|
||||
Function output/parameters: none
|
||||
Function output/returned: file pointer (FILE *)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: none
|
||||
*/
|
||||
FILE *accessInputFilePointer( int ctrlCode, const FILE *filePtr )
|
||||
{
|
||||
// initialize file pointer to null
|
||||
static FILE *filePointer = NULL;
|
||||
|
||||
// check for set new pointer
|
||||
if( ctrlCode == SET_INPUT_FILE_PTR )
|
||||
{
|
||||
// set file pointer to parameter
|
||||
filePointer = (FILE *)filePtr;
|
||||
}
|
||||
|
||||
// return file pointer
|
||||
return filePointer;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: checkForEndOfInputFile
|
||||
process: checks to see if end of file flag has been encountered,
|
||||
returns true if EOF has been encountered, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified test (bool)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: accessEndOfInputFileFlag
|
||||
*/
|
||||
bool checkForEndOfInputFile()
|
||||
{
|
||||
// return access to end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
return accessEndOfInputFileFlag( GET_INPUT_FLAG, DUMMY_INPUT_FLAG );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: checkForInputFileOpen
|
||||
process: checks to see if file is currently open
|
||||
returns true if file pointer not null, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified test (bool)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: accessInputFilePointer
|
||||
*/
|
||||
bool checkForInputFileOpen()
|
||||
{
|
||||
// return access to end of file flag
|
||||
// function: accessInputFilePointer
|
||||
return accessInputFilePointer( GET_INPUT_FLAG,
|
||||
DUMMY_INPUT_FILE_PTR ) != NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: clearLeadingWhiteSpace
|
||||
process: captures non printable characters,
|
||||
and space if flag set,
|
||||
returns first non white space value found as integer
|
||||
Function input/parameters: file pointer (FILE *), clear space flag (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: first non WS character as integer
|
||||
Device input/file: value captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: fgetc
|
||||
*/
|
||||
int clearLeadingWhiteSpace( FILE *filePtr, bool clearSpace )
|
||||
{
|
||||
// initialize character input value
|
||||
// function: fgetc
|
||||
int charInt = fgetc( filePtr );
|
||||
|
||||
while(
|
||||
// continue if not at end of file
|
||||
( charInt != EOF )
|
||||
|
||||
// AND
|
||||
// continue if character is non printable
|
||||
&& ( ( charInt < (int)SPACE || charInt > (int)HIGHEST_PRINTABLE_CHAR )
|
||||
|
||||
// OR
|
||||
// continue if clear space flag set and space is found
|
||||
|| ( clearSpace && charInt == SPACE ) )
|
||||
)
|
||||
{
|
||||
// capture next character
|
||||
// function: fgetc
|
||||
charInt = fgetc( filePtr );
|
||||
}
|
||||
|
||||
// return input value as character
|
||||
return (char)charInt;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: closeInputFile
|
||||
process: closes input file, returns true if successful, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/file: file closed
|
||||
Device output/monitor: none
|
||||
Dependencies: accessInputFilePointer, fclose, accessEndOfInputFileFlag
|
||||
*/
|
||||
bool closeInputFile()
|
||||
{
|
||||
// set local file pointer to working file pointer
|
||||
// function: accessInputFilePointer
|
||||
FILE *filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// check for valid file pointer
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// close file
|
||||
fclose( filePtr );
|
||||
|
||||
// set pointer to NULL
|
||||
// function: accessInputFilePointer
|
||||
accessInputFilePointer( SET_INPUT_FILE_PTR, NULL );
|
||||
|
||||
// set end of file flag to false
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, false );
|
||||
|
||||
// return successful operation
|
||||
return true;
|
||||
}
|
||||
|
||||
// return failed operation
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: openInputFile
|
||||
process: opens input file, sets file pointer and unsets end of file flag,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: file name (c-string)
|
||||
Function output/parameters: none
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/file: file opened
|
||||
Device output/monitor: none
|
||||
Dependencies: fopen, accessInputFilePointer, accessEndOfInputFileFlag
|
||||
*/
|
||||
bool openInputFile( const char *fileName )
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr = NULL;
|
||||
char readOnlyCharacter[] = "r";
|
||||
|
||||
// check for file not open
|
||||
// function: checkForInputFileOpen
|
||||
if( !checkForInputFileOpen() )
|
||||
{
|
||||
// open file
|
||||
// function: fopen
|
||||
filePtr = fopen( fileName, readOnlyCharacter );
|
||||
|
||||
// check for success of file open
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// set pointer in access function
|
||||
// function: accessInputFilePointer
|
||||
accessInputFilePointer( SET_INPUT_FILE_PTR, filePtr );
|
||||
|
||||
// reset end of file flag, if needed
|
||||
// accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, false );
|
||||
|
||||
// return operation success
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// end of file not previously opened block
|
||||
|
||||
// return operation failure
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readCharacterFromFile
|
||||
process: ignores leading unprintable characters, including space,
|
||||
captures first printable character
|
||||
Function input/parameters: allow space capture (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: character found if successful, ZERO_CHAR otherwise
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readCharacterFromFileConfigured
|
||||
*/
|
||||
char readCharacterFromFile()
|
||||
{
|
||||
// initialize parameter to not allow space
|
||||
bool noSpaceCapture = false;
|
||||
|
||||
// capture character, return
|
||||
// function: getCharFromFileConfigured
|
||||
return readCharacterFromFileConfigured( noSpaceCapture );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readCharacterFromFileConfigured
|
||||
process: ignores leading unprintable characters,
|
||||
captures first printable character,
|
||||
including space if allowed
|
||||
Function input/parameters: allow space capture (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: character found if successful, ZERO_CHAR otherwise
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, clearLeadingWhiteSpace,
|
||||
accessEndOfInputFileFlag
|
||||
*/
|
||||
char readCharacterFromFileConfigured( bool captureSpace )
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr;
|
||||
int intChar = ZERO_CHAR;
|
||||
|
||||
// check for file open and data accessible
|
||||
// function: checkForInputFileOpen, checkForEndOfInputFile
|
||||
if( checkForInputFileOpen() && !checkForEndOfInputFile() )
|
||||
{
|
||||
// set file pointer
|
||||
// function: accessInputFilePointer
|
||||
filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// get character
|
||||
// function: clearLeadingWhiteSpace
|
||||
intChar = clearLeadingWhiteSpace( filePtr, !captureSpace );
|
||||
|
||||
// check for end of file found
|
||||
if( intChar == EOF )
|
||||
{
|
||||
// set end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, true );
|
||||
|
||||
// set return value to zero
|
||||
intChar = ZERO_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
// return value as character
|
||||
return intChar;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readDoubleFromFile
|
||||
process: ignores leading unprintable characters,
|
||||
captures first contiguous double value
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: double value found if successful (double)
|
||||
Device input/file: double value captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fscanf, accessEndOfInputFileFlag
|
||||
*/
|
||||
double readDoubleFromFile()
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr = NULL;
|
||||
int fscanfReturn = EOF;
|
||||
double doubleVal = ZERO_VALUE;
|
||||
|
||||
// check for file open and data accessible
|
||||
// function: checkForInputFileOpen, checkForEndOfInputFile
|
||||
if( checkForInputFileOpen() && !checkForEndOfInputFile() )
|
||||
{
|
||||
// set file pointer
|
||||
// function: accessInputFilePointer
|
||||
filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// get double value
|
||||
// function: fscanf
|
||||
fscanfReturn = fscanf( filePtr, "%lf", &doubleVal );
|
||||
|
||||
// check for end of file found
|
||||
if( fscanfReturn == EOF )
|
||||
{
|
||||
// set end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, true );
|
||||
|
||||
// set return value to zero
|
||||
doubleVal = ZERO_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
// return acquired value
|
||||
return doubleVal;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readIntegerFromFile
|
||||
process: ignores leading unprintable characters,
|
||||
captures first contiguous integer
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: integer found if successful, ZERO_VALUE otherwise
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fscanf, accessEndOfInputFileFlag
|
||||
*/
|
||||
int readIntegerFromFile()
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr = NULL;
|
||||
int fscanfReturn = EOF;
|
||||
int intVal = ZERO_VALUE;
|
||||
|
||||
// check for file open and data accessible
|
||||
// function: checkForInputFileOpen, checkForEndOfInputFile
|
||||
if( checkForInputFileOpen() && !checkForEndOfInputFile() )
|
||||
{
|
||||
// set file pointer
|
||||
// function: accessInputFilePointer
|
||||
filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// get integer value
|
||||
// function: fscanf
|
||||
fscanfReturn = fscanf( filePtr, "%d", &intVal );
|
||||
|
||||
// check for end of file found
|
||||
if( fscanfReturn == EOF )
|
||||
{
|
||||
// set end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, true );
|
||||
|
||||
// set return value to zero
|
||||
intVal = ZERO_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
// return acquired value
|
||||
return intVal;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readLongFromFile
|
||||
process: ignores leading unprintable characters,
|
||||
captures first contiguous long int
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: long integer found if successful,
|
||||
ZERO_VALUE otherwise
|
||||
Device input/file: long value captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fscanf, accessEndOfInputFileFlag
|
||||
*/
|
||||
long readLongFromFile()
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr = NULL;
|
||||
int fscanfReturn = EOF;
|
||||
long longVal = ZERO_VALUE;
|
||||
|
||||
// check for file open and data accessible
|
||||
// function: checkForInputFileOpen, checkForEndOfInputFile
|
||||
if( checkForInputFileOpen() && !checkForEndOfInputFile() )
|
||||
{
|
||||
// set file pointer
|
||||
// function: accessInputFilePointer
|
||||
filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// get long value
|
||||
// function: fscanf
|
||||
fscanfReturn = fscanf( filePtr, "%ld", &longVal );
|
||||
|
||||
// check for end of file found
|
||||
if( fscanfReturn == EOF )
|
||||
{
|
||||
// set end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, true );
|
||||
|
||||
// set return value to zero
|
||||
longVal = ZERO_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
// return acquired value
|
||||
return longVal;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readRawCharFromFile
|
||||
process: captures first character in file stream including non-printable
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: character found if successful, ZERO_CHAR otherwise
|
||||
Device input/file: character captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fgetc, accessEndOfInputFileFlag
|
||||
*/
|
||||
char readRawCharFromFile()
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr = NULL;
|
||||
int intChar = (int)ZERO_CHAR;
|
||||
|
||||
// check for file open and data accessible
|
||||
// function: checkForInputFileOpen, checkForEndOfInputFile
|
||||
if( checkForInputFileOpen() && !checkForEndOfInputFile() )
|
||||
{
|
||||
// set file pointer
|
||||
// function: accessInputFilePointer
|
||||
filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// get character
|
||||
// function: fgetc
|
||||
intChar = fgetc( filePtr );
|
||||
|
||||
// check for end of file found
|
||||
if( intChar == EOF )
|
||||
{
|
||||
// set end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, true );
|
||||
|
||||
// set return value to zero
|
||||
intChar = (int)ZERO_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
// return acquired value
|
||||
return (char)intChar;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readStringConfiguredFromFile
|
||||
Process: captures string with options:
|
||||
- clear leading non printable (bool)
|
||||
- clear leading space character (bool)
|
||||
- adquires characters up to any non-printable (bool)
|
||||
- adquires characters up to any printable delimiter (char)
|
||||
- use constant NON_PRINTABLE if no delimiter
|
||||
- also stops capture when full (MAX_STR_LEN)
|
||||
Note: This function consumes the last character input,
|
||||
including the space, delimiter, or non-printable character
|
||||
Function input/parameters: see process above
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
clearLeadingWhiteSpace, fgetc, accessEndOfInputFileFlag
|
||||
*/
|
||||
bool readStringConfiguredFromFile( bool clearLeadingNonPrintable,
|
||||
bool clearLeadingSpace,
|
||||
bool stopAtNonPrintable,
|
||||
char delimiter,
|
||||
char *capturedString )
|
||||
{
|
||||
// initialize variables
|
||||
int intChar = EOF, index = 0;
|
||||
FILE *filePtr = NULL;
|
||||
|
||||
// initialize output string
|
||||
capturedString[ index ] = NULL_CHAR;
|
||||
|
||||
// check for file open and data accessible
|
||||
// function: checkForInputFileOpen, checkForEndOfInputFile
|
||||
if( checkForInputFileOpen() && !checkForEndOfInputFile() )
|
||||
{
|
||||
// get file pointer
|
||||
// function: accessFilePtr
|
||||
filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR,
|
||||
DUMMY_INPUT_FILE_PTR );
|
||||
|
||||
// check for clearing non printable
|
||||
if( clearLeadingNonPrintable )
|
||||
{
|
||||
// clear leading white space, with clear space character flag
|
||||
// function: clearLeadingWhiteSpace
|
||||
intChar = clearLeadingWhiteSpace( filePtr, clearLeadingSpace );
|
||||
}
|
||||
|
||||
// otherwise, assume non printable not cleared
|
||||
else
|
||||
{
|
||||
// get first character
|
||||
// function: fgetc
|
||||
intChar = fgetc( filePtr );
|
||||
|
||||
// check for clearing spaces
|
||||
if( clearLeadingSpace )
|
||||
{
|
||||
// loop while spaces found and end of file not found
|
||||
while( intChar != EOF && intChar == (int)SPACE )
|
||||
{
|
||||
// capture new character
|
||||
// function: fgetc
|
||||
intChar = fgetc( filePtr );
|
||||
}
|
||||
}
|
||||
} // end leading character clearing process
|
||||
|
||||
// check for end of file found
|
||||
if( intChar == EOF )
|
||||
{
|
||||
// set end of file flag
|
||||
// function: accessEndOfInputFileFlag
|
||||
accessEndOfInputFileFlag( SET_INPUT_FLAG, true );
|
||||
|
||||
// return failed operation
|
||||
return false;
|
||||
}
|
||||
|
||||
// loop to capture input
|
||||
while(
|
||||
// continues if not at end of file and max string length not reached
|
||||
( intChar != EOF && index < MAX_STR_LEN - 1 )
|
||||
|
||||
// AND
|
||||
// continues if not printable flag set and characters are printable
|
||||
// OR not printable flag not set
|
||||
&& ( ( stopAtNonPrintable && intChar >= (int)SPACE )
|
||||
|| ( !stopAtNonPrintable ) )
|
||||
|
||||
// AND
|
||||
// continues if specified delimiter is not found
|
||||
&& ( intChar != (char)delimiter )
|
||||
)
|
||||
{
|
||||
// place character in array element
|
||||
capturedString[ index ] = (char)intChar;
|
||||
|
||||
// increment array index
|
||||
index++;
|
||||
|
||||
// set next element to null character / end of c-string
|
||||
capturedString[ index ] = NULL_CHAR;
|
||||
|
||||
// get next character as integer
|
||||
// function: fgetc
|
||||
intChar = fgetc( filePtr );
|
||||
}
|
||||
// end loop
|
||||
|
||||
// return successful operation
|
||||
return true;
|
||||
}
|
||||
// end of open file and accessible data block
|
||||
|
||||
return false; // temporary stub return
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readStringSegmentFromFile
|
||||
process: ignores leading white space, including space character,
|
||||
captures series of characters up to first space,
|
||||
or end of line, or full string
|
||||
Function input/parameters: none
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readStringConfigured with appropriate parameters
|
||||
*/
|
||||
bool readStringSegmentFromFile( char *capturedString )
|
||||
{
|
||||
// initialize variables
|
||||
bool clearLeadingNonPrintable = true;
|
||||
bool clearLeadingSpace = true;
|
||||
bool stopAtNonPrintable = true;
|
||||
char delimiter = SPACE;
|
||||
|
||||
// call utility function, return
|
||||
return readStringConfiguredFromFile( clearLeadingNonPrintable,
|
||||
clearLeadingSpace,
|
||||
stopAtNonPrintable,
|
||||
delimiter,
|
||||
capturedString );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readStringToLineEndFromFile
|
||||
process: ignores leading white space, including space character,
|
||||
captures series of characters up to end of current line
|
||||
or full string
|
||||
Function input/parameters: none
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: string found if successful
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readStringConfigured with appropriate parameters
|
||||
*/
|
||||
bool readStringToLineEndFromFile( char *capturedString )
|
||||
{
|
||||
// initialize variables
|
||||
bool clearLeadingNonPrintable = true;
|
||||
bool clearLeadingSpace = true;
|
||||
bool stopAtNonPrintable = true;
|
||||
char delimiter = NON_PRINTABLE;
|
||||
|
||||
// call utility function, return
|
||||
return readStringConfiguredFromFile( clearLeadingNonPrintable,
|
||||
clearLeadingSpace,
|
||||
stopAtNonPrintable,
|
||||
delimiter,
|
||||
capturedString );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: readStringToDelimiterFromFile
|
||||
process: ignores leading white space, including space character,
|
||||
captures series of characters up to specified character
|
||||
Function input/parameters: none
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: string found if successful
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readStringConfigured with appropriate parameters
|
||||
*/
|
||||
bool readStringToDelimiterFromFile( char delimiter, char *capturedString )
|
||||
{
|
||||
// initialize variables
|
||||
bool clearLeadingNonPrintable = true;
|
||||
bool clearLeadingSpace = true;
|
||||
bool stopAtNonPrintable = true;
|
||||
|
||||
// call utility function, return
|
||||
return readStringConfiguredFromFile( clearLeadingNonPrintable,
|
||||
clearLeadingSpace,
|
||||
stopAtNonPrintable,
|
||||
delimiter,
|
||||
capturedString );
|
||||
}
|
||||
|
||||
|
||||
295
PA04-0927/File_Input_Utility.h
Normal file
295
PA04-0927/File_Input_Utility.h
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
/*
|
||||
Formatted file input utility, function prototypes
|
||||
|
||||
Copyright (c) 2021 by Michael E. Leverington
|
||||
|
||||
Code is free for use in whole or in part and may be modified for other
|
||||
non-commercial use as long as the above copyright statement is included.
|
||||
*/
|
||||
/*
|
||||
Rev 0.0: 30 June 2021, Initial creation of file
|
||||
|
||||
UTILITY USAGE INSTRUCTIONS:
|
||||
|
||||
1) This utility contains functions that may be used for file input operations
|
||||
using the C programming language with text files.
|
||||
The utility must be linked with the program code with which
|
||||
it will be used.
|
||||
|
||||
2) Specifications for all the functions
|
||||
are provided in a standardized format below.
|
||||
|
||||
3) Use this code at your own risk. There is no guarantee of any performance,
|
||||
implied or otherwise, for any part of this code
|
||||
|
||||
END OF INSTRUCTIONS
|
||||
*/
|
||||
|
||||
// PreProcessor test
|
||||
#ifndef FILE_INPUT_UTILITY_H
|
||||
#define FILE_INPUT_UTILITY_H
|
||||
|
||||
// header files
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// constants shared with other files
|
||||
|
||||
// non printable flag, used in getStringConfigured
|
||||
static const char NON_PRINTABLE = (char)(127);
|
||||
|
||||
// constant used for zero character return
|
||||
static const char ZERO_CHAR = '0';
|
||||
|
||||
// constant used for zero int/double value return
|
||||
static const char ZERO_VALUE = 0;
|
||||
|
||||
// function prototypes
|
||||
|
||||
/*
|
||||
Name: accessEndOfInputFileFlag
|
||||
process: allows accessing or modifying end of file flag state;
|
||||
note: flag is maintained (static) value initialized to false
|
||||
Function input/parameters: control code (int), flag state (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of flag state (bool)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: none
|
||||
*/
|
||||
bool accessEndOfInputFileFlag( int ctrlCode, bool setFlag );
|
||||
|
||||
/*
|
||||
Name: accessInputFilePointer
|
||||
process: allows setting or accessing file pointer;
|
||||
note: pointer is maintained (static) value initialized to NULL
|
||||
Function input/parameters: control code (int), file pointer (FILE *)
|
||||
DUMMY_INPUT_FILE_PTR used
|
||||
if not setting file pointer
|
||||
Function output/parameters: none
|
||||
Function output/returned: file pointer (FILE *)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: none
|
||||
*/
|
||||
FILE *accessInputFilePointer( int ctrlCode, const FILE *filePtr );
|
||||
|
||||
/*
|
||||
Name: checkForEndOfInputFile
|
||||
process: checks to see if end of file flag has been encountered,
|
||||
returns true if EOF has been encountered, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified test (bool)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: accessEndOfInputFileFlag
|
||||
*/
|
||||
bool checkForEndOfInputFile();
|
||||
|
||||
/*
|
||||
Name: checkForInputFileOpen
|
||||
process: checks to see if file is currently open
|
||||
returns true if file pointer not null, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified test (bool)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: accessInputFilePointer
|
||||
*/
|
||||
bool checkForInputFileOpen();
|
||||
|
||||
/*
|
||||
Name: clearLeadingWhiteSpace
|
||||
process: captures non printable characters,
|
||||
and space if flag set,
|
||||
returns first non white space value found as integer
|
||||
Function input/parameters: file pointer (FILE *), clear space flag (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: first non WS character as integer
|
||||
Device input/file: value captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: fgetc
|
||||
*/
|
||||
int clearLeadingWhiteSpace( FILE *filePtr, bool clearSpace );
|
||||
|
||||
/*
|
||||
Name: closeInputFile
|
||||
process: closes input file, returns true if successful, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/file: file closed
|
||||
Device output/monitor: none
|
||||
Dependencies: accessInputFilePointer, fclose, accessEndOfInputFileFlag
|
||||
*/
|
||||
bool closeInputFile();
|
||||
|
||||
/*
|
||||
Name: openInputFile
|
||||
process: opens input file, sets file pointer and unsets end of file flag,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: file name (c-string)
|
||||
Function output/parameters: none
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/file: file opened
|
||||
Device output/monitor: none
|
||||
Dependencies: fopen, accessInputFilePointer, accessEndOfInputFileFlag
|
||||
*/
|
||||
bool openInputFile( const char *fileName );
|
||||
|
||||
/*
|
||||
Name: readCharacterFromFile
|
||||
process: ignores leading unprintable characters, including space,
|
||||
captures first printable character
|
||||
Function input/parameters: allow space capture (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: character found if successful, ZERO_CHAR otherwise
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readCharacterFromFileConfigured
|
||||
*/
|
||||
char readCharacterFromFile();
|
||||
|
||||
/*
|
||||
Name: readCharacterFromFileConfigured
|
||||
process: ignores leading unprintable characters,
|
||||
captures first printable character,
|
||||
including space if allowed
|
||||
Function input/parameters: allow space capture (bool)
|
||||
Function output/parameters: none
|
||||
Function output/returned: character found if successful, ZERO_CHAR otherwise
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, clearLeadingWhiteSpace,
|
||||
accessEndOfInputFileFlag
|
||||
*/
|
||||
char readCharacterFromFileConfigured( bool captureSpace );
|
||||
|
||||
/*
|
||||
Name: readDoubleFromFile
|
||||
process: ignores leading unprintable characters,
|
||||
captures first contiguous double value
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: double value found if successful (double)
|
||||
Device input/file: double value captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fscanf, accessEndOfInputFileFlag
|
||||
*/
|
||||
double readDoubleFromFile();
|
||||
|
||||
/*
|
||||
Name: readIntegerFromFile
|
||||
process: ignores leading unprintable characters,
|
||||
captures first contiguous integer
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: integer found if successful, ZERO_VALUE otherwise
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fscanf, accessEndOfInputFileFlag
|
||||
*/
|
||||
int readIntegerFromFile();
|
||||
|
||||
/*
|
||||
Name: readLongFromFile
|
||||
process: ignores leading unprintable characters,
|
||||
captures first contiguous long int
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: long integer found if successful,
|
||||
ZERO_VALUE otherwise
|
||||
Device input/file: long value captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fscanf, accessEndOfInputFileFlag
|
||||
*/
|
||||
long readLongFromFile();
|
||||
|
||||
/*
|
||||
Name: readRawCharFromFile
|
||||
process: captures first character in file stream including non-printable
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: character found if successful, ZERO_CHAR otherwise
|
||||
Device input/file: character captured from file
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
accessInputFilePointer, fgetc, accessEndOfInputFileFlag
|
||||
*/
|
||||
char readRawCharFromFile();
|
||||
|
||||
/*
|
||||
Name: readStringConfiguredFromFile
|
||||
Process: captures string with options:
|
||||
- clear leading non printable (bool)
|
||||
- clear leading space character (bool)
|
||||
- adquires characters up to any non-printable (bool)
|
||||
- adquires characters up to any printable delimiter (char)
|
||||
- use constant NON_PRINTABLE if no delimiter
|
||||
- also stops capture when full (MAX_STR_LEN)
|
||||
Note: This function consumes the last character input,
|
||||
including the space, delimiter, or non-printable character
|
||||
Function input/parameters: see process above
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: checkForInputFileOpen, checkForEndOfInputFile,
|
||||
clearLeadingWhiteSpace, fgetc, accessEndOfInputFileFlag
|
||||
*/
|
||||
bool readStringConfiguredFromFile( bool clearLeadingNonPrintable,
|
||||
bool clearLeadingSpace,
|
||||
bool stopAtNonPrintable,
|
||||
char delimiter,
|
||||
char *capturedString );
|
||||
|
||||
/*
|
||||
Name: readStringSegmentFromFile
|
||||
process: ignores leading white space, including space character,
|
||||
captures series of characters up to first space,
|
||||
or end of line, or full string
|
||||
Function input/parameters: none
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readStringConfigured with appropriate parameters
|
||||
*/
|
||||
bool readStringSegmentFromFile( char *capturedString );
|
||||
|
||||
/*
|
||||
Name: readStringToLineEndFromFile
|
||||
process: ignores leading white space, including space character,
|
||||
captures series of characters up to end of current line
|
||||
or full string
|
||||
Function input/parameters: none
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: string found if successful
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readStringConfigured with appropriate parameters
|
||||
*/
|
||||
bool readStringToLineEndFromFile( char *capturedString );
|
||||
|
||||
/*
|
||||
Name: readStringToDelimiterFromFile
|
||||
process: ignores leading white space, including space character,
|
||||
captures series of characters up to specified character
|
||||
Function input/parameters: none
|
||||
Function output/parameters: captured string (char *), EMPTY_STRING otherwise
|
||||
Function output/returned: string found if successful
|
||||
Device input/file: character(s) captured from file as needed
|
||||
Device output/monitor: none
|
||||
Dependencies: readStringConfigured with appropriate parameters
|
||||
*/
|
||||
bool readStringToDelimiterFromFile( char delimiter, char *capturedString );
|
||||
|
||||
#endif // FILE_INPUT_UTILITY_H
|
||||
|
||||
511
PA04-0927/File_Output_Utility.c
Normal file
511
PA04-0927/File_Output_Utility.c
Normal file
|
|
@ -0,0 +1,511 @@
|
|||
/*
|
||||
Formatted file ouput utility, function implementations
|
||||
|
||||
Copyright (c) 2021 by Michael E. Leverington
|
||||
|
||||
Code is free for use in whole or in part and may be modified for other
|
||||
non-commercial use as long as the above copyright statement is included.
|
||||
*/
|
||||
|
||||
// header files
|
||||
#include "File_Output_Utility.h"
|
||||
|
||||
// local global constants, used only in this file
|
||||
|
||||
// dummy file pointer for accessInputFilePointer
|
||||
const FILE *DUMMY_OUTPUT_FILE_PTR = NULL;
|
||||
|
||||
// dummy Boolean for accessEndOfInputFileFlag, accessOpenFlag
|
||||
// const char DUMMY_OUTPUT_FLAG = false;
|
||||
|
||||
// control code for accessing file pointer, accessInputFilePointer
|
||||
const int GET_OUTPUT_FILE_PTR = 6006;
|
||||
|
||||
// control code for accessing flag value,
|
||||
// accessEndOfInputFileFlag, accessOpenFlag
|
||||
const int GET_OUTPUT_FLAG = 9009;
|
||||
|
||||
// control code for setting file pointer, accessInputFilePointer
|
||||
const int SET_OUTPUT_FILE_PTR = 8008;
|
||||
|
||||
// control code for setting flag value, accessEndOfInputFileFlag,
|
||||
// accessOpenFlag
|
||||
// const int SET_OUTPUT_FLAG = 1001;
|
||||
|
||||
/*
|
||||
Name: accessOutputFilePointer
|
||||
process: allows setting or accessing file pointer;
|
||||
note: pointer is maintained (static) value initialized to NULL
|
||||
Function input/parameters: control code (int), file pointer (FILE *)
|
||||
DUMMY_OUTPUT_FILE_PTR used
|
||||
if not setting file pointer
|
||||
Function output/parameters: none
|
||||
Function output/returned: file pointer (FILE *)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: none
|
||||
*/
|
||||
FILE *accessOutputFilePointer( int ctrlCode, const FILE *filePtr )
|
||||
{
|
||||
static FILE *filePointer = NULL;
|
||||
|
||||
// check for set new pointer
|
||||
if( ctrlCode == SET_OUTPUT_FILE_PTR )
|
||||
{
|
||||
// set file pointer to parameter
|
||||
filePointer = (FILE *)filePtr;
|
||||
}
|
||||
|
||||
// return file pointer
|
||||
return filePointer;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: closeOutputFile
|
||||
Process: closes output file, returns true if successful, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: output file closed
|
||||
Dependencies: accessOutputFilePointer, fclose
|
||||
*/
|
||||
bool closeOutputFile()
|
||||
{
|
||||
// set local file pointer to working file pointer
|
||||
// function: accessOutputFilePointer
|
||||
FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR,
|
||||
DUMMY_OUTPUT_FILE_PTR );
|
||||
|
||||
// check for valid file pointer
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// add two more endlines to verify that the data is ended
|
||||
// and has at least one extra newline after the data
|
||||
// function: fprintf
|
||||
fprintf( filePtr, "\n\n" );
|
||||
|
||||
// flush all data to the device
|
||||
// function: fflush
|
||||
fflush( filePtr );
|
||||
|
||||
// close file
|
||||
// function: fclose
|
||||
fclose( filePtr );
|
||||
|
||||
// set pointer to NULL
|
||||
// function: accessOutputFilePointer
|
||||
accessOutputFilePointer( SET_OUTPUT_FILE_PTR, NULL );
|
||||
|
||||
// return successful operation
|
||||
return true;
|
||||
}
|
||||
|
||||
// return failed operation
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: openOutputFile
|
||||
Process: opens input file, returns true if successful, false otherwise
|
||||
Function input/parameters: file name (c-string)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: output file opened
|
||||
Dependencies: accessOutputFilePointer, fopen
|
||||
*/
|
||||
bool openOutputFile( const char *fileName )
|
||||
{
|
||||
// initialize variables
|
||||
FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR,
|
||||
DUMMY_OUTPUT_FILE_PTR );
|
||||
char writeCharacter[] = "w";
|
||||
|
||||
// check for file not open
|
||||
if( filePtr == NULL )
|
||||
{
|
||||
// open file
|
||||
// function: fopen
|
||||
filePtr = fopen( fileName, writeCharacter );
|
||||
|
||||
// check for success of file open
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// set pointer in access function
|
||||
// function: accessInputFilePointer
|
||||
accessOutputFilePointer( SET_OUTPUT_FILE_PTR, filePtr );
|
||||
|
||||
// return operation success
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// end of file not previously opened block
|
||||
|
||||
// return operation failure
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeCharacterToFile
|
||||
Process: writes individual character to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: character to output (char)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: character written to file
|
||||
Dependencies: accessOutputFilePointer, fprintf
|
||||
*/
|
||||
bool writeCharacterToFile( char outChar )
|
||||
{
|
||||
// initialize variables, set file pointer
|
||||
// function: accessOutputFilePointer
|
||||
FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR,
|
||||
DUMMY_OUTPUT_FILE_PTR );
|
||||
|
||||
// check for open file
|
||||
// function: checkForOutputFileOpen
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// write character
|
||||
// function: fprintf
|
||||
fprintf( filePtr, "%c", outChar );
|
||||
|
||||
// return successful operation
|
||||
return true;
|
||||
}
|
||||
|
||||
// return failed operation
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeCharactersToFile
|
||||
Process: writes multiple characters to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: number of characters to output (int),
|
||||
character to output (char)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: multiple characters written to file
|
||||
Dependencies: writeCharacterToFile
|
||||
*/
|
||||
bool writeCharactersToFile( int numChars, char outChar )
|
||||
{
|
||||
// check for number of characters remaining,
|
||||
if( numChars > 0 )
|
||||
{
|
||||
// write character, check for success
|
||||
// function: writeChar
|
||||
if( writeCharacterToFile( outChar ) )
|
||||
{
|
||||
// continue recursion,
|
||||
// check for downstream success
|
||||
// function: writeChars
|
||||
return writeCharactersToFile( numChars - 1, outChar );
|
||||
}
|
||||
|
||||
// quit recursion
|
||||
// return unsuccessful operation - write operation failed
|
||||
return false;
|
||||
}
|
||||
|
||||
// return successful operation - all characters have been written
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeDoubleToFile
|
||||
Process: writes individual formatted double value to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: double value to output (double),
|
||||
number of digits to right of radix point
|
||||
(precision) (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: double written to file
|
||||
Dependencies: writeDoubleJustifiedToFile
|
||||
*/
|
||||
bool writeDoubleToFile( double outVal, int precision )
|
||||
{
|
||||
// initialize variables, set block size to zero and justified to "LEFT"
|
||||
int blockSize = 0;
|
||||
char justified[] = "LEFT";
|
||||
|
||||
// call to justified function
|
||||
// function: writeDoubleJustifiedToFile
|
||||
return writeDoubleJustifiedToFile( outVal, precision,
|
||||
blockSize, justified );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeDoubleToFileJustified
|
||||
Process: writes individual formatted double value to file justified,
|
||||
returns true if successful, false otherwise
|
||||
outVal - the double value to be output
|
||||
precision - number of digits to the right of the radix point
|
||||
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: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: double written to file as specified
|
||||
Dependencies: sprintf, writeStringJustifiedToFile
|
||||
*/
|
||||
bool writeDoubleJustifiedToFile( double outVal, int precision,
|
||||
int blockSize, const char *justified )
|
||||
{
|
||||
// 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 double to string
|
||||
// function: sprintf
|
||||
sprintf( outStr, specStr, outVal );
|
||||
|
||||
// write as string, return result
|
||||
// function: writeStringJustified
|
||||
return writeStringJustifiedToFile( outStr, blockSize, justified );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeEndlineToFile
|
||||
Process: writes newline ('\n') to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: newline written to file
|
||||
Dependencies: accessOutputFilePointer, fprintf
|
||||
*/
|
||||
bool writeEndlineToFile()
|
||||
{
|
||||
// get file pointer, initialize variable
|
||||
// function: accessOutputFilePointer
|
||||
FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR,
|
||||
DUMMY_OUTPUT_FILE_PTR );
|
||||
|
||||
// check for open file
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// print endline to file
|
||||
// function: fprintf
|
||||
fprintf( filePtr, "%c", NEWLINE_CHAR );
|
||||
|
||||
// return successful operation
|
||||
return true;
|
||||
}
|
||||
|
||||
// file not open, return failed operation
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeEndlinesToFile
|
||||
Process: writes multiple carriage return ('\r')
|
||||
and newline ('\n') pairs to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: number of endline pairs to write (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: multiple newline characters written to file
|
||||
Dependencies: writeString
|
||||
*/
|
||||
bool writeEndlinesToFile( int numEndlines )
|
||||
{
|
||||
// check for number of characters remaining,
|
||||
if( numEndlines > 0 )
|
||||
{
|
||||
// write endline, check for success
|
||||
// function: writeEndlineTofile
|
||||
if( writeEndlineToFile() )
|
||||
{
|
||||
// continue recursion,
|
||||
// check for downstream success
|
||||
// function: writeEndlinesToFile
|
||||
return writeEndlinesToFile( numEndlines - 1 );
|
||||
}
|
||||
|
||||
// quit recursion
|
||||
// return unsuccessful operation - write operation failed
|
||||
return false;
|
||||
}
|
||||
|
||||
// return successful operation - all endlines have been written
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeIntegerToFile
|
||||
Process: writes individual integer to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: integer to output (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: integer written to file
|
||||
Dependencies: writeIntegerJustifiedToFile
|
||||
*/
|
||||
bool writeIntegerToFile( int outVal )
|
||||
{
|
||||
// initialize variables, set block size to zero and justified to "LEFT"
|
||||
int blockSize = 0;
|
||||
char justified[] = "LEFT";
|
||||
|
||||
// call to justified function
|
||||
// function: writeDoubleJustifiedToFile
|
||||
return writeIntegerJustifiedToFile( outVal, blockSize, justified );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeIntegerJustifiedToFile
|
||||
Process: writes individual integer to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters:
|
||||
outVal - the integer value to be output
|
||||
precision - number of digits to the right of the radix point
|
||||
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: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: integer written to file as specified
|
||||
Dependencies: sprintf, writeStringJustifiedToFile
|
||||
*/
|
||||
bool writeIntegerJustifiedToFile( int outVal, int blockSize,
|
||||
const char *justified )
|
||||
{
|
||||
// initialize variables, create temporary output string
|
||||
char outStr[ MIN_STR_LEN ];
|
||||
|
||||
// set integer to string
|
||||
// function: sprintf
|
||||
sprintf( outStr, "%d", outVal );
|
||||
|
||||
// write as string, return result
|
||||
// function: writeStringJustified
|
||||
return writeStringJustifiedToFile( outStr, blockSize, justified );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeStringToFile
|
||||
Process: writes String value to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: double value to output (double),
|
||||
number of digits to right of radix point
|
||||
(precision) (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: String written to file
|
||||
Dependencies: writeStringJustifiedToFile
|
||||
*/
|
||||
bool writeStringToFile( const char *outString )
|
||||
{
|
||||
// initialize variables, set block size to zero and justified to "LEFT"
|
||||
int blockSize = 0;
|
||||
char justified[] = "LEFT";
|
||||
|
||||
// call to justified function
|
||||
// function: writeStringJustifiedToFile
|
||||
return writeStringJustifiedToFile( outString, blockSize, justified );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: writeStringJustifiedToFile
|
||||
Process: write string to file 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: success of output operation (bool)
|
||||
Function input/keyboard: None
|
||||
Device output/file: string written to file as specified
|
||||
Dependencies: strlen, strcmp, writeCharactersToFile, fprint
|
||||
*/
|
||||
bool writeStringJustifiedToFile( const char *outStr,
|
||||
int blockSize, const char *justify )
|
||||
{
|
||||
// initialize variables, set pre-, post- spaces to zero
|
||||
int preSpaces = 0, postSpaces = 0, strLength;
|
||||
|
||||
// get file pointer
|
||||
// function: accessFileOutputFilePointer
|
||||
FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR,
|
||||
DUMMY_OUTPUT_FILE_PTR );
|
||||
|
||||
if( filePtr != NULL )
|
||||
{
|
||||
// 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, check for success
|
||||
// function: writeCharactersToFile
|
||||
writeCharactersToFile( preSpaces, SPACE );
|
||||
|
||||
// print string
|
||||
// function: fprintf
|
||||
fprintf( filePtr, "%s", outStr );
|
||||
|
||||
// print post spaces
|
||||
// function: printChars
|
||||
writeCharactersToFile( postSpaces, SPACE );
|
||||
|
||||
// return successful operation
|
||||
return true;
|
||||
}
|
||||
|
||||
// return failed operation
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
236
PA04-0927/File_Output_Utility.h
Normal file
236
PA04-0927/File_Output_Utility.h
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
Formatted file output utility, function prototypes
|
||||
|
||||
Copyright (c) 2021 by Michael E. Leverington
|
||||
|
||||
Code is free for use in whole or in part and may be modified for other
|
||||
non-commercial use as long as the above copyright statement is included.
|
||||
*/
|
||||
/*
|
||||
Rev 0.0: 30 June 2021, Initial creation of file
|
||||
|
||||
UTILITY USAGE INSTRUCTIONS:
|
||||
|
||||
1) This utility contains functions that may be used for file input operations
|
||||
using the C programming language with text files.
|
||||
The utility must be linked with the program code with which
|
||||
it will be used.
|
||||
|
||||
2) Specifications for all the functions
|
||||
are provided in a standardized format below.
|
||||
|
||||
3) Use this code at your own risk. There is no guarantee of any performance,
|
||||
implied or otherwise, for any part of this code
|
||||
|
||||
END OF INSTRUCTIONS
|
||||
*/
|
||||
|
||||
// PreProcessor directives
|
||||
#ifndef FILE_OUTPUT_UTILITY_H
|
||||
#define FILE_OUTPUT_UTILITY_H
|
||||
|
||||
// header files
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// function prototypes
|
||||
|
||||
/*
|
||||
Name: accessOutputFilePointer
|
||||
process: allows setting or accessing file pointer;
|
||||
note: pointer is maintained (static) value initialized to NULL
|
||||
Function input/parameters: control code (int), file pointer (FILE *)
|
||||
DUMMY_OUTPUT_FILE_PTR used
|
||||
if not setting file pointer
|
||||
Function output/parameters: none
|
||||
Function output/returned: file pointer (FILE *)
|
||||
Device input/file: none
|
||||
Device output/monitor: none
|
||||
Dependencies: none
|
||||
*/
|
||||
FILE *accessOutputFilePointer( int ctrlCode, const FILE *filePtr );
|
||||
|
||||
/*
|
||||
Name: closeOutputFile
|
||||
Process: closes output file, returns true if successful, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: output file closed
|
||||
Dependencies: accessOutputFilePointer, fclose
|
||||
*/
|
||||
bool closeOutputFile();
|
||||
|
||||
/*
|
||||
Name: openOutputFile
|
||||
Process: opens input file, returns true if successful, false otherwise
|
||||
Function input/parameters: file name (c-string)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: output file opened
|
||||
Dependencies: accessOutputFilePointer, fopen
|
||||
*/
|
||||
bool openOutputFile( const char *fileName );
|
||||
|
||||
/*
|
||||
Name: writeCharacterToFile
|
||||
Process: writes individual character to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: character to output (char)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: character written to file
|
||||
Dependencies: accessOutputFilePointer, fprintf
|
||||
*/
|
||||
bool writeCharacterToFile( char outChar );
|
||||
|
||||
/*
|
||||
Name: writeCharactersToFile
|
||||
Process: writes multiple characters to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: number of characters to output (int),
|
||||
character to output (char)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: multiple characters written to file
|
||||
Dependencies: writeCharacterToFile
|
||||
*/
|
||||
bool writeCharactersToFile( int numChars, char outChar );
|
||||
|
||||
/*
|
||||
Name: writeDoubleToFile
|
||||
Process: writes individual formatted double value to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: double value to output (double),
|
||||
number of digits to right of radix point
|
||||
(precision) (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: double written to file
|
||||
Dependencies: writeDoubleJustifiedToFile
|
||||
*/
|
||||
bool writeDoubleToFile( double outVal, int precision );
|
||||
|
||||
/*
|
||||
Name: writeDoubleToFileJustified
|
||||
Process: writes individual formatted double value to file justified,
|
||||
returns true if successful, false otherwise
|
||||
outVal - the double value to be output
|
||||
precision - number of digits to the right of the radix point
|
||||
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: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: double written to file as specified
|
||||
Dependencies: sprintf, writeStringJustifiedToFile
|
||||
*/
|
||||
bool writeDoubleJustifiedToFile( double outVal, int precision,
|
||||
int blockSize, const char *justified );
|
||||
|
||||
/*
|
||||
Name: writeEndlineToFile
|
||||
Process: writes newline ('\n') to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: newline written to file
|
||||
Dependencies: accessOutputFilePointer, fprintf
|
||||
*/
|
||||
bool writeEndlineToFile();
|
||||
|
||||
/*
|
||||
Name: writeEndlinesToFile
|
||||
Process: writes multiple carriage return ('\r')
|
||||
and newline ('\n') pairs to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: number of endline pairs to write (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: multiple newline characters written to file
|
||||
Dependencies: writeString
|
||||
*/
|
||||
bool writeEndlinesToFile( int numEndlines );
|
||||
|
||||
/*
|
||||
Name: writeIntegerToFile
|
||||
Process: writes individual integer to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: integer to output (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: integer written to file
|
||||
Dependencies: writeIntegerJustifiedToFile
|
||||
*/
|
||||
bool writeIntegerToFile( int outVal );
|
||||
|
||||
/*
|
||||
Name: writeIntegerJustifiedToFile
|
||||
Process: writes individual integer to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters:
|
||||
outVal - the integer value to be output
|
||||
precision - number of digits to the right of the radix point
|
||||
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: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: integer written to file as specified
|
||||
Dependencies: sprintf, writeStringJustifiedToFile
|
||||
*/
|
||||
bool writeIntegerJustifiedToFile( int outVal, int blockSize,
|
||||
const char *justified );
|
||||
|
||||
/*
|
||||
Name: writeStringToFile
|
||||
Process: writes String value to file,
|
||||
returns true if successful, false otherwise
|
||||
Function input/parameters: double value to output (double),
|
||||
number of digits to right of radix point
|
||||
(precision) (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: operation success (bool)
|
||||
Device input/file: none
|
||||
Device output/file: String written to file
|
||||
Dependencies: writeStringJustifiedToFile
|
||||
*/
|
||||
bool writeStringToFile( const char *outString );
|
||||
|
||||
/*
|
||||
Name: writeStringJustifiedToFile
|
||||
Process: write string to file 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: success of output operation (bool)
|
||||
Function input/keyboard: None
|
||||
Device output/file: string written to file as specified
|
||||
Dependencies: strlen, strcmp, writeCharactersToFile, fprint
|
||||
*/
|
||||
bool writeStringJustifiedToFile( const char *outStr,
|
||||
int blockSize, const char *justify );
|
||||
|
||||
|
||||
#endif // FILE_OUTPUT_UTILITY_H
|
||||
|
||||
10
PA04-0927/InputFiles/in_1.txt
Normal file
10
PA04-0927/InputFiles/in_1.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Start Room Data,
|
||||
Bio Sciences, 413, 30
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3103, 36
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 122, 61
|
||||
CS 386, 28
|
||||
CS 421, 32
|
||||
End Class Data,
|
||||
10
PA04-0927/InputFiles/in_1_bad.txt
Normal file
10
PA04-0927/InputFiles/in_1_bad.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Start Room Data,
|
||||
Bio Sciences, 413, 30
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3103, 36
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 122, 61
|
||||
CS 386, 70
|
||||
CS 421, 32
|
||||
End Class Data,
|
||||
14
PA04-0927/InputFiles/in_2.txt
Normal file
14
PA04-0927/InputFiles/in_2.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Start Room Data,
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3103, 36
|
||||
Health & Learning Center, 3113, 70
|
||||
Adel Mathematics Center, 147, 46
|
||||
Adel Mathematics Center, 148, 40
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 110, 39
|
||||
CS 112, 69
|
||||
CS 136, 61
|
||||
CS 200, 44
|
||||
CS 212, 34
|
||||
End Class Data,
|
||||
18
PA04-0927/InputFiles/in_3.txt
Normal file
18
PA04-0927/InputFiles/in_3.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Start Room Data,
|
||||
Bio Sciences, 265, 140
|
||||
Bio Sciences, 413, 30
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3113, 70
|
||||
Adel Mathematics Center, 148, 40
|
||||
Eastburn Education, 124, 50
|
||||
Raul H. Castro SBS, 111, 98
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 110, 39
|
||||
CS 112, 69
|
||||
CS 136, 61
|
||||
CS 200, 44
|
||||
CS 248, 138
|
||||
CS 301, 95
|
||||
CS 386, 28
|
||||
End Class Data,
|
||||
18
PA04-0927/InputFiles/in_4.txt
Normal file
18
PA04-0927/InputFiles/in_4.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Start Room Data,
|
||||
Bio Sciences, 265, 140
|
||||
Bio Sciences, 413, 30
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3113, 70
|
||||
Adel Mathematics Center, 148, 40
|
||||
Eastburn Education, 124, 50
|
||||
Raul H. Castro SBS, 111, 98
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 110, 39
|
||||
CS 112, 79
|
||||
CS 136, 61
|
||||
CS 200, 44
|
||||
CS 248, 138
|
||||
CS 301, 95
|
||||
CS 386, 28
|
||||
End Class Data,
|
||||
24
PA04-0927/InputFiles/in_5.txt
Normal file
24
PA04-0927/InputFiles/in_5.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Start Room Data,
|
||||
Bio Sciences, 256, 140
|
||||
Bio Sciences, 265, 140
|
||||
Science Annex, 113, 90
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3103, 36
|
||||
Adel Mathematics Center, 147, 46
|
||||
Adel Mathematics Center, 148, 40
|
||||
Adel Mathematics Center, 164, 50
|
||||
Eastburn Education, 174, 38
|
||||
Raul H. Castro SBS, 111, 98
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 110, 39
|
||||
CS 122, 48
|
||||
CS 126, 36
|
||||
CS 136, 61
|
||||
CS 200, 44
|
||||
CS 248, 138
|
||||
CS 249, 87
|
||||
CS 301, 95
|
||||
CS 480, 128
|
||||
CS 421, 32
|
||||
End Class Data,
|
||||
28
PA04-0927/InputFiles/in_6.txt
Normal file
28
PA04-0927/InputFiles/in_6.txt
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Start Room Data,
|
||||
Bio Sciences, 256, 140
|
||||
Bio Sciences, 413, 30
|
||||
Science Annex, 113, 90
|
||||
Health & Learning Center, 3101, 65
|
||||
Health & Learning Center, 3103, 36
|
||||
Health & Learning Center, 3113, 70
|
||||
Adel Mathematics Center, 147, 46
|
||||
Adel Mathematics Center, 148, 40
|
||||
Adel Mathematics Center, 164, 50
|
||||
Eastburn Education, 124, 40
|
||||
Eastburn Education, 174, 38
|
||||
Raul H. Castro SBS, 111, 98
|
||||
End Room Data,
|
||||
Start Class Data,
|
||||
CS 110, 39
|
||||
CS 112, 69
|
||||
CS 122, 48
|
||||
CS 126, 36
|
||||
CS 136, 61
|
||||
CS 200, 44
|
||||
CS 212, 34
|
||||
CS 248, 138
|
||||
CS 249, 87
|
||||
CS 301, 95
|
||||
CS 386, 28
|
||||
CS 421, 32
|
||||
End Class Data,
|
||||
41
PA04-0927/Makefile
Normal file
41
PA04-0927/Makefile
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
CC = gcc -Wall
|
||||
SOURCES = PA04_Main.c StateUtilities_LogN.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
||||
OBJECTS = PA04_Main.o StateUtilities_LogN.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
||||
|
||||
all: PA04_Main
|
||||
|
||||
PA04_Main: $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -o PA04_Main
|
||||
|
||||
PA04_Main.o: PA04_Main.c
|
||||
$(CC) -c PA04_Main.c -o PA04_Main.o
|
||||
|
||||
BasicUtilities.o: BasicUtilities.c
|
||||
$(CC) -c BasicUtilities.c -o BasicUtilities.o
|
||||
|
||||
CourseUtilities.o: CourseUtilities.c
|
||||
$(CC) -c CourseUtilities.c -o CourseUtilities.o
|
||||
|
||||
RoomUtilities.o: RoomUtilities.c
|
||||
$(CC) -c RoomUtilities.c -o RoomUtilities.o
|
||||
|
||||
Console_IO_Utility.o: Console_IO_Utility.c
|
||||
$(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o
|
||||
|
||||
File_Input_Utility.o: File_Input_Utility.c
|
||||
$(CC) -c File_Input_Utility.c -o File_Input_Utility.o
|
||||
|
||||
File_Output_Utility.o: File_Output_Utility.c
|
||||
$(CC) -c File_Output_Utility.c -o File_Output_Utility.o
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) PA03_Main PA03_Main.out
|
||||
|
||||
clean_objects:
|
||||
rm -f $(OBJECTS)
|
||||
|
||||
run:
|
||||
./PA04_Main
|
||||
|
||||
run_win:
|
||||
PA04_Main
|
||||
38
PA04-0927/OutputFiles/Output_In1.txt
Normal file
38
PA04-0927/OutputFiles/Output_In1.txt
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Course/Classroom Fit Program
|
||||
============================
|
||||
|
||||
==========Upload start
|
||||
Nm: Bio Sciences, Num: 413, cap: 30
|
||||
Nm: Health & Learning Center, Num: 3101, cap: 65
|
||||
Nm: Health & Learning Center, Num: 3103, cap: 36
|
||||
Nm: CS 122, sz: 61
|
||||
Nm: CS 386, sz: 28
|
||||
Nm: CS 421, sz: 32
|
||||
==========Upload end
|
||||
|
||||
Start Solution Search
|
||||
|
||||
Recursion Level 0: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 122, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Success!
|
||||
Course Name: CS 386, Course Size: 28 will fit in Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 122, Course Size: 61 - Success!
|
||||
Course Name: CS 122, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36
|
||||
Trying Course Name: CS 122, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
Trying Course Name: CS 421, Course Size: 32 - Success!
|
||||
Course Name: CS 421, Course Size: 32 will fit in Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36
|
||||
|
||||
Fit Classroom Success: Solution Found.
|
||||
|
||||
Classroom/Course Request Fit List
|
||||
=================================
|
||||
Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30 - Course Name: CS 386, Course Size: 28
|
||||
Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65 - Course Name: CS 122, Course Size: 61
|
||||
Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36 - Course Name: CS 421, Course Size: 32
|
||||
|
||||
End Course/Classroom Fit Program
|
||||
23
PA04-0927/OutputFiles/Output_In1_Bad.txt
Normal file
23
PA04-0927/OutputFiles/Output_In1_Bad.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
Course/Classroom Fit Program
|
||||
============================
|
||||
|
||||
==========Upload start
|
||||
Nm: Bio Sciences, Num: 413, cap: 30
|
||||
Nm: Health & Learning Center, Num: 3101, cap: 65
|
||||
Nm: Health & Learning Center, Num: 3103, cap: 36
|
||||
Nm: CS 122, sz: 61
|
||||
Nm: CS 386, sz: 70
|
||||
Nm: CS 421, sz: 32
|
||||
==========Upload end
|
||||
|
||||
Start Solution Search
|
||||
|
||||
Recursion Level 0: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 122, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 70 - Failed!
|
||||
Trying Course Name: CS 421, Course Size: 32 - Failed!
|
||||
|
||||
Fit Classroom Failure: Solution not found.
|
||||
|
||||
End Course/Classroom Fit Program
|
||||
169
PA04-0927/OutputFiles/Output_In2.txt
Normal file
169
PA04-0927/OutputFiles/Output_In2.txt
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
Course/Classroom Fit Program
|
||||
============================
|
||||
|
||||
==========Upload start
|
||||
Nm: Health & Learning Center, Num: 3101, cap: 65
|
||||
Nm: Health & Learning Center, Num: 3103, cap: 36
|
||||
Nm: Health & Learning Center, Num: 3113, cap: 70
|
||||
Nm: Adel Mathematics Center, Num: 147, cap: 46
|
||||
Nm: Adel Mathematics Center, Num: 148, cap: 40
|
||||
Nm: CS 110, sz: 39
|
||||
Nm: CS 112, sz: 69
|
||||
Nm: CS 136, sz: 61
|
||||
Nm: CS 200, sz: 44
|
||||
Nm: CS 212, sz: 34
|
||||
==========Upload end
|
||||
|
||||
Start Solution Search
|
||||
|
||||
Recursion Level 0: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Success!
|
||||
Course Name: CS 212, Course Size: 34 will fit in Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 212, Course Size: 34 - recursion fell back to Recursion Level 1!
|
||||
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 0!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Success!
|
||||
Course Name: CS 212, Course Size: 34 will fit in Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 212, Course Size: 34 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
|
||||
Fit Classroom Success: Solution Found.
|
||||
|
||||
Classroom/Course Request Fit List
|
||||
=================================
|
||||
Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65 - Course Name: CS 136, Course Size: 61
|
||||
Building Name: Health & Learning Center, Room Number: 3103, Room Capacity: 36 - Course Name: CS 212, Course Size: 34
|
||||
Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70 - Course Name: CS 112, Course Size: 69
|
||||
Building Name: Adel Mathematics Center, Room Number: 147, Room Capacity: 46 - Course Name: CS 200, Course Size: 44
|
||||
Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40 - Course Name: CS 110, Course Size: 39
|
||||
|
||||
End Course/Classroom Fit Program
|
||||
656
PA04-0927/OutputFiles/Output_In3.txt
Normal file
656
PA04-0927/OutputFiles/Output_In3.txt
Normal file
|
|
@ -0,0 +1,656 @@
|
|||
Course/Classroom Fit Program
|
||||
============================
|
||||
|
||||
==========Upload start
|
||||
Nm: Bio Sciences, Num: 265, cap: 140
|
||||
Nm: Bio Sciences, Num: 413, cap: 30
|
||||
Nm: Health & Learning Center, Num: 3101, cap: 65
|
||||
Nm: Health & Learning Center, Num: 3113, cap: 70
|
||||
Nm: Adel Mathematics Center, Num: 148, cap: 40
|
||||
Nm: Eastburn Education, Num: 124, cap: 50
|
||||
Nm: Raul H. Castro SBS, Num: 111, cap: 98
|
||||
Nm: CS 110, sz: 39
|
||||
Nm: CS 112, sz: 69
|
||||
Nm: CS 136, sz: 61
|
||||
Nm: CS 200, sz: 44
|
||||
Nm: CS 248, sz: 138
|
||||
Nm: CS 301, sz: 95
|
||||
Nm: CS 386, sz: 28
|
||||
==========Upload end
|
||||
|
||||
Start Solution Search
|
||||
|
||||
Recursion Level 0: Seeking a fit for Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Success!
|
||||
Course Name: CS 386, Course Size: 28 will fit in Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 386, Course Size: 28 - recursion fell back to Recursion Level 1!
|
||||
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 0!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Success!
|
||||
Course Name: CS 386, Course Size: 28 will fit in Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
|
||||
Recursion Level 5: Seeking a fit for Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 4!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
|
||||
Recursion Level 5: Seeking a fit for Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 4!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 386, Course Size: 28 - recursion fell back to Recursion Level 1!
|
||||
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 0!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Success!
|
||||
Course Name: CS 386, Course Size: 28 will fit in Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
|
||||
Recursion Level 5: Seeking a fit for Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 4!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 386, Course Size: 28 - recursion fell back to Recursion Level 1!
|
||||
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 0!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Success!
|
||||
Course Name: CS 386, Course Size: 28 will fit in Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
|
||||
Recursion Level 5: Seeking a fit for Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 4!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 386, Course Size: 28 - recursion fell back to Recursion Level 1!
|
||||
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 0!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Success!
|
||||
Course Name: CS 248, Course Size: 138 will fit in Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140
|
||||
|
||||
Recursion Level 1: Seeking a fit for Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Success!
|
||||
Course Name: CS 386, Course Size: 28 will fit in Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30
|
||||
|
||||
Recursion Level 2: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 112, Course Size: 69 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 136, Course Size: 61 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 200, Course Size: 44 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 2!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Success!
|
||||
Course Name: CS 136, Course Size: 61 will fit in Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65
|
||||
|
||||
Recursion Level 3: Seeking a fit for Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Failed!
|
||||
Trying Course Name: CS 386, Course Size: 28 - Failed!
|
||||
|
||||
Course Name: CS 110, Course Size: 39 - recursion fell back to Recursion Level 3!
|
||||
|
||||
Trying Course Name: CS 112, Course Size: 69 - Success!
|
||||
Course Name: CS 112, Course Size: 69 will fit in Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70
|
||||
|
||||
Recursion Level 4: Seeking a fit for Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
Trying Course Name: CS 110, Course Size: 39 - Success!
|
||||
Course Name: CS 110, Course Size: 39 will fit in Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40
|
||||
|
||||
Recursion Level 5: Seeking a fit for Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Success!
|
||||
Course Name: CS 200, Course Size: 44 will fit in Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50
|
||||
|
||||
Recursion Level 6: Seeking a fit for Building Name: Raul H. Castro SBS, Room Number: 111, Room Capacity: 98
|
||||
Trying Course Name: CS 110, Course Size: 39 - Failed!
|
||||
Trying Course Name: CS 112, Course Size: 69 - Failed!
|
||||
Trying Course Name: CS 136, Course Size: 61 - Failed!
|
||||
Trying Course Name: CS 200, Course Size: 44 - Failed!
|
||||
Trying Course Name: CS 248, Course Size: 138 - Failed!
|
||||
Trying Course Name: CS 301, Course Size: 95 - Success!
|
||||
Course Name: CS 301, Course Size: 95 will fit in Building Name: Raul H. Castro SBS, Room Number: 111, Room Capacity: 98
|
||||
|
||||
Fit Classroom Success: Solution Found.
|
||||
|
||||
Classroom/Course Request Fit List
|
||||
=================================
|
||||
Building Name: Bio Sciences, Room Number: 265, Room Capacity: 140 - Course Name: CS 248, Course Size: 138
|
||||
Building Name: Bio Sciences, Room Number: 413, Room Capacity: 30 - Course Name: CS 386, Course Size: 28
|
||||
Building Name: Health & Learning Center, Room Number: 3101, Room Capacity: 65 - Course Name: CS 136, Course Size: 61
|
||||
Building Name: Health & Learning Center, Room Number: 3113, Room Capacity: 70 - Course Name: CS 112, Course Size: 69
|
||||
Building Name: Adel Mathematics Center, Room Number: 148, Room Capacity: 40 - Course Name: CS 110, Course Size: 39
|
||||
Building Name: Eastburn Education, Room Number: 124, Room Capacity: 50 - Course Name: CS 200, Course Size: 44
|
||||
Building Name: Raul H. Castro SBS, Room Number: 111, Room Capacity: 98 - Course Name: CS 301, Course Size: 95
|
||||
|
||||
End Course/Classroom Fit Program
|
||||
1576
PA04-0927/OutputFiles/Output_In4.txt
Normal file
1576
PA04-0927/OutputFiles/Output_In4.txt
Normal file
File diff suppressed because it is too large
Load diff
78802
PA04-0927/OutputFiles/Output_In5.txt
Normal file
78802
PA04-0927/OutputFiles/Output_In5.txt
Normal file
File diff suppressed because it is too large
Load diff
360165
PA04-0927/OutputFiles/Output_In6.txt
Normal file
360165
PA04-0927/OutputFiles/Output_In6.txt
Normal file
File diff suppressed because it is too large
Load diff
194
PA04-0927/PA04_Main.c
Normal file
194
PA04-0927/PA04_Main.c
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
// header files
|
||||
#include <string.h>
|
||||
#include "StandardConstants.h"
|
||||
#include "File_Input_Utility.h"
|
||||
#include "BasicUtilities.h"
|
||||
#include "CourseUtilities.h"
|
||||
#include "RoomUtilities.h"
|
||||
|
||||
// local constants
|
||||
const int MAX_NUM_ROOMS = 25;
|
||||
const int MAX_NUM_COURSES = 25;
|
||||
const int NO_CLASS = -1;
|
||||
|
||||
// local prototypes
|
||||
bool fitClassRooms( CourseArrayType *courseData,
|
||||
RoomArrayType *roomData, int initialRoomLevel, bool verboseFlag );
|
||||
bool uploadData( const char *fileName,
|
||||
CourseArrayType *courseData, RoomArrayType *roomData );
|
||||
|
||||
// main function
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int initialRoomLevel = 0;
|
||||
RoomArrayType *rooms;
|
||||
CourseArrayType *courses;
|
||||
bool verboseSetting = true;
|
||||
|
||||
printf( "\nCourse/Classroom Fit Program\n" );
|
||||
printf( "============================\n" );
|
||||
|
||||
rooms = createRoomArray( MAX_NUM_ROOMS );
|
||||
courses = createCourseArray( MAX_NUM_COURSES );
|
||||
|
||||
if( uploadData( "in_1.txt", courses, rooms ) )
|
||||
{
|
||||
printf( "Start Solution Search\n" );
|
||||
|
||||
if( fitClassRooms( courses, rooms, initialRoomLevel, verboseSetting ) )
|
||||
{
|
||||
printf( "\nFit Classroom Success: Solution Found.\n");
|
||||
|
||||
displayList( courses, rooms );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf( "\nFit Classroom Failure: Solution not found.\n");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf( "Upload failure\n" );
|
||||
}
|
||||
|
||||
// end program
|
||||
|
||||
// clear data
|
||||
rooms = clearRoomArray( rooms );
|
||||
courses = clearCourseArray( courses );
|
||||
|
||||
// show program end
|
||||
printf( "\nEnd Course/Classroom Fit Program\n" );
|
||||
|
||||
// return success
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: fitClassRooms
|
||||
Process: implements brute force recursive backtracking strategy
|
||||
to fit specified courses with their specified student size
|
||||
into classrooms with their specified capacity
|
||||
Function input/parameters: pointer to a courses array type (CourseArrayType *),
|
||||
pointer to a room array type (RoomArrayType *),
|
||||
room level shows which room is seeking a course
|
||||
and indicates the recursion level (int),
|
||||
verbose flag that specifies whether
|
||||
to display the recursive backtracking process (bool)
|
||||
Function output/parameters: updated courses file (CourseArrayType *),
|
||||
updated rooms file (RoomArrayType *)
|
||||
Function output/returned: Boolean result of the process (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: available tools as needed
|
||||
*/
|
||||
bool fitClassRooms( CourseArrayType *courses,
|
||||
RoomArrayType *rooms, int roomLevel, bool verboseFlag )
|
||||
{
|
||||
// TODO: Create recursive backtracking function
|
||||
// to find correct assignment of specified courses to available c Rooms
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: uploadData
|
||||
Process: uploads data file containing rooms available and courses to be fitted,
|
||||
has internal flag to show uploaded data or not
|
||||
Function input/parameters: file name (const char *),
|
||||
pointer to course array type (CourseArrayType*),
|
||||
pointer to room array type (RoomArrayType *)
|
||||
Function output/parameters: updated courses file (CourseArrayType *),
|
||||
updated rooms file (RoomArrayType *)
|
||||
Function output/returned: Boolean result of the process (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including File Input Utilities, and strcmp
|
||||
*/
|
||||
bool uploadData( const char *fileName,
|
||||
CourseArrayType *courseData, RoomArrayType *roomData )
|
||||
{
|
||||
char tempStr[ STD_STR_LEN ];
|
||||
int tempRoomNum, tempRoomCapacity, tempRoomAssociation = NO_CLASS;
|
||||
int tempClassSize, tempClassAvailable = true;
|
||||
bool verboseFlag = true;
|
||||
|
||||
roomData->size = 0;
|
||||
|
||||
if( openInputFile( fileName ) )
|
||||
{
|
||||
if( verboseFlag )
|
||||
{
|
||||
printf( "\n==========Upload start\n" );
|
||||
}
|
||||
|
||||
// ignore first line
|
||||
readStringToLineEndFromFile( tempStr );
|
||||
|
||||
// capture first room line - prime loop
|
||||
readStringToDelimiterFromFile( COMMA, tempStr );
|
||||
|
||||
// loop to end of room data
|
||||
while( strcmp( tempStr, "End Room Data" ) != 0
|
||||
&& roomData->size < roomData->capacity )
|
||||
{
|
||||
tempRoomNum = readIntegerFromFile();
|
||||
|
||||
readCharacterFromFile();
|
||||
|
||||
tempRoomCapacity = readIntegerFromFile();
|
||||
|
||||
if( verboseFlag )
|
||||
{
|
||||
printf( "Nm: %s, Num: %d, cap: %d\n",
|
||||
tempStr, tempRoomNum, tempRoomCapacity );
|
||||
}
|
||||
|
||||
addRoomWithData( roomData, tempStr,
|
||||
tempRoomNum, tempRoomCapacity, tempRoomAssociation );
|
||||
// reprime - capture next building name, or end of data string
|
||||
readStringToDelimiterFromFile( COMMA, tempStr );
|
||||
}
|
||||
|
||||
// initialize class size
|
||||
courseData->size = 0;
|
||||
|
||||
// ignore first line
|
||||
readStringToLineEndFromFile( tempStr );
|
||||
|
||||
// capture first course line - prime loop
|
||||
readStringToDelimiterFromFile( COMMA, tempStr );
|
||||
|
||||
// loop to end of course data
|
||||
while( strcmp( tempStr, "End Class Data" ) != 0
|
||||
&& courseData->size < courseData->capacity )
|
||||
{
|
||||
// get class size
|
||||
tempClassSize = readIntegerFromFile();
|
||||
|
||||
if( verboseFlag )
|
||||
{
|
||||
printf( "Nm: %s, sz: %d\n", tempStr, tempClassSize );
|
||||
}
|
||||
|
||||
addCourseWithData( courseData,
|
||||
tempStr, tempClassSize, tempClassAvailable );
|
||||
|
||||
// reprime - get next building name, or end of data string
|
||||
readStringToDelimiterFromFile( COMMA, tempStr );
|
||||
}
|
||||
|
||||
if( verboseFlag )
|
||||
{
|
||||
printf( "==========Upload end\n\n" );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
192
PA04-0927/RoomUtilities.c
Normal file
192
PA04-0927/RoomUtilities.c
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
// header file
|
||||
#include "RoomUtilities.h"
|
||||
|
||||
// function implementations
|
||||
|
||||
/*
|
||||
Name: clearRoomArray
|
||||
Process: frees RoomArrayType memory, along with array memory, returns NULL
|
||||
Function input/parameters: room array structure (const RoomArrayType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: NULL (RoomArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: free
|
||||
*/
|
||||
RoomArrayType *clearRoomArray( RoomArrayType *toClear )
|
||||
{
|
||||
free( toClear->array );
|
||||
|
||||
free( toClear );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: addRoomWithData
|
||||
Process: adds room data to array and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: room data array (RoomArrayType *),
|
||||
building name (const char *),
|
||||
room number, room capacity, associated index (int)
|
||||
Function output/parameters: updated room data array(RoomArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with copyString
|
||||
*/
|
||||
bool addRoomWithData( RoomArrayType *roomData, const char *buildingName,
|
||||
int roomNumber, int roomCapacity, int associatedIndex )
|
||||
{
|
||||
if( roomData->size < roomData->capacity )
|
||||
{
|
||||
copyString( roomData->array[ roomData->size ].buildingName,
|
||||
buildingName );
|
||||
roomData->array[ roomData->size ].roomNumber = roomNumber;
|
||||
roomData->array[ roomData->size ].roomCapacity = roomCapacity;
|
||||
roomData->array[ roomData->size ].associatedIndex = associatedIndex;
|
||||
|
||||
roomData->size = roomData->size + 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: addRoomFromRoom
|
||||
Process: adds room data to array from other room and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: room data array (RoomArrayType *)
|
||||
Function output/parameters: updated room data (RoomArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: setRoomWithData - one line of code
|
||||
*/
|
||||
bool addRoomFromRoom( RoomArrayType *destRoom, const RoomDataType srcRoom )
|
||||
{
|
||||
return addRoomWithData ( destRoom, srcRoom.buildingName, srcRoom.roomNumber,
|
||||
srcRoom.roomCapacity, srcRoom.associatedIndex );
|
||||
}
|
||||
|
||||
/*
|
||||
Name: compareRooms
|
||||
Process: compares two rooms first alphabetically by building name,
|
||||
and then numerically by room number, with the following results:
|
||||
- if left room is greater than right room, returns positive number
|
||||
- if left room is less than right room, returns negative number
|
||||
- if rooms are the same, returns zero
|
||||
Function input/parameters: room data to be compared(const RoomDataType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified comparison (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with compareStrings
|
||||
*/
|
||||
int compareRooms( const RoomDataType *leftRoom, const RoomDataType *rightRoom )
|
||||
{
|
||||
int strDiff
|
||||
= compareStrings( leftRoom->buildingName, rightRoom->buildingName );
|
||||
|
||||
if( strDiff == 0 )
|
||||
{
|
||||
return leftRoom->roomNumber - rightRoom->roomNumber;
|
||||
}
|
||||
|
||||
return strDiff;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: createRoomArray
|
||||
Process: allocates memory for RoomArrayType, and internal array,
|
||||
returns pointer to array type
|
||||
Function input/parameters: array capacity (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: pointer to room array (RoomArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: malloc, with keyword sizeof
|
||||
*/
|
||||
RoomArrayType *createRoomArray( int initCapacity )
|
||||
{
|
||||
RoomArrayType *newArray
|
||||
= (RoomArrayType *)malloc( sizeof( RoomArrayType ) );
|
||||
|
||||
newArray->array
|
||||
= (RoomDataType *)malloc( initCapacity * sizeof( RoomDataType ) );
|
||||
|
||||
newArray->capacity = initCapacity;
|
||||
|
||||
newArray->size = 0;
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: deepCopyRoom
|
||||
Process: copies source room data into destination room
|
||||
Function input/parameters: source room data (const RoomDataType)
|
||||
Function output/parameters: destination room data (RoomDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with copyString
|
||||
*/
|
||||
void deepCopyRoom( RoomDataType *destRoom, const RoomDataType srcRoom )
|
||||
{
|
||||
copyString( destRoom->buildingName, srcRoom.buildingName );
|
||||
destRoom->roomNumber = srcRoom.roomNumber;
|
||||
destRoom->roomCapacity = srcRoom.roomCapacity;
|
||||
destRoom->associatedIndex = srcRoom.associatedIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: displayList
|
||||
Process: displays rooms with associated courses
|
||||
Function input/parameters: pointer to course array (const CourseArrayType *)
|
||||
Function output/parameters: pointer to room array (const RoomArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including printf, setCourseDataString
|
||||
*/
|
||||
void displayList( const CourseArrayType *courses, const RoomArrayType *rooms )
|
||||
{
|
||||
int roomIndex, courseIndex;
|
||||
char roomStr[ MAX_STR_LEN ], courseStr[ STD_STR_LEN ];
|
||||
|
||||
printf( "\nClassroom/Course Request Fit List\n" );
|
||||
printf( "=================================\n" );
|
||||
|
||||
for( roomIndex = 0; roomIndex < rooms->size; roomIndex++ )
|
||||
{
|
||||
setRoomDataString( roomStr, rooms->array[ roomIndex ] );
|
||||
|
||||
courseIndex = rooms->array[ roomIndex ].associatedIndex;
|
||||
|
||||
setCourseDataString( courseStr, courses->array[ courseIndex ] );
|
||||
|
||||
printf( "%s - %s\n", roomStr, courseStr );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Name: setRoomDataString
|
||||
Process: load room data into string, in format:
|
||||
"Building Name: <building name>, Room Number: <room number>,
|
||||
Room Capacity: <room capacity>"
|
||||
Function input/parameters: room data (const RoomDataType)
|
||||
Function output/parameters: loaded c-style string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including sprintf
|
||||
*/
|
||||
void setRoomDataString( char *dataStr, const RoomDataType roomData )
|
||||
{
|
||||
sprintf( dataStr, "Building Name: %s, Room Number: %d, Room Capacity: %3d",
|
||||
roomData.buildingName, roomData.roomNumber, roomData.roomCapacity );
|
||||
}
|
||||
|
||||
139
PA04-0927/RoomUtilities.h
Normal file
139
PA04-0927/RoomUtilities.h
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#ifndef ROOM_UTILITIES_H
|
||||
#define ROOM_UTILITIES_H
|
||||
|
||||
// header files
|
||||
#include <string.h>
|
||||
#include "StandardConstants.h"
|
||||
#include "BasicUtilities.h"
|
||||
#include "CourseUtilities.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// data structure
|
||||
typedef struct RoomDataStruct
|
||||
{
|
||||
char buildingName[ STD_STR_LEN ];
|
||||
int roomNumber;
|
||||
int roomCapacity;
|
||||
int associatedIndex;
|
||||
} RoomDataType;
|
||||
|
||||
typedef struct RoomArrayStruct
|
||||
{
|
||||
RoomDataType *array;
|
||||
|
||||
int size, capacity;
|
||||
} RoomArrayType;
|
||||
|
||||
// function prototoypes
|
||||
|
||||
/*
|
||||
Name: clearRoomArray
|
||||
Process: frees RoomArrayType memory, along with array memory, returns NULL
|
||||
Function input/parameters: room array structure (const RoomArrayType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: NULL (RoomArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: free
|
||||
*/
|
||||
RoomArrayType *clearRoomArray( RoomArrayType *toClear );
|
||||
|
||||
/*
|
||||
Name: addRoomWithData
|
||||
Process: adds room data to array and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: room data array (RoomArrayType *),
|
||||
building name (const char *),
|
||||
room number, room capacity, associated index (int)
|
||||
Function output/parameters: updated room data array(RoomArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with copyString
|
||||
*/
|
||||
bool addRoomWithData( RoomArrayType *roomData, const char *buildingName,
|
||||
int roomNumber, int roomCapacity, int associatedIndex );
|
||||
|
||||
/*
|
||||
Name: addRoomFromRoom
|
||||
Process: adds room data to array from other room and returns true,
|
||||
returns false if array is full
|
||||
Function input/parameters: room data array (RoomArrayType *)
|
||||
Function output/parameters: updated room data (RoomArrayType *)
|
||||
Function output/returned: Boolean result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: setRoomWithData - one line of code
|
||||
*/
|
||||
bool addRoomFromRoom( RoomArrayType *destRoom, const RoomDataType srcRoom );
|
||||
|
||||
/*
|
||||
Name: compareRooms
|
||||
Process: compares two rooms first alphabetically by building name,
|
||||
and then numerically by room number, with the following results:
|
||||
- if left room is greater than right room, returns positive number
|
||||
- if left room is less than right room, returns negative number
|
||||
- if rooms are the same, returns zero
|
||||
Function input/parameters: room data to be compared(const RoomDataType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified comparison (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with compareStrings
|
||||
*/
|
||||
int compareRooms( const RoomDataType *leftRoom, const RoomDataType *rightRoom );
|
||||
|
||||
/*
|
||||
Name: createRoomArray
|
||||
Process: allocates memory for RoomArrayType, and internal array,
|
||||
returns pointer to array type
|
||||
Function input/parameters: array capacity (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: pointer to room array (RoomArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: malloc, with keyword sizeof
|
||||
*/
|
||||
RoomArrayType *createRoomArray( int initCapacity );
|
||||
|
||||
/*
|
||||
Name: deepCopyRoom
|
||||
Process: copies source room data into destination room
|
||||
Function input/parameters: source room data (const RoomDataType)
|
||||
Function output/parameters: destination room data (RoomDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, with copyString
|
||||
*/
|
||||
void deepCopyRoom( RoomDataType *destRoom, const RoomDataType srcRoom );
|
||||
|
||||
/*
|
||||
Name: displayList
|
||||
Process: displays rooms with associated courses
|
||||
Function input/parameters: pointer to course array (const CourseArrayType *)
|
||||
Function output/parameters: pointer to room array (const RoomArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including printf, setCourseDataString
|
||||
*/
|
||||
void displayList( const CourseArrayType *courses, const RoomArrayType *rooms );
|
||||
|
||||
/*
|
||||
Name: setRoomDataString
|
||||
Process: load room data into string, in format:
|
||||
"Building Name: <building name>, Room Number: <room number>,
|
||||
Room Capacity: <room capacity>"
|
||||
Function input/parameters: room data (const RoomDataType)
|
||||
Function output/parameters: loaded c-style string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including sprintf
|
||||
*/
|
||||
void setRoomDataString( char *dataStr, const RoomDataType roomData );
|
||||
|
||||
|
||||
#endif // ROOM_UTILITIES_H
|
||||
73
PA04-0927/StandardConstants.h
Normal file
73
PA04-0927/StandardConstants.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// Preprocessor directives
|
||||
#ifndef STANDARD_CONSTANTS_H
|
||||
#define STANDARD_CONSTANTS_H
|
||||
|
||||
// Include Boolean
|
||||
#include <stdbool.h>
|
||||
|
||||
// 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 '-'
|
||||
|
||||
// highest printable character
|
||||
#define HIGHEST_PRINTABLE_CHAR '~'
|
||||
|
||||
// constant for huge string length
|
||||
#define HUGE_STR_LEN 256
|
||||
|
||||
// lowest printable character
|
||||
#define LOWEST_PRINTABLE_CHAR ' '
|
||||
|
||||
// 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 NEWLINE_CHAR '\n'
|
||||
|
||||
// first non-printable above ASCII
|
||||
#define DELETE_KEY 127
|
||||
|
||||
// constant for end of c-string null character
|
||||
#define NULL_CHAR '\0'
|
||||
|
||||
// columns found in grade sheet before grading columns
|
||||
#define NUM_BASE_COLS 5
|
||||
|
||||
// constant for number of grading frequency bins
|
||||
#define NUM_FREQUENCY_BINS 10
|
||||
|
||||
//Constant for printing a pipe
|
||||
#define PIPE '|'
|
||||
|
||||
//Constant for a period
|
||||
#define PERIOD '.'
|
||||
|
||||
//Constant for PRECISION, 2 digits
|
||||
#define PRECISION_2 2
|
||||
|
||||
//Constant for PRECISION, 4 digits
|
||||
#define PRECISION_4 4
|
||||
|
||||
// constant for space character
|
||||
#define SPACE ' '
|
||||
|
||||
// constant for standard string length
|
||||
#define STD_STR_LEN 64
|
||||
|
||||
// constant for smallest string length
|
||||
#define TINY_STR_LEN 16
|
||||
|
||||
#endif // STANDARD_CONSTANTS
|
||||
Loading…
Add table
Add a link
Reference in a new issue