Question
Define a structure called Class which contains a c-string for its title (e.g.: CSIT 839), an integer for its number of units and a character
Define a structure called Class which contains a c-string for its title (e.g.: CSIT 839), an integer for its number of units and a character for the letter grade received.
In main, declare an array of 10 Class pointers, initialized to NULL and continuously present the following menu to the user asking him or her to choose one:
1. Add new class
2. Edit an existing class
3. Display a class
4. List all classes
5. Display GPA
6. Delete all classes
7. Quit
If Add new class is selected, pass the array of pointers to an add() function, which dynamically allocates memory for a new Class, reads the class information (title, units and grade) from the user, saves its pointer in the array of pointers and displays the menu again.
If Edit is selected, the program passes the array of pointers and size to edit() function that displays all classes with a number next to them and asks which class to edit, like so:
Select the class to edit:
1. Math 102 2. CSIT 839 3. English 112
Enter your selection: 2
It then reads new class information from the user and writes to the selected class using its pointer, as follows:
Enter class name: CSIT 802
Enter number of units: 5
Enter grade: B
If Display a class is selected, the program must pass the array of pointers and size to a sort() function to sort the pointers, ask the user to enter a class, pass the class name and array of pointers to a bin_search() function which will do a binary search on the class names using the pointers and either find and display the class information, or that Class was not found. For example, if CSIT 839 is to be searched, when found, it will display: CSIT 839, 3 units, grade: A.
If List all classes is selected, the program must again pass the array of pointers and size to the sort() function to sort the pointers based on their title and then pass the array of pointers and size to a display() function to display all classes.
If Display GPA is selected, the program must calculate and display the GPA as follows:
GPA = (sum of the products of units x points for all classes) / total number of units for all classes, where points are 4 for A, 3 for B, 2 for C, 1 for D and 0 for F. For example, if only 3 classes are taken worth 3, 5 and 4 units with the letter grade of C, A and B, respectively, the GPA is given by (3 units x 2 points + 5 units x 4 points + 4 units x 3 points) / (3 + 5 + 4) = 3.17.
If Delete all classes is selected, the program must pass the array of pointers and size to a delete() function that will delete all structures created dynamically and set their pointers to NULL.
Selecting Quit must pass all pointers and size to the delete() function that will delete all structures created dynamically, set the pointers to NULL and quit the program. Not explicitly deleting the objects created dynamically will cause memory leak.
NOTE THIS IS C++ Code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started