Question: Using C++ Define a structure called Class with name (string), units (int) and grade (char) as its member data. Define a structure called Student with

Using C++

Define a structure called Class with name (string), units (int) and grade (char) as its member data.

Define a structure called Student with name (string), numClasses (int), gpa (double) and an array of maximum of 20 Class structures called classes, where name is the student's full name, numClasses is the number of classes taken so far and gpa is the current grade point average and classes is all the classes taken so far.

Write a function called get_info which takes an array of Student structures called students and array size, reads all the information for as many students as the user wants to enter except for the gpa which is later calculated, storing them in students array. It then returns the number of students entered by the user before quitting. The user indicates the end of data entry by entering a NULL string ("") for the student. The user must enter as many classes for each student as indicated by numClasses - number of classes.

Write a function called display which takes an array of Student structures called students and array size and displays the information for all the students of the array.

Write a function called get_gpa that takes a single student and returns the GPA for the student computed from his or her array of classes. GPA is calculated by multiplying the number of units for each class by the number of points earned for the class, adding up all the products of units and points (units*points) and dividing the resulting sum by the total number of units of all classes. The points earned is given by the letter grade earned for each class. A is worth 4 points, B 3 points, C 2 points, D 1 point and F 0 points. For example, if a student has taken 3 classes with units of 3, 5 and 4 and grades of A, C and B, respectively, the GPA is given by: (3 x 4 + 5 x 2 + 4 x 3) / (3 + 5 + 4) which is 2.8.

Write a sort_name function that takes an array of Student structures and array size and sorts the array in ascending order based on the student name.

Write a sort_gpa function that takes an array of Student structures and array size and sorts the array in ascending order based on gpa.

Write a search_name function that takes students sorted on name, its size and a name and performs a binary search on the students to find the specified name. The function must return the index of the student if found or -1 if not found.

In main, declare an array of maximum of 100 Student structures and then pass the array and its maximum size (100) to get_info() to read as many students as the user wants, storing the information entered in the array passed as parameter. The function must set gpa to 0.0.

Then, pass each student of the array of students to get_gpa() function and store the gpa returned by the function in the gpa field of the student overwriting the 0.0. For example, if students[0] has taken 3 classes with units of 3, 5 and 4 and grades of A, C and B, respectively, get_gpa should return a gpa of 2.8, which main must store in the gpa field of the student in question (students[0]).

Then, pass the array of students and the actual size returned by get_info() to display to print all students entered.

Pass the array of Student structures and the actual size returned by get_info() to sort_name() function to sort the array based on name in ascending order. Again, display the sorted list of students using display().

Ask the user to enter a name and pass it, along with students array and array size, to the search_name() function. Print the information of the student found or print "Student not found" in main.

Finally, pass the array of Student structures and the actual size returned by get_info to sort_gpa() function to sort the array based on gpa. Then, print the sorted list of students using the display function.

The following is a sample execution of the program:

Enter student name: Robert Hall

Enter number of classes taken by Robert: 3

Enter name of class 1: CSIT 801

Enter units for CSIT 801: 3

Enter letter grade received for CSIT 801: C

Enter name of class 2: CSIT 802

Enter units for CSIT 802: 5

Enter letter grade received for CSIT 802: B

Enter name of class 3: CSIT 839

Enter units for CSIT 839: 3

Enter letter grade received for CSIT 839: A

Enter student name: Susan Ball

Enter number of classes taken by Susan: 2

Enter name of class 1: CSIT 802

Enter units for CSIT 802: 5

Enter letter grade received for CSIT 802: A

Enter name of class 2: CSIT 808

Enter units for CSIT 808: 3

Enter letter grade received for CSIT 808: B

Enter student name: Kim Yong

Enter number of classes taken by Kim: 2

Enter name of class 1: Math 801

Enter units for Math 801: 4

Enter letter grade received for Math 801: C

Enter name of class 2: Math 802

Enter units for Math 802: 3

Enter letter grade received for Math 802: B

Enter student name: [ENTER]

List of students entered:

Student: Robert Hall

CSIT 801, 3 units, Grade C

CSIT 802, 5 units, Grade B

CSIT 839, 3 units, Grade A

GPA: 3.0

Student: Susan Hall

CSIT 802, 5 units, Grade A

CSIT 808, 3 units, Grade B

GPA: 3.6

Student: Kim Yong

Math 801, 4 units, Grade C

Math 802, 3 units, Grade B

GPA: 2.1

List of students sorted on name:

Student: Kim Yong

Math 801, 4 units, Grade C

Math 802, 3 units, Grade B

GPA: 2.1

Student: Robert Hall

CSIT 801, 3 units, Grade C

CSIT 802, 5 units, Grade B

CSIT 839, 3 units, Grade A

GPA: 3.0

Student: Susan Hall

CSIT 802, 5 units, Grade A

CSIT 808, 3 units, Grade B

GPA: 3.6

Enter a student name to search for: Robert Hall

Student: Robert Hall

CSIT 801, 3 units, Grade C

CSIT 802, 5 units, Grade B

CSIT 839, 3 units, Grade A

GPA: 3.0

List of students sorted by GPA:

Student: Susan Hall

CSIT 802, 5 units, Grade A

CSIT 808, 3 units, Grade B

GPA: 3.6

Student: Robert Hall

CSIT 801, 3 units, Grade C

CSIT 802, 5 units, Grade B

CSIT 839, 3 units, Grade A

GPA: 3.0

Student: Kim Yong

Math 801, 4 units, Grade C

Math 802, 3 units, Grade B

GPA: 2.1

Press any key to continue.

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!