Question: Need the below code to print out the ID numbers and grades entered by the user, SORTED BY ID NUMBER. Please point out where the

Need the below code to print out the ID numbers and grades entered by the user, SORTED BY ID NUMBER. Please point out where the sort code is entered when inserted in the code.

Thanks

#include

#include

//Creating the GradeBook Structure

struct gradeBook {

//Declaring the student's Id array and Grade array

int id;

int grade;

} gradbk[100]; //array of structures

int main( )

{

//initialize variables

int i=0, j=0;

int id,n; struct gradeBook temp;

//infinite loop which will stop when user enters -1 as id value

while(id != -1)

{

//Getting the id entered by the user

printf(" Enter student id number (Enter -1 to stop):");

scanf("%d",&id);

//if user entered id is not -1

if(id != -1)

{

//Populating the id into the id array

gradbk[i].id=id;

//Getting the grade entered by the user

printf(" Enter grade percentage (0-100) ");

//read grade

scanf("%d",&gradbk[i].grade);

i++;

continue;

}

//if user entered -1, then exit this loop

else

{

break;

}

}

n= i;

//Displaying all the students id's and grades

printf(" Displaying the Students ID's and Grades : ");

//loop which will iterate till no:of user entered grades

for(j=0; j

{

//print the students id's and grade

printf(" Student id : %d ",gradbk[j].id);

printf(" Grade is : %d ",gradbk[j].grade);

}

for(i=0;igradbk[j+1].id) { temp = gradbk[j]; gradbk[j] = gradbk[j+1]; gradbk[j+1] = temp; } } } //print out the ID numbers and grades entered by the user, sorted by ID number. for(j=0; j

{

//print the students id's and grade

printf(" Student id : %d ",gradbk[j].id);

printf(" Grade is : %d ",gradbk[j].grade);

}

return 0;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!