Question
You are required to develop a C++ program that reads an input data set consisting of four parts (a lot of the coding is already
You are required to develop a C++ program that reads an input data set consisting of four parts (a lot of the coding is already done in Assignment4.cpp,LinkedList.h and Hash.h files below):
a) The first part is a hash table size requested by a user.
b) The second part is a list of students, this part will end with the line InsertionEnd
c) The third part is a number of commands to follow
d) The forth part is a list of commands.
1. After reading in a hash table size (reresented by an integer), a hash table of the size (collision resolving by chaining) needs to be created. Each slot of your hash table should be a link list of nodes where each node represents one Student. Initially all linked lists should be empty.
2. Then by reading each students information line by line, their information needs to be stored in the hash table using a hash function. You will need to design your own hash function so that it reduces the number of collisions, i.e.,the length of each linked list should not be too long.
Each student data will be in one line and will contain the following information which are separated by commas:
name, gender, inClass_or_onLine, major, campus, status, address, city
The following shows an example of such data for students:
John Smith,M,InClass,Computer Science,Tempe,Freshman,123 Whatever St.,Chandler Mary Johnson,F,InClass,Business,Tempe,Junior,213 Whatever St.,Chandler Carole Almenda,F,InClass,Computer Science,Polytech,Sophomore,111 Mickey Mouse Ave.,Tempe Natalie Parkson,F,InClass,Psychology,Tempe,Freshman,123 Main Ave.,Tempe Adriean Santoros,F,InClass,Psychology,Tempe,Freshman,22 Linda Dr.,Gilbert Tammy Barnes,M,Online,Business,Tempe,Senior,22 Linda Dr.,Seattle Jason Brown,M,InClass,Computer Science,Polytech,Freshman,123 University Dr.,Tempe Roger Clark,M,InClass,Business,Tempe,Junior,213 Whatever St.,Chandler
3. After the line InsertionEnd, a user will enter a number of commands.
4. Each command will be in one of the three forms: hashDisplay, hashSearch, or hashDelete.
hashDisplay command:
With hashDisplay command, your program needs to display the content of your hash table by listing the content of each linked list in the following format,
By specifying the index of each slot of the hash table and their linked list size (if a linked list is empty, it should print out The list is empty.
Then print out each linked lists elements one-by-one.
hashSearch command: hashSearch command will have the format of:
hashSearch,name,gender,major,address
where the word hashSearch is followed by name,gender,major,address of a student and the data is separated by commas. A real example of such command can be:
hashSearch,John Smith,M,Computer Science,123 Whatever St.
After the hashSearch command is entered, the program should search for a student that matches those data fields, and if it is found, display the following information:
John Smith in Computer Science major, on Tempe campus is found.
If not found, display a message using the following format:
Lily Guy with Computer Science major, live at 123 Main Ave. is not found.
hashDelete command: hashDelete command will have the format of:
hashDelete,name,gender,major,address
where the word hashDelete is followed by name,gender,major,address of a student and the data is separated by commas. A real example of such command can be:
hashDelete,Roger Clark,M,Business,213 Whatever St.
After the hashDelete command is entered, the program should search for a student that matches those data fields, and if it is found, it should be deleted from the hash table and the program needs to display a message using the following format:
Roger Clark in Business major, on Tempe campus is deleted.
If not found, display a message using the following format:
John Smith with Computer Science major, live at 12 Main Ave. is not found.
Example: Input1.txt
6 John Smith,M,InClass,Computer Science,Tempe,Freshman,123 Whatever St.,Chandler Mary Johnson,F,InClass,Business,Tempe,Junior,213 Whatever St.,Chandler Carole Almenda,F,InClass,Computer Science,Polytech,Sophomore,111 Mickey Mouse Ave.,Tempe Natalie Parkson,F,InClass,Psychology,Tempe,Freshman,123 Main Ave.,Tempe Adriean Santoros,F,InClass,Psychology,Tempe,Freshman,22 Linda Dr.,Gilbert Tammy Barnes,M,Online,Business,Tempe,Senior,22 Linda Dr.,Seattle Jason Brown,M,InClass,Computer Science,Polytech,Freshman,123 University Dr.,Tempe Roger Clark,M,InClass,Business,Tempe,Junior,213 Whatever St.,Chandler InsertionEnd 8 hashDisplay hashDelete,Natalie Parkson,F,Psychology,123 Main Ave. hashSearch,John Smith,M,Computer Science,123 Whatever St. hashSearch,Lily Guy,F,Computer Science,123 Main Ave. hashDelete,Jason Brown,M,Computer Science,123 University Dr. hashSearch,Roger Clark,M,Business,213 Whatever St. hashDelete,Roger Clark,M,Business,213 Whatever St. hashDisplay
Example: Output1.txt
Assignment4.cpp
#include#include #include #include "Hash.h" using namespace std; int main() { string name, gender, inClass_or_onLine, major, campus, status, address, city; //a variable represents the number of hash table slots int count; //a variable represents the number of commands inside the input file int numOfCommand; //a variable represents the actual command name inside the input file string command; //declare any other necessary variables here //---- //get the first line which is a number and store it inside count cin >> count; //create a hash table with the 'count' number of slots //---- do { //get one line of student data //---- //Tokenize it to get each information out, then //insert the new student inside the hash table //---- //---- } while(//as long the line we read in is not "InsertionEnd"); cin >> numOfCommand; for(int i= 0;i LinkedList.h
#include#include #include using namespace std; struct Student { string key; string name, gender, inClass_or_onLine, major, campus; string status, address, city; struct Student *next = NULL; }; class LinkedList { private: struct Student *head; int size; public: LinkedList(); ~LinkedList(); bool insert(string key, string name, string gender, string inClass_or_onLine, string major, string campus, string status, string address, string city); bool deleteStudent(string key); bool search(string key); void displayList(); int getSize(); }; //Constructor LinkedList::LinkedList() { head = NULL; size = 0; } //Destructor LinkedList::~LinkedList() { //Add your own codes here //---- //---- } //Return number of students inside the Linked list int LinkedList::getSize() { return size; } //Insert the parameter student at the head of the linked list. //return true if it is inserted successfully and false otherwise bool LinkedList::insert(string key, string name, string gender, string inClass_or_onLine, string major, string campus, string status, string address, string city) { //Add your own codes here //---- //---- } //Delete the student with the given key. //Return true if it is deleted successfully and false otherwise bool LinkedList::deleteStudent(string key) { //Add your own codes here //---- //---- if(//the student's key matches the parameter key) { cout name major campus Hash.h
#include#include #include #include "LinkedList.h" using namespace std; class Hash { private: LinkedList **table; int m; public: Hash(int size); ~Hash(); bool hashInsert(string name, string gender, string inClass_or_onLine, string major, string campus, string status, string address, string city); bool hashDelete(string name, string gender, string major, string address); bool hashSearch(string name, string gender, string major, string address); void hashDisplay(); int h(string key); //Add any other necessary function declarations here //which you think are useful //---- //---- }; //constructor - create an array of LinkedList, m is the number of slots Hash::Hash(int size) { table = new LinkedList*[size]; m = size; } //Destructor - release the memory Hash::~Hash() { delete[] table; table = NULL; } //hashInsert inserts a student with the relevant info. into the hash table. //it returns true if the data is inserted successfully and false otherwise bool Hash::hashInsert(string name, string gender, string inClass_or_onLine, string major, string campus, string status, string address, string city) { //Add your own codes here //---- //---- } //hashDelete deletes a student with the relevant key from the hash table. //it returns true if it is deleted successfully and false otherwise //Note: key is the combination of name, gender, major and address bool Hash::hashDelete(string name, string gender, string major, string address) { //A bool variable used to check whether the student is deleted from //the hash table or not. bool deleted = false; //Add your own codes here //---- //---- if(!deleted) { cout 2. Design Requirements You should create a hash table with collision resolving-by-chanung (an arra oflinked ust Please spect your bash unction h k clearly The key or each studen address. For instance, for the student with the information: ohn Smith,M, InClas, Computer Science, Tempe, Freshman, 123 Whatever St.,Chandler ill be struig made by appending their name, gender, ma or and the key should be "John SmithMComputer science123 Whatever St." You also need to define hashInsert, hashDelete, and hashSearch functions for the hash table, and definc insert, deleteStudent, search functions for the linked list. Please have comments to clearly identify these functions in your code 2. Design Requirements You should create a hash table with collision resolving-by-chanung (an arra oflinked ust Please spect your bash unction h k clearly The key or each studen address. For instance, for the student with the information: ohn Smith,M, InClas, Computer Science, Tempe, Freshman, 123 Whatever St.,Chandler ill be struig made by appending their name, gender, ma or and the key should be "John SmithMComputer science123 Whatever St." You also need to define hashInsert, hashDelete, and hashSearch functions for the hash table, and definc insert, deleteStudent, search functions for the linked list. Please have comments to clearly identify these functions in your code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started