Started PA03 for real this time
+- Makefile for PA03 ++ PA03_Main ++ StateData.csv +- StateUtilities_LogN.c ++ outDebug
This commit is contained in:
parent
ff284efcf5
commit
7cebe82132
5 changed files with 149 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#include "StateUtilities.h"
|
||||
#include "StateUtilities_LogN.h"
|
||||
|
||||
// local constants
|
||||
const int NAME_BLOCK_SIZE = 16;
|
||||
|
|
@ -32,6 +32,24 @@ void addElementFromData( StateArrayType *stateArr,
|
|||
const char *stateName, int statePop,
|
||||
double stateGrowth, char politicalMajority )
|
||||
{
|
||||
printf("\nAdding Element(from data)\n");
|
||||
printf("\nSize is: %d\n", &stateArr->size);
|
||||
printf("\nCapacity is: %d\n", &stateArr->capacity);
|
||||
// check to see if the size will go over the capacity
|
||||
if(&stateArr->size < &stateArr->capacity)
|
||||
{
|
||||
printf("\nInside IF\n");
|
||||
// put in the data to the array
|
||||
// stateArr->array[stateArr.size] = parameter
|
||||
stateArr->array[&stateArr->size].population = statePop;
|
||||
stateArr->array[&stateArr->size].growth = stateGrowth;
|
||||
stateArr->array[&stateArr->size].majority = politicalMajority;
|
||||
// use strcpy(stateArr->array[stateArr.size].name, stateName)
|
||||
strcpy(stateArr->array[&stateArr->size].name, stateName);
|
||||
// increment size (stateArr.size = stateArr.size + 1)
|
||||
&stateArr->size = &stateArr->size + 1;
|
||||
printf("\nDONE IF\n");
|
||||
}
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +68,10 @@ Dependencies: addElementFromData - function uses one code statement
|
|||
void addElementFromElement( StateArrayType *stateArr,
|
||||
const StateDataType state )
|
||||
{
|
||||
printf("\nAdding Element\n");
|
||||
addElementFromData(stateArr, state.name, state.population,
|
||||
state.growth, state.majority);
|
||||
printf("\nAdded Element\n");
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +109,15 @@ Dependencies: as needed, including free
|
|||
*/
|
||||
StateArrayType *clearStateArrayType( StateArrayType *stateArray )
|
||||
{
|
||||
// return NULL (temporarily)
|
||||
int stateIterator;
|
||||
for(stateIterator = 0; stateIterator < stateArray->size; stateIterator++)
|
||||
{
|
||||
// free the states from memory
|
||||
free(&stateArray->array[stateIterator]);
|
||||
}
|
||||
// free the array in the stateArray
|
||||
free(stateArray);
|
||||
// return NULL once complete
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -304,6 +334,13 @@ Dependencies: none
|
|||
*/
|
||||
void setEmptyElementData( StateDataType *element )
|
||||
{
|
||||
// set the element's name to ""
|
||||
strcpy(element->name, "");
|
||||
// set the element's population and growth to 0
|
||||
element->population = 0;
|
||||
element->growth = 0.0;
|
||||
// set the element's majority to 'x'
|
||||
element->majority = 'x';
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -320,6 +357,14 @@ Dependencies: as needed
|
|||
*/
|
||||
void showTitle()
|
||||
{
|
||||
// use console io utilities to display the string
|
||||
printString("Data Management with Log N Sorting");
|
||||
// print endline
|
||||
printEndline();
|
||||
// use console io utilities to display 38 '='
|
||||
printCharacters(TITLE_LENGTH, EQUALS);
|
||||
// print an endline
|
||||
printEndline();
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -355,6 +400,45 @@ Dependencies: as needed
|
|||
*/
|
||||
bool uploadStateData( StateArrayType *arrayType, const char *fileName )
|
||||
{
|
||||
// setup a counter and other variables
|
||||
int stateNum = 0;
|
||||
StateDataType stateUpload;
|
||||
bool fileOpenCheck;
|
||||
char currentString[STD_STR_LEN];
|
||||
// int populationUpload;
|
||||
// double growthUpload;
|
||||
// char majorityUpload;
|
||||
// open file
|
||||
setEmptyElementData(&stateUpload);
|
||||
fileOpenCheck = openInputFile(fileName);
|
||||
if(fileOpenCheck)
|
||||
{
|
||||
// read in the four strings/starting line
|
||||
// (use readStringToLineEndFromFile)
|
||||
readStringToLineEndFromFile(currentString);
|
||||
while(!checkForEndOfInputFile())
|
||||
{
|
||||
// repeat these steps: (use readStringToDelimiterFromFile)
|
||||
// read in the state name, store
|
||||
readStringToDelimiterFromFile(COMMA, currentString);
|
||||
strcpy(stateUpload.name, currentString);
|
||||
// read in the population, store (cast from string to int)
|
||||
stateUpload.population = readIntegerFromFile();
|
||||
readCharacterFromFile();
|
||||
// read in the growth, store (cast from string to double)
|
||||
stateUpload.growth = readDoubleFromFile();
|
||||
// read in the majority, store
|
||||
readCharacterFromFile();
|
||||
stateUpload.majority = readCharacterFromFile();
|
||||
// use the addElementFromElement function to add the data to array
|
||||
printf("\nElement: %d uploaded\n", stateNum);
|
||||
stateNum = stateNum + 1;
|
||||
addElementFromElement(arrayType, stateUpload);
|
||||
// do until end of the file is reached.
|
||||
}
|
||||
// return true when completely finished
|
||||
return true;
|
||||
}
|
||||
// return false
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue