Question: Using C++ Define a structure called Student with id (string) and gpa (double). Write a program that reads student ID's and their GPA's into an
Using C++
Define a structure called Student with id (string) and gpa (double). Write a program that reads student ID's and their GPA's into an array of Students of maximum size 100, sorts the array based on the GPA in descending order and allows the user to search for a range of GPA's and prints the ID, name and GPA of the students whose GPA is found in the given range. To end data entry, the user will enter -1 for the ID. You will use a sort function to sort and a modified binary search function to search for a range of GPA's.
The sort function will take the array of Student structures and sort the array based on the GPA's. The search function will take the array, a range of GPA's such as 2.9 and 3.1 (low, high) and an array of Students (section). It will assign the array elements that fall in the given range of GPA's to the elements of the section array and return number of GPA's that fell in the given range. Upon the function's return, main will print the ID, name and GPA of those stored in the section array.
The search function must not do the search in a linear fashion, but rather take advantage of the fact that the list is sorted. For example, to search for GPA's that fall within 2.9 and 3.1, it should compare the mid value with those limits. If the mid value is below 2.9, it should adjust the last index and if it's larger than 3.1, it should adjust the first index. Once it finds a value that falls in the range, such as 3.0, it needs to search for any other GPA that might be in that range, either larger or smaller than the one found, such as 2.9 and 3.1 and store them in the section array in descending order (largest GPA to smallest that fall in the range).
The following is a sample interaction between the user and the program:
Enter student ID (-1 to quit): 88101
Enter GPA: 3.3
Enter student ID (-1 to quit): 88102
Enter GPA: 2.7
Enter student ID (-1 to quit): 88103
Enter GPA: 2.5
Enter student ID (-1 to quit): 88104
Enter GPA: 3.6
Enter student ID (-1 to quit): 88105
Enter GPA: 3.4
Enter student ID (-1 to quit): 88106
Enter GPA: 3.1
Enter student ID (-1 to quit): 88107
Enter GPA: 3.0
Enter student ID (-1 to quit): 88108
Enter GPA: 2.8
Enter student ID (-1 to quit): 88109
Enter GPA: 3.1
Enter student ID (-1 to quit): -1
Sorted list:
88104 3.6
88105 3.4
88101 3.3
88106 3.1
88109 3.1
88107 3.0
88108 2.8
88102 2.7
88103 2.5
Enter a range of GPA's: 2.8 3.1
Found the following:
ID GPA
88106 3.1
88109 3.1
88107 3.0
88108 2.8
Press any key to continue.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
