Initialize PA02
++ PA02 Files (StateUtilities) ++ STD LEV Utils ++ Makefile (Copied from PA01)
This commit is contained in:
parent
5777809d47
commit
ee473c78b1
12 changed files with 3155 additions and 0 deletions
120
PA02-0913/PA02_Main.c
Normal file
120
PA02-0913/PA02_Main.c
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
// header file
|
||||
#include "Console_IO_Utility.h"
|
||||
#include "StateUtilities.h"
|
||||
|
||||
// local constants for program
|
||||
const int MAX_NUM_STATES = 50;
|
||||
|
||||
int main()
|
||||
{
|
||||
// initialize function/program
|
||||
|
||||
// initialize variables
|
||||
int wkgNumStates, sortingNumStates;
|
||||
int capacity = MAX_NUM_STATES;
|
||||
char fileName[ MIN_STR_LEN ];
|
||||
StateDataType *wkgArray, *sortingArray;
|
||||
StateDataType resultData, searchData, removeData;
|
||||
|
||||
// show title
|
||||
// function: showTitle
|
||||
showTitle();
|
||||
|
||||
// create input/working and sorting arrays
|
||||
wkgArray = createStateArray( MAX_NUM_STATES );
|
||||
sortingArray = createStateArray( MAX_NUM_STATES );
|
||||
|
||||
// set empty data - data items will only have the state name
|
||||
setEmptyElementData( &searchData );
|
||||
strcpy( searchData.name, "North Dakota" );
|
||||
|
||||
setEmptyElementData( &removeData );
|
||||
strcpy( removeData.name, "Wyoming" );
|
||||
|
||||
// get input
|
||||
|
||||
// get file name
|
||||
// function: getFileName
|
||||
promptForString( "Enter file name: ", fileName );
|
||||
|
||||
// upload state data
|
||||
// function: uploadstateData
|
||||
wkgNumStates = uploadStateData( wkgArray, capacity, fileName );
|
||||
|
||||
if( wkgNumStates > 0 )
|
||||
{
|
||||
// make copy of working array for later sorting use
|
||||
sortingNumStates = wkgNumStates;
|
||||
copyArray( sortingArray, wkgArray, sortingNumStates );
|
||||
|
||||
// process and display data
|
||||
|
||||
// display original list
|
||||
displayData( wkgArray, wkgNumStates, "Original data after upload" );
|
||||
|
||||
// find state
|
||||
printf( "\nFinding state: %s\n", searchData.name );
|
||||
findStateByName( &resultData, wkgArray, wkgNumStates, searchData );
|
||||
printf( "State found: %s, %d, %5.2f%%, %c\n", resultData.name,
|
||||
resultData.population,
|
||||
resultData.growth * 100.00,
|
||||
resultData.majority );
|
||||
|
||||
// remove state
|
||||
printf( "\nRemoving state: %s\n", removeData.name );
|
||||
removeStateByName( &resultData, wkgArray, &wkgNumStates, removeData );
|
||||
|
||||
printf( "State removed: %s, %d, %5.2f%%, %c\n", resultData.name,
|
||||
resultData.population,
|
||||
resultData.growth * 100.00,
|
||||
resultData.majority );
|
||||
|
||||
// display original list
|
||||
displayData( wkgArray, wkgNumStates,
|
||||
"Original data after state removal" );
|
||||
|
||||
// bubble sort
|
||||
// function: runBubbleSort
|
||||
runBubbleSortByName( sortingArray, sortingNumStates );
|
||||
|
||||
// display bubble-sorted list
|
||||
displayData( sortingArray, sortingNumStates,
|
||||
"Full list sorted by name using bubble sort" );
|
||||
|
||||
// insertion sort
|
||||
// function: runInsertionSort
|
||||
runInsertionSortByPopulation( sortingArray, sortingNumStates );
|
||||
|
||||
// display insertion-sorted list
|
||||
displayData( sortingArray, sortingNumStates,
|
||||
"Full list sorted by population using insertion sort" );
|
||||
|
||||
// selection sort
|
||||
// function: runSelectionSort
|
||||
runSelectionSortByGrowth( sortingArray, sortingNumStates );
|
||||
|
||||
// display insertion-sorted list
|
||||
displayData( sortingArray, sortingNumStates,
|
||||
"Full list sorted by growth using selection sort" );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf( "\nData upload failed - program aborted\n" );
|
||||
}
|
||||
|
||||
// end program
|
||||
|
||||
// report end program
|
||||
// function: printf
|
||||
printf( "\nProgram End\n" );
|
||||
|
||||
// clear dynamic array
|
||||
wkgArray = clearStateArray( wkgArray );
|
||||
sortingArray = clearStateArray( sortingArray );
|
||||
|
||||
// return program success
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue