Initialize Project 3, Include STUB functions
++ PA03 files ++ Makefile for PA03
This commit is contained in:
parent
1169a2607e
commit
ff284efcf5
11 changed files with 3506 additions and 0 deletions
321
PA03-0920/StateUtilities_LogN.h
Normal file
321
PA03-0920/StateUtilities_LogN.h
Normal file
|
|
@ -0,0 +1,321 @@
|
|||
#ifndef STATE_UTILITIES_LOGN_H
|
||||
#define STATE_UTILITIES_LOGN_H
|
||||
|
||||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "Console_IO_Utility.h"
|
||||
#include "File_Input_Utility.h"
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// global constants
|
||||
|
||||
// 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;
|
||||
|
||||
// Prototypes
|
||||
|
||||
/*
|
||||
Name: addElementFromData
|
||||
Process: adds all individual data values to StateDataType array,
|
||||
must check for resize before adding new element
|
||||
Function input/parameters: pointer to data array type (StateArrayType *),
|
||||
state name (const char *),
|
||||
state population (int),
|
||||
state growth (double),
|
||||
state political majority (char)
|
||||
Function output/parameters: updated data array (StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including strcpy
|
||||
*/
|
||||
void addElementFromData( StateArrayType *stateArr,
|
||||
const char *stateName, int statePop,
|
||||
double stateGrowth, char politicalMajority );
|
||||
|
||||
/*
|
||||
Name: addElementFromElement
|
||||
Process: adds data from element to StateDataType array,
|
||||
uses supporting function
|
||||
Function input/parameters: data array type (StateArrayType *)
|
||||
source element (const StateDataType)
|
||||
Function output/parameters: updated data array (StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: addElementFromData - function uses one code statement
|
||||
*/
|
||||
void addElementFromElement( StateArrayType *stateArr,
|
||||
const StateDataType state );
|
||||
|
||||
/*
|
||||
Name: checkForResize
|
||||
Process: checks if array needs to be resized,
|
||||
resizes (increases capacity of) array to double capacity
|
||||
and moves data from previous array into new one
|
||||
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 ADT is unchanged
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including malloc, free, keyword sizeof
|
||||
*/
|
||||
void checkForResize( StateArrayType *stateArray );
|
||||
|
||||
/*
|
||||
Name: clearStateArrayType
|
||||
Process: deallocates dynamically allocated array from memory,
|
||||
deallocates dynamically allocated state data type,
|
||||
returns NULL
|
||||
Function input/parameters: data array (StateDataType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: NULL
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including free
|
||||
*/
|
||||
StateArrayType *clearStateArrayType( StateArrayType *stateArray );
|
||||
|
||||
/*
|
||||
Name: copyArrayType
|
||||
Process: copies state data array type from one array type to another
|
||||
Function input/parameters: source array (const StateArrayType)
|
||||
Function output/parameters: pointer to destination array (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void copyArrayType( StateArrayType *dest, const StateArrayType src );
|
||||
|
||||
/*
|
||||
Name: createStateArrayType
|
||||
Process: dynamically allocates memory for array type,
|
||||
dynamically allocates memory for array,
|
||||
initializes size and capacity
|
||||
Function input/parameters: initial capacity (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: pointer to newly created array type (StateArrayType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including function malloc and keyword sizeof
|
||||
*/
|
||||
StateArrayType *createStateArrayType( int initialCapacity );
|
||||
|
||||
/*
|
||||
Name: deepCopy
|
||||
Process: copies all individual values from StateDataType source
|
||||
to StateDataType destination
|
||||
Function input/parameters: source element (const StateDataType)
|
||||
Function output/parameters: pointer to destination value (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed, including strcpy
|
||||
*/
|
||||
void deepCopy( StateDataType *dest, const StateDataType src );
|
||||
|
||||
/*
|
||||
Name: displayData
|
||||
Process: displays element data in array type as table
|
||||
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 data 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: as needed
|
||||
*/
|
||||
void displayData( const StateArrayType arrayType, const char *subTitle );
|
||||
|
||||
/*
|
||||
Name: reverseArray
|
||||
Process: reverses values in array
|
||||
Function input/parameters: pointer to state array type (StateArrayType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void reverseArray( StateArrayType *stateArray );
|
||||
|
||||
/*
|
||||
Name: runMerge
|
||||
Process: merges StateArrayType ADT subsets brought in between a low, middle,
|
||||
and high index segment of the StateArrayType ADT,
|
||||
must dynamically create (and release) one internal array
|
||||
must use three array transfer loops
|
||||
Function input/parameters: pointer to state array type (StateArrayType *),
|
||||
low index, middle index, high index (int)
|
||||
Function output/parameters: pointer to updated state array type
|
||||
(StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void runMerge( StateArrayType *stateArray,
|
||||
int lowIndex, int middleIndex, int highIndex );
|
||||
|
||||
/*
|
||||
Name: runMergeSortByName
|
||||
Process: sorts StateArrayType ADT using merge sort algorithm,
|
||||
calls helper function with appropriate indices
|
||||
Function input/parameters: pointer to state array type (StateArrayType *)
|
||||
Function output/parameters: pointer to updated state array type
|
||||
(StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void runMergeSortByName( StateArrayType *stateArray );
|
||||
|
||||
/*
|
||||
Name: runMergeSortHelper
|
||||
Process: recursively breaks given StateArrayType ADT segments down
|
||||
to smaller segments between lowIndex and highIndex (inclusive),
|
||||
then sorts data using merge operation for segments created
|
||||
Function input/parameters: pointer to state array type (StateArrayType *),
|
||||
low & high inclusive indices (int)
|
||||
Function output/parameters: pointer to updated state array type
|
||||
(StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void runMergeSortHelper( StateArrayType *stateArray,
|
||||
int lowIndex, int highIndex );
|
||||
|
||||
/*
|
||||
Name: runPartition
|
||||
Process: partitions StateArrayType ADT
|
||||
must use the first value as the partition value;
|
||||
when this function is complete the partition value is
|
||||
in the correct location in the array;
|
||||
main loop must iterate from left to right
|
||||
Function input/parameters: pointer to state array type (StateArrayType *)
|
||||
Function output/parameters: pointer to updated state array type
|
||||
(StateArrayType *)
|
||||
Function output/returned: partition value index within array
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
int runPartition( StateArrayType *stateArray, int lowIndex, int highIndex );
|
||||
|
||||
/*
|
||||
Name: runQuickSortByPopulation
|
||||
Process: sorts StateArrayType ADT using quick sort algorithm,
|
||||
calls helper with appropriate indices to implement sort
|
||||
Function input/parameters: pointer to state array type (StateArrayType *)
|
||||
Function output/parameters: pointer to updated state array type
|
||||
(StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void runQuickSortByPopulation( StateArrayType *stateArray );
|
||||
|
||||
/*
|
||||
Name: runQuickSortHelper
|
||||
Process: helper function run with parameters that partition arrays
|
||||
on a given (first) element of an array segment,
|
||||
then recursively sort left and right sides of given partition value
|
||||
Function input/parameters: pointer to state array type (StateArrayType *)
|
||||
low & high inclusive indices (int)
|
||||
Function output/parameters: pointer to updated state array type
|
||||
(StateArrayType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void runQuickSortHelper( StateArrayType *stateArray,
|
||||
int lowIndex, int highIndex );
|
||||
|
||||
/*
|
||||
Name: setEmptyElementData
|
||||
Process: sets state data type to empty or default values,
|
||||
name to empty string, population and growth to zero,
|
||||
and majority to 'x'
|
||||
Function input/parameters: none
|
||||
Function output/parameters: state data value (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
void setEmptyElementData( StateDataType *element );
|
||||
|
||||
/*
|
||||
Name: showTitle
|
||||
Process: displays program title with thick underline,
|
||||
"Data Management with Log N Sorting"
|
||||
Function input/parameters: none
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: displays title as specified
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void showTitle();
|
||||
|
||||
/*
|
||||
Name: swapElements
|
||||
Process: swaps state data elements within an array
|
||||
Function input/parameters: given array (StateDataType *),
|
||||
left and right indices to be swapped (int)
|
||||
Function output/parameters: updated array with swapped values (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
void swapElements( StateDataType *array, int leftIndex, int rightIndex );
|
||||
|
||||
/*
|
||||
Name: uploadStateData
|
||||
Process: uploads data from given file to state data array,
|
||||
ignores first (title) line in .csv file,
|
||||
then captures comma-delimited state name, population, growth,
|
||||
and political majority data on each row,
|
||||
returns true if upload successful, false otherwise
|
||||
Function input/parameters: file name (const char *)
|
||||
Function output/parameters: updated array with uploaded values (StateDataType *)
|
||||
Function output/returned: Boolean result of upload operation
|
||||
Device input/HD: data uploaded from text file as specified
|
||||
Device output/---: none
|
||||
Dependencies: as needed
|
||||
*/
|
||||
bool uploadStateData( StateArrayType *arrayType, const char *fileName );
|
||||
|
||||
#endif // STATE_UTILITIES_LOGN_H
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue