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 pointers and dynamic memory allocation posted here under Pages. For sorting, you can

Review structures, pointers and dynamic memory allocation from CSIT 839. 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 "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to Co Sci 839 or google: "binary search function in C++".

You can separate the main function from the definitions of the functions by adding a second C++ file to your project (Project/Add New Item: C++ File), and write the function definitions there. Likewise, you can separate the class definition by adding a header file to the project (Project/Add New Item: 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 initialize a 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 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:

  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 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.

The following is a sample run of the program:

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: Math 102

Enter number of units: 3

Enter grade received: C

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: 2

Editing: Math 102, 3 units, grade: B

Enter course name: Math 102

Enter units: 4

Enter grade: B

Course modified.

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: 3

Math 102, 3 units, grade: B

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. Display a course
  4. List all courses
  5. Display GPA
  6. Delete all courses
  7. Quit

Enter selection number: 5

GPA = 3.50

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: 6

All courses deleted!

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: 7

Press any key to continue.

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

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

Give a brief defi ni tion of the terms population and sample.

Answered: 1 week ago

Question

Describe your ideal working day.

Answered: 1 week ago