67 lines
No EOL
1.7 KiB
C
67 lines
No EOL
1.7 KiB
C
// 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.
|
|
} |