Updated A 5
Updated A 5
Updated A 5
Programming Assignment 5
Binary Search Tree
Assigned: 11/17/2014
Due: 11/24/2014 via Webcourses at 11:30 pm
Problem:
In this program you are to implement a database of student records, using the
binary search tree abstract data type, implemented as a linked list. There is a lot of
code on the internet. Please do not simply copy the code already developed by
other programmers. Write your own code.
The student record will have the following format:
typedef struct studentRec{
int id;
char[] name; //the name has a maximum length of 25 letters
char[] major; //the major array has a max length of 15
int year;
}
You are required to maintain the database by providing the following functionality:
1. Search to see if a record exists in the data base
2. Add a record to the database;
3. Delete a record from the database
4. Update a record in the database
5. Print out all of the records in the database
6. Print out all of the records in the database from a given point
Objectives:
The objective of this assignment is for students to demonstrate a working
knowledge of :
Binary Search Trees
Linked list implementation of BST
BST operations
Requirements:
Your program should demonstrate the 6 functionalities described above. These
should be implemented as the following functions:
1. initBST: In this function your program should read an input file to obtain
the student records then your BST should be populated by adding each of
these records to the BST. Your function should return a pointer to the root of
the BST. Do not hardcode the name of your input file in your program. It
should be a parameter passed to main.
2. Search: This function takes a pointer to the BST, and an integer parameter. It
searches the BST for the student with that Id. If the record is found it prints
out the record and the function returns 1 otherwise it returns 0;
3. addNode: This function takes a pointer to the BST, an integer, two char
arrays and a second integer. It creates a new node and then adds that node
in place to the BST and returns a pointer to the modified BST.
4. updateStudent: This function takes a pointer to the BST and two integers. It
finds the student whose id is the first integer and updates the year value to
the second integer parameter and returns a pointer to the updated BSGT.
5. deleteStudent: This function takes a pointer to the BST, and the integer id
of a student, finds that student record, deletes it (using the predecessor
method) and returns the updated BST.
6. print: This function takes a pointer to the BST and prints out all of the
student records stored in table form as shown in the sample output
7. printFrom: This function takes a pointer to the BST and an integer and
prints out all of the student records stored in the BST from that node to all of
its sub-trees. The values are printed in table form as shown in the sample
output
When your program is run, it should read input from an input file one line at a time.
Each line will contain an integer, followed by two char arrays and then a second
integer. Your program should continue to read the input file, until a line beginning
with the number 0 is encountered. The data in the input file will be used to initialize
the BST. The name of your input file will be passed as an argument to main so it
should not be hardcoded in your program
It should then provide a menu of choices 2-7 to the user. This allows a software
testing team to test your other functions. Your program should repeat the menu
display until the user selects the option 0 which means to Quit.
Grading Rubric
Comments and formatting of code5
Required functions..65
Appropriate naming of variables ... 5
Correct file I/O......10
Correct menu display5
Correct output format.. 10
Total 100
Note: If your program does not compile on Eustis you will receive a maximum score
of 40 if your code has all of the functions. If your code does not compile and there
are missing functions, then you will receive a grade lower than 40.
Sample inputfile
123
125
120
137
Mary Green
Thomas Heys
Kyle Hope
Rachael Singh
CS
Math
Bio
Art
1
4
4
3
0
Sample output from running code
Please select an action from the following menu
2 to Search for a student
3 to add a student
4 to update a students record
5 to delete a student
6 to print all student records
7 to print student records beginning with a given student
0 (or any other number) to stop
6
3
ID
Name
Major
Year
----------------------------------120
Kyle Hope
Bio
4
123
Mary Green
CS
1
125
Thomas Heys
Math
4
137
Rachael Singh Art
3
4
Please enter the PID for the student you would like to update and the new year
137 4
Rachel Singhs record has been updated
Please select an action from the following menu
2 to Search for a student
3 to add a student
4 to update a students record
5 to delete a student
6 to print all student records
7 to print student records beginning with a given student
0 (or any other number) to stop
6
ID
Name
Major
Year
----------------------------------120
Kyle Hope
Bio
4
123
Mary Green
CS
1
125
Thomas Heys
Math
4
134
Jack Frost
CS
1
137
Rachael Singh Art
4