Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Review structures, pointers and dynamic memory allocation from CSIT 835 Also, review pointers and dynamic memory allocation posted here under Pages For sorting, you can

image text in transcribed

image text in transcribed

image text in transcribed

Review structures, pointers and dynamic memory allocation from CSIT 835 Also, review pointers and dynamic memory allocation posted here under Pages For sorting, you can refer to the textbook for Co Sci 839 or google functions". The Bubble sort is the simplest. For binary search too, you can refe to Co Sci 839 or google: "binary search function in C++ "C++ sort You can separate the main fun adding a second C++ file to your project (Project/Add New Item: C++ File), and ction from the definitions of the functions by write the function definitions ther e. Likewise, you can separate the class efinition by adding a header file to the project (Project/Add New ltem: Header File), and write the class definition there. Thus, you should have two cpp files: courses_main.pp and courses_functions.cpp and courses.h. 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 initializea Course object, 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 1. Add new course 2. Edit an existing course 3. Display a course 4. List all courses 5. Display GPA 6. Delete all courses 7. Quit If Add new course is selected, pass the array of pointers to an add0 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 edit0 function that displays all courses with a number next to them and asks which course to edit, like so Select the course to edit: 1. 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 sort0function to sort the pointers, ask the user to enter a course, pass the course name and array of pointers to a bin search0 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 sortOfunction to sort the pointers based on their title and then pass the array of pointers and size to a display0 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 an size to a deleteOfunction that will delete all structures created dynamically and set their pointers to NULL Selecting Quit must pass all pointers and size to the delete0 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. Select one of the following actions: 1. Add new course 2. Edit an existing course 3. Display a course 4. List all courses 5. Display GPA 6. Delete all courses 7. Quit Enter selection number:1 Enter course name: CSIT 839 Enter number of units:3 Enter grade: A Select one of the following actions: 1. Add new course 2. Edit an existing course 3. Display a course 4. List all courses 5. Display GPA 6. Delete all courses 7. Quit Enter selection number: 4 CSIT 839, 3 units, grade: A Math 102, 3 units, grade: B Select one of the following actions: 1. Add new course 2. Edit an existing course 3. 4. 5. 6. 7. Display a course List all courses Display GPA Delete all courses Quit Enter selection number:5 GPA 3.50 Select one of the following actions: 1. 2. 3. 4. 5. Add new course Edit an existing course Display a course List all courses Display GPA

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

More Books

Students also viewed these Databases questions