Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3) (25 pts) Write a studentemp function that takes in pointers to two studentTs

ID: 3751800 • Letter: 3

Question

3) (25 pts) Write a studentemp function that takes in pointers to two studentTs and compares them using the following criteria: a) If the first student (pointed to by ptrA) has a lower GPA than the second, a negative integer is returned. If the first student has a higher GPA than the second, a positive integer is returned. b) If the two GPAs are equal, then ties are broken by stremp in the string library applied to the last names. (In these cases, if the last names are different, just return what strcmp does.) c) If the two last names are the same, then those ties are broken by strcmp applied to the first names. (In these cases, if the first names are different, just return what stremp does.) d) Break the tie in this case by returning the difference in PIDs. #include int studentcmp (const studentT* ptrA, const studentT ptrB)

Explanation / Answer

Please find the code below.

CODE

================

#include <stdio.h>

#include <string.h>

#include <sys/types.h>

int studentcmp(const studentT* ptrA, const studentT* ptrB) {

if (ptrA->GPA > ptrB->GPA) {

return 1;

} else if (ptrA->GPA < ptrB->GPA) {

return -1;

} else {

if(strcmp(ptrA->last_name, ptrB->last_name) != 0) {

return strcmp(ptrA->last_name, ptrB->last_name);

} else {

if(strcmp(ptrA->first_name, ptrB->first_name) != 0) {

return strcmp(ptrA->first_name, ptrB->first_name);

}

}

}

return getpid();

}

NOTE: This code might give syntax error since i don't know the variable names for First name, last name and GPA. In case they give errors, just replace the variable names with the actual names.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote