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

Please use C langauge to create ...... note (I\'m using Xcode) Problem 1. The us

ID: 3676752 • Letter: P

Question

Please use C langauge to create ...... note (I'm using Xcode)

Problem 1. The user will first input the number of students (less than 100). Then input the detailed information for each students including ID, name (less than 20 characters and do not contain spaces), grade for math and physics 2. Define a structure type and use a structure array to store the data input by the user Use the qsort function in header file stdlib.h to sort the structure array. Then output the sorted array on the screen. Do not write your own code for sorting 3. The comparison standard is as follows (a) The student with greater total grade will rank first. (b) If two students have the same total grade, the student with lower difference between the student's own grade for math and physics will rank first (c) If two students have the same total grade and the same grade difference, the student with less student ID will rank first Sample Input 101 Bob 80 90 125 Tom 81 91 133 Jim 82 90 131 Lucy 82 90 Sample Output 131 Lucy 82 90 133 Jim 82 90 125 Tom 81 91 101 Bob 80 90

Explanation / Answer

#include <iostream>
#include <string>
#include <stdlib.h>

using std::string;
using std::cout;

struct student {
int id;
string name;
int grade;
};

int compareByGrade(const void * voidA, const void * voidB) {
student * studentA = (student *)(voidA);
student * studentB = (student *)(voidB);
return studentA->grade - studentB->grade;
}

int compareByName(const void * voidA, const void * voidB) {
student * studentA = (student *)(voidA);
student * studentB = (student *)(voidB);
return (studentA->name).compare(studentB->name);
}
int main() {
const int SIZE = 4;
student math_class[4] = { { 101, "Bob", 80}, { 125, "Tom", 81 }, { 133, "Jim", 82 }, { 131, "Lucy", 82 } };

qsort( math_class, SIZE, sizeof(student), compareByGrade);
cout << "Sort by Grade: ";
for( int i = 0; i < SIZE; i++ ) {
    cout << math_class[i].id << ": " << math_class[i].name << " " << math_class[i].grade << " ";
}

qsort( math_class, SIZE, sizeof(student), compareByName);
cout << "Sort by Name: ";
for( int i = 0; i < SIZE; i++ ) {
    cout << math_class[i].id << ": " << math_class[i].name << " " << math_class[i].grade << " ";
}
return 0;
}


output

Sort by Grade:
101: Bob 80
125: Tom 81
133: Jim 82
131: Lucy 82
Sort by Name:
101: Bob 80
133: Jim 82
131: Lucy 82
125: Tom 81