diff --git a/PA05-1004/ArrayDataEngine.c b/PA05-1004/ArrayDataEngine.c new file mode 100644 index 0000000..645b8df --- /dev/null +++ b/PA05-1004/ArrayDataEngine.c @@ -0,0 +1,257 @@ +// header files +#include "ArrayDataEngine.h" + +/* Data Structures +typedef struct StateDataStruct + { + char name[ STD_STR_LEN ]; + + int population; + + double growth; + + char majority; + } StateDataType; + +typedef struct StateArrayStruct + { + StateDataType *array; + + int size, capacity; + } StateArrayType; +Data Structures */ + +// function implementations + +/* +Name: clearDataStructure +Process: deallocates memory for the array data structure + and encapsulated state data, + returns NULL to calling function +Function input/parameters: pointer to state data array (StateDataArray *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: free +*/ +StateArrayType *clearDataStructure( StateArrayType *arrayPtr ) +{ + // return NULL + return NULL; +} + +/* +Name: copyDataList +Process: copies elements from one state data array to another + resets array size as needed, + also resets array capacity as needed if destination array type + capacity is less than capacity of source array type +Function input/parameters: source state data array type (StateArrayType *) +Function output/parameters: pointer to destination state data array type + (StateArrayType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: privateCheckForResize, deepCopyData +*/ +void copyDataList( StateArrayType *dest, const StateArrayType src ) +{ + // no return, void +} + +/* +Name: createDataStructure +Process: dynamically creates instance of state array type + along with dynamically allocating the state data array within it +Function input/parameters: given initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to state array type (StateArrayType *) +Device input/---: none +Device output/---: none +Dependencies: malloc, sizeof (C keyword) +*/ +StateArrayType *createDataStructure( int initialCapacity ) +{ + // return stateArrayType + return NULL; +} + +/* +Name: deepCopyData +Process: copies all members of a StateDataType item into another one +Function input/parameters: state data type item (const StateDataType ) +Function output/parameters: pointer to state data item (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: privateCopyString +*/ +void deepCopyData( StateDataType *dest, const StateDataType src ) +{ + // no return, void +} + +/* +Name: displayData +Process: displays comma-delimited data items in array if array is not empty, + otherwise displays "Data not found - Display aborted", + allows for subtitle to be added to "Display Data - " +Function input/parameters: state array type (const StateArrayType), + subtitle (const char *) +Function output/parameters: none +Function output/returned: none +Device input/---: none +Device output/monitor: data displayed as specified +Dependencies: printf, listIsEmpty +*/ +void displayData( const StateArrayType stateData, const char *subTitle ) +{ + // no return, void +} + +/* +Name: getItemAtIndex +Process: checks for index within bounds, + acquires and returns the value as a parameter, + and returns true, + otherwise sets data in parameter to empty and returns false +Function input/parameters: state array type (const StateArrayType), + list index (int) +Function output/parameters: value if found, + otherwise, value set to empty (StateDataType *) +Function output/returned: Boolean result of operation (bool) +Device input/---: none +Device output/---: none +Dependencies: deepCopyData, setItemToEmpty +*/ +bool getItemAtIndex( StateDataType *returnVal, + const StateArrayType stateData, int listIndex ) +{ + // return false (TEMP) + return false; +} + +/* +Name: getListSize +Process: provides the size of the list +Function input/parameters: state array type (const StateArrayType) +Function output/parameters: none +Function output/returned: size of the list (int) +Device input/---: none +Device output/---: none +Dependencies: none +*/ +int getListSize( const StateArrayType stateData ) +{ + // return 0 (TEMP) + return 0; +} + +/* +Name: insertItemAtIndex +Process: checks for index in bounds, inserts item at index, returns true, + resizes array as needed, + if index not in bounds, returns false +Function input/parameters: pointer to state array type (StateArrayType *), + StateDataType item to insert (const StateDataType), + index for insertion (int) +Function output/parameters: updated pointer to state array type + (StateArrayType *) +Function output/returned: Boolean result of specified process (bool) +Device input/---: none +Device output/---: none +Dependencies: checkForResize +*/ +bool insertItemAtIndex( StateArrayType *stateData, + StateDataType toBeInserted, int insertIndex ) +{ + // return false (TEMP) +} + +/* +Name: listIsEmpty +Process: returns true if list is empty, false otherwise +Function input/parameters: state array type (const StateArrayType) +Function output/parameters: none +Function output/returned: Boolean result of test as specified (bool) +Device input/---: none +Device output/---: none +Dependencies: none +*/ +bool listIsEmpty( const StateArrayType array ) +{ + // return false (TEMP) +} + +/* +Name: privateCheckForResize +Process: checks if array needs to be resized, + resizes (increases capacity of) array to double current capacity +Function input/parameters: pointer to state array type (StateArrayType *) +Function output/parameters: updated pointer + to state array type (StateArrayType *) + if resize has taken place, + otherwise array type is unchanged +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: malloc, sizeof (C keyword), deepCopyData, free +*/ +void privateCheckForResize( StateArrayType *stateData ) +{ + // no return, void +} + +/* +Name: privateCopyString +Process: copies string character for character up to NULL_CHAR of source string +Function input/parameters: source string to be copied (const char *) +Function output/parameters: destination string (char *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: none +*/ +void privateCopyString( char *dest, const char *src ) +{ + // no return, void +} + +/* +Name: removeItemAtIndex +Process: removes from array at index, shifts data down as needed, + returns true if found, false otherwise +Function input/parameters: pointer to state array type (StateArrayType *), + index to remove (int) +Function output/parameters: pointer to updated state array type + (StateArrayType *), + pointer to removed item (StateDataType *) +Function output/returned: Boolean result of removal operation (bool) +Device input/---: none +Device output/---: none +Dependencies: none +*/ +bool removeItemAtIndex( StateArrayType *stateData, + StateDataType *removedItem, int removeIndex ) +{ + // return false (TEMP) + return false; +} + +/* +Name: setItemToEmpty +Process: sets state data type struct to empty or default values, + including empty string and majority 'x' +Function input/parameters: pointer to state data value (StateDataType *) +Function output/parameters: pointer to updated state data value + (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: none +*/ +void setItemToEmpty( StateDataType *data ) +{ + // no return, void +} \ No newline at end of file diff --git a/PA05-1004/IteratorUtility.c b/PA05-1004/IteratorUtility.c new file mode 100644 index 0000000..9ac5c05 --- /dev/null +++ b/PA05-1004/IteratorUtility.c @@ -0,0 +1,171 @@ +// header files +#include "IteratorUtility.h" + +/* Data Structures +typedef struct IteratorStruct + { + StateArrayType *iterData; + + int currentIndex; + } IteratorType; +Data Structures */ + +// function implementation + +/* +Name: clearIterator +Process: clears the StateDataType sub-structure, and then the IteratorType +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: clearDataStructure, free +*/ +IteratorType *clearIterator( IteratorType *iterator ) +{ + // return NULL + return NULL; +} + +/* +Name: createIterator +Process: initializes the IteratorType, + and then the StateDataType sub-structure +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to initialized IteratorType (IteratorType *) +Device input/---: none +Device output/---: none +Dependencies: malloc, createDataStructure +*/ +IteratorType *createIterator( int initialCapacity ) +{ + // return IteratorType + return NULL; +} + +/* +Name: getFirst +Process: gets first value in iterator, returns true, + returns false otherwise +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex +*/ +bool getFirst( IteratorType *iterator, StateDataType *returned ) +{ + // return false (TEMP) + return false; +} + +/* +Name: getLast +Process: gets last value in iterator, returns true, + returns false otherwise +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool getLast( IteratorType *iterator, StateDataType *returned ) +{ + // return false (TEMP) + return false; +} + +/* +Name: getNext +Process: gets next value in iterator if available, returns true, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool getNext( IteratorType *iterator, StateDataType *returned ) +{ + // return false (TEMP) + return false; +} + +/* +Name: getPrevious +Process: gets previous value in iterator if available, returns true, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex +*/ +bool getPrevious( IteratorType *iterator, StateDataType *returned ) +{ + // return false (TEMP) + return false; +} + +/* +Name: insertAfterCurrentIndex +Process: inserts value immediately after currentIndex, if possible, returns true, + otherwise, returns false +Function input/parameters: pointer to IteratorType (IteratorType *), + value to be inserted (const StateDataType) +Function output/parameters: none +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex, getListSize +*/ +bool insertAfterCurrentIndex( IteratorType *iterator, + const StateDataType toBeInserted ) +{ + // return false (TEMP) + return false; +} + +/* +Name: insertAtCurrentIndex +Process: inserts value at currentIndex, if possible, returns true + otherwise, returns false +Function input/parameters: pointer to IteratorType (IteratorType *), + value to be inserted (const StateDataType) +Function output/parameters: none +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex +*/ +bool insertAtCurrentIndex( IteratorType *iterator, + const StateDataType toBeInserted ) +{ + // return false (TEMP) + return false; +} + +/* +Name: removeAtCurrentIndex +Process: removes value at current index if possible, returns true, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to IteratorType (IteratorType *), + value to be remove (StateDataType *) +Function output/parameters: pointer to updated IteratorType (IteratorType *), + pointer to item removed (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: removeItemAtIndex, getListSize +*/ +bool removeAtCurrentIndex( IteratorType *iterator, StateDataType *removedItem ) +{ + // return false (TEMP) + return false; +} \ No newline at end of file diff --git a/PA05-1004/Makefile b/PA05-1004/Makefile index e18051c..62901a1 100644 --- a/PA05-1004/Makefile +++ b/PA05-1004/Makefile @@ -1,25 +1,28 @@ CC = gcc -Wall -SOURCES = PA04_Main.c BasicUtilities.c RoomUtilities.c CourseUtilities.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c -OBJECTS = PA04_Main.o BasicUtilities.o RoomUtilities.o CourseUtilities.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o +SOURCES = PA05_Main.c ArrayDataEngine.c IteratorUtility.c QueueUtility.c StackUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c +OBJECTS = PA05_Main.o ArrayDataEngine.o IteratorUtility.o QueueUtility.o StackUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o # Uses the template structure defined in the TypicalUtils folder -all: PA04_Main +all: PA05_Main -PA04_Main: $(OBJECTS) - $(CC) $(OBJECTS) -o PA04_Main +PA05_Main: $(OBJECTS) + $(CC) $(OBJECTS) -o PA05_Main -PA04_Main.o: PA04_Main.c - $(CC) -c PA04_Main.c -o PA04_Main.o +PA05_Main.o: PA05_Main.c + $(CC) -c PA05_Main.c -o PA05_Main.o -BasicUtilities.o: BasicUtilities.c - $(CC) -c BasicUtilities.c -o BasicUtilities.o +ArrayDataEngine.o: ArrayDataEngine.c + $(CC) -c ArrayDataEngine.c -o ArrayDataEngine.o -CourseUtilities.o: CourseUtilities.c - $(CC) -c CourseUtilities.c -o CourseUtilities.o +QueueUtility.o: QueueUtility.c + $(CC) -c QueueUtility.c -o QueueUtility.o -RoomUtilities.o: RoomUtilities.c - $(CC) -c RoomUtilities.c -o RoomUtilities.o +IteratorUtility.o: IteratorUtility.c + $(CC) -c IteratorUtility.c -o IteratorUtility.o + +StackUtility.o: StackUtility.c + $(CC) -c StackUtility.c -o StackUtility.o Console_IO_Utility.o: Console_IO_Utility.c $(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o @@ -31,13 +34,13 @@ 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 + rm -f $(OBJECTS) PA05_Main PA05_Main.out clean_objects: rm -f $(OBJECTS) run: - ./PA04_Main + ./PA05_Main run_win: - PA04_Main + PA05_Main diff --git a/PA05-1004/QueueUtility.c b/PA05-1004/QueueUtility.c new file mode 100644 index 0000000..cc3258f --- /dev/null +++ b/PA05-1004/QueueUtility.c @@ -0,0 +1,99 @@ +// header files +#include "QueueUtility.h" + +/* Data Structures +typedef struct StateArrayStruct + { + StateDataType *array; + + int size, capacity; + } QueueType; (aka StateArrayType) +Data Structures*/ + +// function implementations + +/* +Name: clearQueue +Process: clears QueueType, returns NULL +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: clearDataStructure +*/ +QueueType *clearQueue( QueueType *queue ) +{ + // return NULL + return NULL; +} + +/* +Name: createQueue +Process: creates QueueType, initializes front index to zero, + rear index to -1, returns pointer to data structure +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to queue type (QueueType *) +Device input/---: none +Device output/---: none +Dependencies: createDataStructure +*/ +QueueType *createQueue( int initialCapacity ) +{ + // return QueueType + return NULL; +} + +/* +Name: peekFront +Process: captures value at front of queue + returns true if successful and sets return value, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool peekFront( StateDataType *returnVal, const QueueType queue ) +{ + // return false (TEMP) + return false; +} + +/* +Name: dequeue +Process: captures value at front of queue, removes and returns value, + returns true if successful, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: removeItemAtIndex, getListSize +*/ +bool dequeue( StateDataType *returnVal, QueueType *queue ) +{ + // return false (TEMP) + return false; +} + +/* +Name: enqueue +Process: sets value at rear of queue + returns true if successful, false otherwise +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: value to be pushed (const StateDataType) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex +*/ +bool enqueue( QueueType *queue, const StateDataType toBePushed ) +{ + // return false (TEMP) + return false; +} \ No newline at end of file diff --git a/PA05-1004/StackUtility.c b/PA05-1004/StackUtility.c new file mode 100644 index 0000000..799145c --- /dev/null +++ b/PA05-1004/StackUtility.c @@ -0,0 +1,95 @@ +// header files +#include "StackUtility.h" + +/* Data Structures +typedef struct StateArrayStruct + { + StateDataType *array; + + int size, capacity; + } StackType; (aka StateArrayType) +Data Structures*/ + +// function implementations + +/* +Name: clearStack +Process: clears StackType, returns NULL +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: clearDataStructure +*/ +StackType *clearStack( StackType *stackData ) +{ + // return NULL + return NULL; +} + +/* +Name: createStack +Process: creates StackType, returns pointer to it +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to stack type (StackType *) +Device input/---: none +Device output/---: none +Dependencies: createDataStructure +*/ +StackType *createStack( int initialCapacity ) +{ + // return StackType + return NULL; +} + +/* +Name: peekTop +Process: captures value at top of stack, returns, + returns true if successful, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation (bool) +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool peekTop( StateDataType *returnVal, const StackType stackData ) +{ + // return false (TEMP) +} + +/* +Name: popStack +Process: captures value at top of stack, removes and returns, + returns true if successful, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: removeItemAtIndex, getListSize +*/ +bool popStack( StateDataType *returnVal, StackType *stackData ) +{ + // return false (TEMP) +} + +/* +Name: pushStack +Process: sets value at top of stack, + returns true if successful, false otherwise +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: value to be pushed (const StateDataType) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex, getListSize +*/ +bool pushStack( StackType *stackData, const StateDataType toBePushed ) +{ + // return false (TEMP) +} \ No newline at end of file