"Finish" PA09
+- GeneralUtility.c +- HeapUtility.c +- StudentUtility.c +- PA09_Main
This commit is contained in:
parent
146e26b5cf
commit
d9e90f6501
4 changed files with 663 additions and 0 deletions
67
PA09-1108/StudentUtility.c
Normal file
67
PA09-1108/StudentUtility.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// header file
|
||||
#include "StudentUtility.h"
|
||||
|
||||
// constants
|
||||
|
||||
/* Data Structures
|
||||
|
||||
typedef struct StudentStruct
|
||||
{
|
||||
char name[ MAX_STR_LEN ];
|
||||
int studentId;
|
||||
char gender;
|
||||
double gpa;
|
||||
int priority;
|
||||
|
||||
} StudentType;
|
||||
|
||||
typedef struct StudentArrayStruct
|
||||
{
|
||||
StudentType *array;
|
||||
|
||||
int size, capacity;
|
||||
} StudentArrayType;
|
||||
|
||||
Data Structures */
|
||||
|
||||
// function implementations
|
||||
|
||||
/*
|
||||
Name: deepCopyStudentDAta
|
||||
Process: copies one StudentType item into another
|
||||
Function input/parameters: source data (const StudentType)
|
||||
Function output/parameters: destination data (StudentType *)
|
||||
Function output/returned: none
|
||||
Device input/ ---: none
|
||||
Device output/ ---: none
|
||||
Dependencies: privateCopyString
|
||||
*/
|
||||
void deepCopyStudentData(StudentType *dest, const StudentType source)
|
||||
{
|
||||
// copy each piece of data out of the source given
|
||||
privateCopyString(dest->name, source.name);
|
||||
dest->studentId = source.studentId;
|
||||
dest->gender = source.gender;
|
||||
dest->gpa = source.gpa;
|
||||
dest->priority = source.priority;
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: studentDataToString
|
||||
Process: creates display string from all object data
|
||||
Method input/parameters: none
|
||||
Method output/parameters: pointer to return string (char * const)
|
||||
Method output/returned: none
|
||||
Device input/keyboard: none
|
||||
Device output/monitor: none
|
||||
Dependencies: sprintf
|
||||
*/
|
||||
void studentDataToString(char *outString, const StudentType toDisplay)
|
||||
{
|
||||
// use sprintf to "cast" the data to a string
|
||||
sprintf(outString, "Nm: %s, Id: %d, Gndr: %c, GPA: %.4f, Priority: %d\n",
|
||||
toDisplay.name, toDisplay.studentId, toDisplay.gender,
|
||||
toDisplay.gpa, toDisplay.priority);
|
||||
// no return, void.
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue