Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Computer Science I

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.

What do you submit?


For this assignment you are required to submit your source code as a single .c file
called BSTree.c. All submissions are to be made via Webcourses by the deadline.
Email Assignments will not be accepted. There will be NO EXTENSION FOR
THIS ASSIGNMENT. You may choose to submit up to 24 hours late, with 15%
grade penalty.

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.

Expectations for code testing:


Your code will be tested on Eustis. The test file used by the TA will not be the one
given in the sample input. However, it will match the specifications given in the
assignment. For example there may be more or less employees but the file format
will be the same and the data will end with a 0.
When your program is run, any sequence of menu choices may be used.

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

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
2
Please enter the Id for the student that you would like to find
125
ID
Name
Major
Year
----------------------------------125
Thomas Heys
Math
4

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
2
Please enter the Id for the student that you would like to find
300
Sorry this student is not in our system.
4

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
3
Please enter the information for the student whom you would like to add
134 Jack Frost CS 1
Jack Frost has been added to the student list
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
3

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
5

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

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
5
Please enter the pid for the student you would like to delete
125
Thomas Heys has been deleted from our system

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
134
Jack Frost
CS
1
137
Rachael Singh Art
4

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
7
Please enter the PID for the student that you would like to start from
137
ID
Name
Major
Year
----------------------------------134
Jack Frost
CS
1
137
Rachael Singh Art
4

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
0
Thank you for using our Student System. GoodBye!

You might also like