Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review topics posted here under Pages for pointers and dynamic memory allocation and then

Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review topics posted here under Pages for pointers and dynamic memory allocation and then do the following: Define a class called Course 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. Member functions must be added as needed: constructor to initialize a Course object and allocate memory for it when it's created (or added), to edit the information of an existing object, to display Course information, the function for calculating the GPA and a destructor to free dynamically allocated memory for each object. The destructor ensures that each and every object created will be freed. This will make it unnecessary for Quit to call a delete() function to delete all objects and free their allocated memory . In main, declare an array of 10 Course pointers, initialized to NULL and continuously present the following menu to the user asking him or her to choose one: Add new course Edit an existing course Display a course List all courses Display GPA Delete all courses Quit If Add new course is selected, pass the array of pointers to an add() function, which dynamically allocates memory for a new Course, reads the course 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 courses with a number next to them and asks which course to edit, like so: Select the course to edit: Math 102 2. CSIT 839 3. English 112 Enter your selection: 2 It then reads new course information from the user and writes to the selected course using its pointer, as follows: Enter course name: CSIT 802 Enter number of units: 5 Enter grade: B If Display a course 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 course, pass the course name and array of pointers to a bin_search() function which will do a binary search on the course names using the pointers and either find and display the course information, or that Course 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 courses 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 courses. 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 courses) / total number of units for all courses, where points are 4 for A, 3 for B, 2 for C, 1 for D and 0 for F. For example, if only 3 courses 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 courses 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

7. How will you encourage her to report back on the findings?

Answered: 1 week ago

Question

Were the decisions based on appropriate facts?

Answered: 1 week ago

Question

Were the right people involved in the decision-making process?

Answered: 1 week ago