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,17 +1,17 @@
|
||||||
CC = gcc -Wall
|
CC = gcc -Wall
|
||||||
SOURCES = PA02_Main.c StateUtilities.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
SOURCES = PA03_Main.c StateUtilities_LogN.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
||||||
OBJECTS = PA02_Main.o StateUtilities.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
OBJECTS = PA03_Main.o StateUtilities_LogN.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
||||||
|
|
||||||
all: PA02_Main
|
all: PA03_Main
|
||||||
|
|
||||||
PA02_Main: $(OBJECTS)
|
PA03_Main: $(OBJECTS)
|
||||||
$(CC) $(OBJECTS) -o PA02_Main
|
$(CC) $(OBJECTS) -o PA03_Main
|
||||||
|
|
||||||
PA02_Main.o: PA02_Main.c
|
PA03_Main.o: PA03_Main.c
|
||||||
$(CC) -c PA02_Main.c -o PA02_Main.o
|
$(CC) -c PA03_Main.c -o PA03_Main.o
|
||||||
|
|
||||||
StateUtilities.o: StateUtilities.c
|
StateUtilities_LogN.o: StateUtilities_LogN.c
|
||||||
$(CC) -c StateUtilities.c -o StateUtilities.o
|
$(CC) -c StateUtilities_LogN.c -o StateUtilities_LogN.o
|
||||||
|
|
||||||
Console_IO_Utility.o: Console_IO_Utility.c
|
Console_IO_Utility.o: Console_IO_Utility.c
|
||||||
$(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o
|
$(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o
|
||||||
|
|
@ -23,13 +23,13 @@ File_Output_Utility.o: File_Output_Utility.c
|
||||||
$(CC) -c File_Output_Utility.c -o File_Output_Utility.o
|
$(CC) -c File_Output_Utility.c -o File_Output_Utility.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJECTS) PA02_Main PA02_Main.out
|
rm -f $(OBJECTS) PA03_Main PA03_Main.out
|
||||||
|
|
||||||
clean_objects:
|
clean_objects:
|
||||||
rm -f $(OBJECTS)
|
rm -f $(OBJECTS)
|
||||||
|
|
||||||
run:
|
run:
|
||||||
./PA02_Main
|
./PA03_Main
|
||||||
|
|
||||||
run_win:
|
run_win:
|
||||||
PA02_Main
|
PA03_Main
|
||||||
BIN
PA03-0920/PA03_Main
Executable file
BIN
PA03-0920/PA03_Main
Executable file
Binary file not shown.
51
PA03-0920/StateData.csv
Normal file
51
PA03-0920/StateData.csv
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
State,Population,Growth,Majority
|
||||||
|
North Carolina,10698973,0.0851,N
|
||||||
|
Texas,30029572,0.1336,R
|
||||||
|
Ohio,11756058,0.0222,N
|
||||||
|
Arkansas,3045637,0.0315,R
|
||||||
|
Mississippi,2940057,-0.002,R
|
||||||
|
Tennessee,7051339,0.0804,R
|
||||||
|
Missouri,6177957,0.0268,R
|
||||||
|
Alabama,5074296,0.0482,R
|
||||||
|
Arizona,7359197,0.104,N
|
||||||
|
Massachusetts,6981974,0.0677,D
|
||||||
|
Rhode Island,1093734,0.0405,D
|
||||||
|
Maine,1385340,0.0248,D
|
||||||
|
South Dakota,909824,0.0804,R
|
||||||
|
West Virginia,1775156,-0.0333,R
|
||||||
|
Delaware,1018396,0.0912,D
|
||||||
|
Florida,22244823,0.1239,N
|
||||||
|
New Jersey,9261699,0.0529,D
|
||||||
|
Utah,3380800,0.1505,R
|
||||||
|
Nebraska,1967923,0.068,R
|
||||||
|
South Carolina,5282634,0.0945,R
|
||||||
|
Wyoming,581381,0.0228,R
|
||||||
|
Georgia,10912876,0.0938,N
|
||||||
|
Oklahoma,4019800,0.052,R
|
||||||
|
Colorado,5839926,0.1257,D
|
||||||
|
Kentucky,4512310,0.0367,R
|
||||||
|
Washington,7785786,0.1241,D
|
||||||
|
Nevada,3177772,0.1268,N
|
||||||
|
Michigan,10034113,0.0191,N
|
||||||
|
Connecticut,3626205,0.0088,D
|
||||||
|
Wisconsin,5892539,0.0348,N
|
||||||
|
Louisiana,4590241,0.0266,R
|
||||||
|
Hawaii,1440196,0.0644,D
|
||||||
|
Virginia,8683619,0.072,D
|
||||||
|
New Mexico,2113344,0.0274,D
|
||||||
|
Oregon,4240137,0.0941,D
|
||||||
|
North Dakota,779261,0.1331,R
|
||||||
|
New Hampshire,1395231,0.0439,D
|
||||||
|
Pennsylvania,12972008,0.023,N
|
||||||
|
Kansas,2937150,0.0287,R
|
||||||
|
Minnesota,5717184,0.0696,N
|
||||||
|
Indiana,6833037,0.0441,R
|
||||||
|
Idaho,1939033,0.1434,R
|
||||||
|
Montana,1122867,0.0859,R
|
||||||
|
Alaska,733583,0.0314,R
|
||||||
|
Maryland,6164660,0.0645,D
|
||||||
|
Vermont,647064,0.0268,D
|
||||||
|
New York,19677151,0.0404,D
|
||||||
|
California,39029342,0.0571,D
|
||||||
|
Iowa,3200517,0.0447,R
|
||||||
|
Illinois,12582032,-0.0014,D
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "StateUtilities.h"
|
#include "StateUtilities_LogN.h"
|
||||||
|
|
||||||
// local constants
|
// local constants
|
||||||
const int NAME_BLOCK_SIZE = 16;
|
const int NAME_BLOCK_SIZE = 16;
|
||||||
|
|
@ -32,6 +32,24 @@ void addElementFromData( StateArrayType *stateArr,
|
||||||
const char *stateName, int statePop,
|
const char *stateName, int statePop,
|
||||||
double stateGrowth, char politicalMajority )
|
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
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,6 +68,10 @@ Dependencies: addElementFromData - function uses one code statement
|
||||||
void addElementFromElement( StateArrayType *stateArr,
|
void addElementFromElement( StateArrayType *stateArr,
|
||||||
const StateDataType state )
|
const StateDataType state )
|
||||||
{
|
{
|
||||||
|
printf("\nAdding Element\n");
|
||||||
|
addElementFromData(stateArr, state.name, state.population,
|
||||||
|
state.growth, state.majority);
|
||||||
|
printf("\nAdded Element\n");
|
||||||
// no return, void
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +109,15 @@ Dependencies: as needed, including free
|
||||||
*/
|
*/
|
||||||
StateArrayType *clearStateArrayType( StateArrayType *stateArray )
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,6 +334,13 @@ Dependencies: none
|
||||||
*/
|
*/
|
||||||
void setEmptyElementData( StateDataType *element )
|
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
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -320,6 +357,14 @@ Dependencies: as needed
|
||||||
*/
|
*/
|
||||||
void showTitle()
|
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
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,6 +400,45 @@ Dependencies: as needed
|
||||||
*/
|
*/
|
||||||
bool uploadStateData( StateArrayType *arrayType, const char *fileName )
|
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
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
PA03-0920/build/Debug/outDebug
Executable file
BIN
PA03-0920/build/Debug/outDebug
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue