CS249-Projects/PA10-1115/StateDataUtility.c
cdez c1e9dd47db Finished StateDataUtility, Started HashUtility
+- HashUtiltity.c
+- StateDataUtility.c
2023-11-13 15:09:13 -07:00

103 lines
No EOL
3.1 KiB
C

// header files
#include "GeneralUtility.h"
#include "StateDataUtility.h"
#include <stdio.h>
/* Data Structures
typedef struct StateStruct
{
char name[ STD_STR_LEN ];
double averageTemp, lowestTemp, highestTemp;
bool inUse;
} StateDataType;
Data Structures */
// function definitions
/*
Name: setDataNodeFromData
Process: sets given values into a given StateDataType struct,
using individual struct data
Function input/parameters: provided name (const char *),
average, lowest, and highest temperatures (double),
and node in use state
Function output/parameters: updated state data pointer (StateDataType *)
Function output/returned: none
Device input/---: none
Device output/---: none
Dependencies: privateCopyString
*/
void setDataNodeFromData( StateDataType *nodePtr, const char *name,
double avgTemp, double lowTemp, double highTemp, bool nodeState )
{
// copy the string into the node
privateCopyString(nodePtr->name, name);
// copy the rest of the data into the node
nodePtr->averageTemp = avgTemp;
nodePtr->highestTemp = highTemp;
nodePtr->lowestTemp = lowTemp;
nodePtr->inUse = nodeState;
// no return, void.
}
/*
Name: setDataNodeFromStruct
Process: sets given values into a given StateDataType struct,
using another data struct
Function input/parameters: provided state data source struct
(const StateDataType)
Function output/parameters: updated state data pointer (StateDataType *)
Function output/returned: none
Device input/---: none
Device output/---: none
Dependencies: setDataNodeFromData
*/
void setDataNodeFromStruct( StateDataType *nodePtr,
const StateDataType source )
{
setDataNodeFromData(nodePtr, source.name, source.averageTemp,
source.lowestTemp, source.highestTemp, source.inUse);
// no return, void.
}
/*
Name: stateDataToString
Process: creates string from StateDataType data
Function input/parameters: provided state data (const StateDataType)
Function output/parameters: output string (char *)
Function output/returned: none
Device input/---: none
Device output/---: none
Dependencies: sprintf, or other options
*/
void stateDataToString( char *outStr, const StateDataType state )
{
// get the data out using sprintf
sprintf(outStr, "%s, Avg: %0.2f, Low: %0.2f, High: %0.2f", state.name,
state.averageTemp, state.lowestTemp, state.highestTemp);
// no return, void.
}
/*
Name: setEmptyDataNode
Process: sets given node values to string "---", zero values,
and Boolean in use variable to false
Function input/parameters: state data struct (StateDataType *)
Function output/parameters: updated state data struct (StateDataType *)
Function output/returned: none
Device input/---: none
Device output/---: none
Dependencies: privateCopyString
*/
void setEmptyDataNode( StateDataType *node )
{
// fill the node with blank data.
privateCopyString(node->name, "---");
node->averageTemp = 0;
node->highestTemp = 0;
node->lowestTemp = 0;
node->inUse = false;
// no return, void.
}