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
#include <stdio.h>
#include <stdbool.h>
#include <conio.h>
#include <windows.h>
typedef struct{
char id;
char fname[30];
char lname[30];
char creditAtt[6];
char creditEarned[3];
char gpa[1];
}STUD;
typedef struct node *nd;
struct node
{
STUD stu;
nd left;
nd rigth;
}NODE;
void inputStud(nd *);
bool treeEmpty(nd *);
void deleteNode(nd *);
void editStud(nd *);
void viewAll(nd);
nd searchNode(nd *,nd *,char[]);
int main(void)
{
int ans,c;
bool e;
nd root = NULL;
do
{
system("cls");
printf("1] Add New Student Record\n");
printf("2] Edit Student Record\n");
printf("3] View Specific Record\n");
printf("4] Display All\n");
printf("5] Delete Student Record\n");
printf("6] Exit\n");
printf("Pick your choice: ");
scanf("%d",&ans);
switch(ans)
{
case 1: inputStud(&root);
break;
case 2: editStud(&root);
break;
case 3: viewAll(root);
getch();
break;
case 4: viewAll(root);
getch();
break;
case 5: deleteNode(&root);
break;
case 6: printf("\n\nclosing the program in 5 seconds....");
sleep(5000);
}
}while (ans != 6);
return 0;
}
void inputStud(nd *root)
{
nd t, t1, temp;
char creAtt[6];
char lnam[20];
char fnam[30];
char creEar[3];
char gpa[1];
STUD st;
ifstream file;
file.open("StudentRecord.txt");
if (!file) // Validation statement
{
cout << "Can't open input file " << endl;
}
for(int x = 0;x <= filecheck; x++)
{
id = x+1;
file >> fnam >> lnam >> creAtt >> creEar;
}
strcpy(st.creditAtt, creAtt);
strcpy(st.lname, lnam);
strcpy(st.fname, fnam);
strcpy(st.creditEarned, creEar);
st.gpa=gpa;
temp = malloc(sizeof(NODE));
temp -> stu = st;
temp -> left = NULL;
temp -> rigth = NULL;
if (*root == NULL)
{
*root = temp;
}
else
{
t = *root;
while (t != NULL)
{
t1 = t;
if (strcmp(temp -> stu.creditAtt,t -> stu.creditAtt)==0)
t = t -> left;
else
t = t -> rigth;
}
if (strcmp(temp -> stu.creditAtt,t1 -> stu.creditAtt) < 0)
t1 -> left = temp;
else
t1 -> rigth = temp;
}
t1 = NULL;
t = NULL;
temp = NULL;
return;
}
void editStud(nd *root)
{
int id;
char creAtt[6];
char lnam[20];
char fnam[30];
char creEar[3];
float gpa;
STUD st;
printf("Please enter the ID of the Student you would like to edit: ");
gets(id);
if(strcmp(id,st.id)==0)
{
printf("Enter Student Credit Earned: /n");
gets(creEar);
printf("Enter Student's Last Name: /n");
gets(lnam);
printf("Enter Student's First Name: /n");
gets(fnam);
printf("Enter Student's Credit earned: /n");
gets(creAtt);
printf("Enter Student's gpa: /n");
scanf("%f", &gpa);
strcpy(st.creditAtt, creAtt);
strcpy(st.lname, lnam);
strcpy(st.fname, fnam);
strcpy(st.creditEarned, creEar);
st.gpa=gpa;
}
else
{
printf("Student not found..");
}
return;
}
void deleteNode(nd *root)
{
char iD[6];
bool e,lmoved = false;
nd t,t1,t2;
STUD st;
e = treeEmpty(root);
if (e)
{
printf("\n\nSorry, the tree is empty...");
sleep(3000);
}
else
{
printf("Please enter ID of student to be deleted: ");
gets(iD);
t = searchNode(root,&t1,iD[]);
if (t == NULL)
{
printf("\n\n%s not found...",iD);
sleep(2000);
}
else
{
if ((t -> left == NULL)&&(t -> rigth == NULL))
{
if (strcmp( iD, t1 -> stu.creditAtt) <0)
t1 -> left = NULL;
else
t1 -> rigth = NULL;
}
else if ((t -> left == NULL)&&(t -> rigth != NULL))
{
if (strcmp( iD,t1 -> stu.creditAtt) <0)
t1 -> left = t -> rigth;
else
t1 -> rigth = t -> rigth;
}
else if ((t -> left != NULL)&&(t -> rigth == NULL))
{
if (strcmp( iD,t1 -> stu.creditAtt) <0)
t1 -> left = t -> left;
else
t1 -> rigth = t -> left;
}
else
{
t1 = t;
t = t1 -> rigth;
while(t -> left != NULL)
{
t2 = t;
t = t -> left;
lmoved = true;
}
t1 -> stu.creditAtt = t -> stu.creditAtt;
if (t -> rigth == NULL)
{
if (lmoved)
t2 -> left = NULL;
else
t1 -> rigth = NULL;
}
else
{
if (lmoved)
t2 -> left = t -> rigth;
else
t1 -> rigth = t -> rigth;
}
}
free(t);
t1 = NULL;
t2 = NULL;
}
}
return;
}
nd searchNode(nd *r,nd *t1,char iD[], nd root)
{
nd t;
t = *r;
STUD st;
while((t != NULL) && (strcmp(t -> stu.creditAtt, iD)== 0)
{
*t1 = t;
if ((strcmp( iD,t1 -> stu.creditAtt) <0)
t = t -> left;
else
t = t -> rigth;
}
return t;
}
bool treeEmpty(nd *r)
{
bool e = false;
if (*r == NULL)
e = true;
return e;
}
void viewAll(nd ptr)
{
if (ptr != NULL)
{
printf("Student Attempted: %s", stu.creditAtt );
printf("First Name: %s", stu.fName);
printf("Credit Earned: %s", stu.creditEarned);
printf("Last Name: %s", stu.lName);
printf("gpa: %f", stu.gpa);
}
return;
}
Write a C++ program to store and update students' academic records in a binary search tree....
Hi there, I am working on a binary search tree code in c++. The program must store and update students' academic records, each node includes the student name, credits attempted, credits earned and GPA. I have made some progress with the code and written most of the functions in the .cpp file (already did the .h file) but i am struggling with what to put in the main and how to put an update part in the insert function. I...
java A University would like to implement its students registery as a binary search tree, calledStudentBST. Write an Student node class, called StudentNode, to hold the following information about an Student: - id (as a int) - gpa (as double) StudentNode should have constructors and methods (getters, setters, and toString()) to manage Write the StudentBST class, which is a binary search tree to hold objects of the class StudentNode. The key in each node is the id. : import.java.ArrayList; public...
Write a program to use a binary search tree to store a list of computer games. Each node in the tree stores the title (string) of a computer game. Different games have different titles. Your program should display the following menu repeatedly: 1. Insert new game 2. Search for games 3. List games 4. quit Option 1 should read a game (title) and add the game into the tree. Option 2 allows the user to enter a partial key...
This is binary search tree problem. The program reads the text file, and creates a binary search tree based on the words in the file. I can create the tree but I also have to store 'the order of insertion' in each node. For example, if text includes "the" 3 times and it is the 1st, 5th, and 9th word in the file, in binary search tree, one node should have string value "the" and array list{1, 5, 9}. How...
LANGUAGE: C++ Write a class to create the binary tree (insert, delete, search, exit) and display the output using inorder, preorder and postorder tree traversal methods.
Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...
Binary Tree Template Write your own version of a class template that will create a binary tree that can hold values of any data type. Demonstrate the class with a driver program. Place your binary tree template in it's own header file, Btree.h. Include methods for the following: inserting new values into the tree removing nodes from the tree searching the tree returning the number of nodes in the tree displaying the contents of the tree using preorder traversal Your...
Suppose a binary search tree has a preorder traversal of E B A D C H G F and an inorder traversal of A B C D E F G H. List all the leaf nodes of the binary tree, separated by a space. (Suppose the leaf nodes were A, B, and C. Then put A B C for your answer.)
Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...
Write a program in C++ to: 1. Read all records from a binary file (also attached to this email) to arrays; (the record structure: student number (20 bytes), grade (integer)) 2. Sort the list according to test scores; 3. Calculate the average test score for the class and print on the screen; 4. write sorted records to a new binary file. For example: The records in the original file: 1 89 2 95 3 76 The new file sorted by...