Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should

Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:

1) Student name - the key field (string);

2) Credits attempted (integer);

3) Credits earned (integer);

4) Grade point average - GPA (real).

All student information is to be read from a text file. Each record in the file represents the grade information on a course attempted by a student and contains:

1) Student name ;

2) Course credits ( integer);

3) Course grade (character).

A file excerpt might look like:

Jones,Sue 3 B

Brown,Charlie 3 D

This file contains no special end-of-data tag (flag) except for the usual end-of-file condition.

In computing grade point averages, GPAs, you will need to compute the quality points associated with each grade according to the scale: A = 4, B = 3, C = 2, D = 1 and F = 0. No "+" of "-" grades are given, and no grades other that A, B, C, D, or F are given.

Your program should read the student course grade records from the data file one at a time. For each record it should search the current binary search tree for a node with a name matching the student name it has just read. There are 2 cases to consider.

1) The name is not found so this record corresponds to a new student. A new node for this

student should be created and inserted into the binary search tree. The information fields of

this new node should be initialized as follows:

a) Student name = student name read from the file;

b) Credits attempted = course credits read from the file;

c) Credits earned = credits attempted if the course grade read from the file was not an F or 0 if the course grade read from the file was an F.

d) GPA = quality points associated with the grade read from the file.

2) The name is found so this record corresponds to an update for a current student. The information fields in this student's node should be updated as follows:

a) New GPA = [(old GPA) * (old credits attempted) + (course credits) * (quality points

of the grade)] / [(old credits attempted) + (course credits)]

b) Credits attempted = old credits attempted + course credits read from the file.

c) If the grade read from the file was not an F, credits earned = old credits earned +

course credits read from the file; otherwise, credits earned remains the same.

After your program has created and updated the binary search tree of student academic records, it must perform the following tasks:

1) Print the students' academic records in alphabetical order according to student names;

2) Find the student who has earned the most credits using a postorder traversal;

3) Count both the number of students with GPAs under 2.5 using a single preorder traversal.

Each of these tasks must be done using an appropriate recursive function for the tree traversal.

In task #1, the student academic records must be printed in a table with the following headings:

STUDENT RECORDS

CREDITS CREDITS

NAME ATTEMPTED EARNED GPA

GPAs must be printed with exactly 3 decimal places.

In task #2, finding the student who has earned the most credits, your program must print the student names as it processes their nodes in the postorder traversal. Your program should then print the name, GPA, and number of credits earned of the student who has earned the most credits in the form:

xxxxxxxxxxxxxxxxxxxx WITH A GPA OF x.xxx HAS EARNED THE MOST CREDITS, xx

Your program may assume that the most number of credits earned is unique, i.e., no two students have earned this "maximum" number of credits. If it is not unique, your program can print either name. Finding the student who has earned the most number of credits requires you to use a pointer to the student node of the student who has the most credits so far in the traversal. This pointer is initialized to the root. As each node is processed, this pointer will change if the current student has earned a higher number of credits than the one pointed to by this pointer; otherwise it remains the same. When the processing ends, this pointer points to the node corresponding to the student who has earned the most credits.

In task #3, your program must use a single preorder traversal to find the count. As your program does the preorder traversal, it must print each student name as the student's node is processed. The count should be printed in the following form:

xx STUDENTS HAD GPAS UNDER 2.50.

Run your program using the attached file.

Student.txt

Jones,Sue 3 B

Brown,Charlie 3 D

Smith,John 3 C

Smith,John 4 C

Bird,Sam 2 C

Bird,Sam 2 C

Smith,John 5 C

Jones,Sue 3 A

Moose,Manny 3 A

Bear,Ben 4 C

Bear,Ben 5 F

Bear,Ben 2 C

Brown,Charlie 3 C

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 Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

Students also viewed these Databases questions