Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ write a class. The requirements for the class are define as followings: Using the Student and StudentHash class below create a StudentHashDriver class

In C++ write a class. The requirements for the class are define as followings:

Using the Student and StudentHash class below create a StudentHashDriver class

#include

using namespace std; class student { public: string first_name; string last_name; string middle_name; int Student_ID; student() { cout<<"Enter first name="; cin>>first_name; cout<<"Enter last name="; cin>>last_name; cout<<"Enter ID="; cin>>Student_ID; cout<<"Do you have Middle name(0 for no, 1 for yes)"; int n; cin>>n; if(n) { cout<<"Enter Middle name="; cin>>middle_name; } } };

class StudentHash {

public: StudentHash(int n) { students = new Student*[n]; size = n; }

void add(Student *s) { int index = s->Student_ID % size; if(students[index] == NULL) { students[index] = s; return index; } else { return -1 * index; } }

Student* search(int id) { int index = id % size;

if(students[index] != NULL && s->Student_ID == id) { return students[index]; } else { return NULL; } }

void printRecords() { for(int i=0; i

private: student **students; int size; };

  • Class StudentHashDriver This class will contain the implementation of the main() method of the program. The following tasks will need to be implemented:
    • There will be 3 options:
      • Option 1 Allow the user to enter Student records and add them in the hash table of the StudentHash class.
      • Option 2 Allow the user to search for a Student record by the Student ID.
      • Option 3 Print out the contents of the hash table.
    • Option 1:
      • Prompt the user for the number of Student records to be entered.
      • Create an instance of the StudentHash class, passing the number of Student records through the constructor of the StudentHash class.
      • Prompt the user to enter Student data.
      • Add the Student data to the hash table of the StudentHash class.
      • Whether or not the Student data can be added successfully, print out the collision number.
        • If the collision number is not negative, print out Successfully inserted Student with ID (x).
        • If the collision number is negative, print out Unsuccessfully inserted Student with ID (x).
    • Option 2:
      • Prompt the user for the Student ID.
      • Search for the Student record in the hash table using this ID.
      • If found, display the Student data.
      • Otherwise, report to the user that no Student record can be found using this ID.
    • Option 3:
      • Print the contents of the hash table.

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 Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions