In this assignment, you will push your C++ skills to the limit by implementing a simple database system using binary search trees. Though the end product will be a far cry from Oracle or MySQL, your DB will allow the user to insert, delete, and query data. The data itself will be persistent (stored on disk), so that you may process it over several sessions.
The DB itself will contain data that would be commonly found in a university’s computer system. In our case, this information consists of student and faculty records. The information for each will be stored in its own tree (or “table” in DB terminology).
Though I will provide you with a general outline of the program, many of the implementation details will be up to you. In the same spirit, I will give you a point in the right direction as far as some of the C++ techniques go, but it will also be your responsibility to research the techniques in more detail.


The tables that store the records in your DB will be binary search trees. The nodes will consist of Student or Faculty objects, depending on the tree. The tree will be sorted on the primary key value of the nodes, which in our case will be faculty and student Ids.
Your first job will be to build a BST implementation supporting the usual operations (including delete). This should not be difficult in and of itself. Just be sure to use templates to make your implementation generic, and overload operators as required.

Student Records
Student records will be stored in a Student class. Student records contain a unique student ID (an integer), a String name field, a string level field (Freshman, Sophomore, etc), a String major field, a double GPA field, and an integer advisor field, which will contain the Faculty ID of their advisor. These are the only fields the class contains.
The Student class must overload equality, less than, greater than operators, etc. so that we can compare them to one another.

Faculty Records
Faculty records are similar to student records, and will also require overloaded operators.

Faculty records contain an integer Faculty ID, a String name, a String level (lecturer, assistant prof, associate prof, etc), a String department, and a list of integers corresponding to all of the faculty member’s advisees’ ids. These are the only fields the class contains.

How the Program Should Work
Your program will keep references to both the faculty and student tables in memory. These references are simply BSTree instances. For convenience, we will call them masterFaculty and masterStudent.

When the program starts, it should check the current directory for the existence of 2 files “facultyTable” and “studentTable”. These files correspond to the BSTrees containing the faculty and student data. If neither of these files exist, then masterFaculty and masterStudent should be initialized as new, empty trees. If the files do exist, then they should be read into the appropriate variables. (See appendix A)

Once the tables have been set up, a menu should be presented to the user to allow them to manipulate the databases. At a minimum (if you do more you’ll get more credit), the choices should include:

1. Print all students and their information (sorted by ascending id #)
2. Print all faculty and their information (sorted by ascending id #)
3. Find and display student information given the students id
4. Find and display faculty information given the faculty id
5. Given a student’s id, print the name and info of their faculty advisor
6. Given a faculty id, print ALL the names and info of his/her advisees.
7. Add a new student
8. Delete a student given the id
9. Add a new faculty member
10. Delete a faculty member given the id.
11. Change a student’s advisor given the student id and the new faculty id.
12. Remove an advisee from a faculty member given the ids
13. Rollback
14. Exit

When a command is selected, you should prompt the user for the required data, and execute the command. If there are any errors, you should inform the user and abort the command.

All of the above commands should enforce referential integrity. That is to say, a student can not have an advisor that is not in the faculty table. A faculty member can’t have an advisee in the student table. If a faculty member is deleted, then their advisees must have their advisors changed, etc. Your commands will be responsible for maintaining referential integrity. If a user issues a command that would break referential integrity, you should warn them and abort the command, or execute the command and fix any violations as appropriate.

After each command is executed, the menu should be displayed again, and the user allowed to continue.

The Rollback command is used if the user realizes they have made a mistake in their data processing. The Rollback command will “undo” the previous action, but only if that action changed the structure of the DB. Your program should allow the user to roll back the last 5 commands that CHANGED the DB. (Commands that simply display data do not count.) This will involve keeping snapshots of the DB before and after commands are issued. The implementation details for this are left up to you.

If the user chooses to exit, you should write the faculty and student tables back out to the “facultyTable” and “studentTable” files (see appendix A), clean up, and quit gracefully.

Programming Strategy
At this point you should realize this is a non-trivial assignment. To successfully complete it, you need to make use of your best OO design and programming skills. Think modularly, sketch out a solution before you start coding, and START EARLY. Sleeping is optional, but not recommended.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <list>
#include <iterator>

#include "GenBst.h"
#include "Student.h"
#include "Faculty.h"

string facultyFile = "faculties.txt";
string studentFile = "students.txt";

GenBst<Student> * addStudent (GenBst<Student> students, GenBst<Student> *studentTable);
GenBst<Faculty> * addStudent (GenBst<Faculty> faculties, GenBst<Faculty> *facultyTable);
GenBst<Student> * findStudent(GenBst<Student> students, GenBst<Student> *studentTable);
GenBst<Faculty> * findFaculty(GenBst<Faculty> faculties, GenBst<Faculty> *facultyTable);

GenBst<Student> * addStudent (GenBst<Student> students, GenBst<Student> *studentTable) {

cout << "******** Student Insertion ********" << endl;
Student student;

cout << "Enter student ID: ";
cin >> student.ID;

cout << "Enter student name: ";
cin >>;

cout << "Enter student level: ";
cin >> student.level;

cout << "Enter student major: ";
cin >> student.major;

cout << "Enter student GPA: ";
cin >> student.GPA;

studentTable = students.insertBST(studentTable, student);
cout << "******** Student Insertion ends ********" << endl;
return studentTable;

GenBst<Student> * deleteStudent (GenBst<Student> students, GenBst<Student> *studentTable) {

cout << "******** Student Deletion ********" << endl;
GenBst<Student> *student = findStudent(students, studentTable);

if (student != NULL) {
Student stud = student->key;
studentTable = students.deleteBST(studentTable, stud);
cout << "******** Student Deletion ends ********" << endl;
return studentTable;

GenBst<Faculty> * deleteFaculty (GenBst<Faculty> faculties, GenBst<Faculty> *facultyTable) {

cout << "******** Faculty Deletion ********" << endl;
GenBst<Faculty> *faculty = findFaculty(faculties, facultyTable);

if (faculty != NULL) {
Faculty fact = faculty->key;
facultyTable = faculties.deleteBST(facultyTable, fact);
cout << "******** Faculty Deletion ends ********" << endl;
return facultyTable;

GenBst<Faculty> * addFaculty (GenBst<Faculty> faculties, GenBst<Faculty> *facultyTable) {

cout << "******** Faculty Insertion ********" << endl;
Faculty faculty;

cout << "Enter Faculty ID: ";
cin >> faculty.ID;

cout << "Enter Faculty name: ";
cin >>;

cout << "Enter Faculty level: ";
cin >> faculty.level;

cout << "Enter Faculty department: ";
cin >> faculty.department;

facultyTable = faculties.insertBST(facultyTable, faculty);
cout << "******** Faculty Insertion ends ********" << endl;
return facultyTable;

GenBst<Student>* findStudent(GenBst<Student> students, GenBst<Student> *studentTable) {
int id;
cout << "******** Student Search ********" << endl;
cout << "Enter student Id: ";
cin >> id;
Student student;
student.ID = id;
GenBst<Student> *found = students.searchBST(studentTable, student);
if (found != NULL) {
cout << found->key;
} else {
cout << "Student with ID=" << id << " not found" << endl;
cout << "******** Student Search Ends ********" << endl;
return found;

void updateStudent (GenBst<Student> students, GenBst<Student> *studentTable,
GenBst<Faculty> faculties, GenBst<Faculty> *facultyTable) {
cout << "******** Update Student advisor ********" << endl;
Student student;
GenBst<Student> *found = findStudent(students, studentTable);
if (found != NULL) {
GenBst<Faculty> *fact = findFaculty(faculties, facultyTable);
if (fact != NULL) {
cout << "******** Update Student advisor ends ********" << endl;

void findFacultyAdvisor(GenBst<Student> students, GenBst<Student> *studentTable,
GenBst<Faculty> faculties, GenBst<Faculty> *facultyTable) {
cout << "******** Student's Faculty advisor Search ********" << endl;

GenBst<Student> *student = findStudent(students, studentTable);
if (student != NULL) {
Faculty faculty;
faculty.ID = student->key.advisor;
GenBst<Faculty> *found = faculties.searchBST(facultyTable, faculty);
if (found != NULL) {...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats