Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code needs to be done in c++ Create a class called Record: ? this will represent a data record with the following data: ? an

Code needs to be done in c++

Create a class called Record: ? this will represent a data record with the following data: ? an integer id (this will be the key) ? a name string (you will likely want to make this a fixed size character array) ? you will have the following public methods: ? a constructor, taking an id and a name as arguments ? Getters: getId() and getName() ? Note: You need to make sure all record objects are the same size, so you may want to use a character array with a fixed size, padded or truncated as necessary, to represent the name. 2. Create a class called Bucket: ? this will represent a bucket of records it will have the following data members: ? an integer, capacity, giving the number of records in a bucket ? an array of Record objects (there will be capacity record objects in the array) ? you will have the following public methods: ? a constructor, taking the integer capacity as an argument the constructor should initialize the bucket to contain capacity empty records, where an empty record is identified by an id value of 0 (name value doesn't matter) ? void setRecord(int pos, Record r) replace the record at position pos in the bucket with the given record r (pos = 0...capacity-1) ? Record getRecord(int pos) return the record at position pos in the bucket CSS 532 Advanced Data Structures Spring 2018 3. Create a class called HashFile: ? this will represent your hash file, and it will understand how to perform hashing. It will have at least the following data items: ? the fstream or RandomAccessFile that will implement the hash file ? an integer, numBuckets, representing the number of buckets in the hash file ? an integer, bucketCapacity, represent the number of records to be in each bucket ? an integer, bucketSize, representing the total number of bytes in a bucket ? you will have the following public methods: ? a constructor, HashFile(fileName, numBuckets, bucketCapacity) this should open the underlying hash file, and fill it with numBuckets buckets, each bucket containing bucketCapacity empty records (for our purposes, we will re-create the hash file every time we run the program. This, of course, would be silly for real use). ? int insert(Record r) insert the given record r into the hash file. Return the bucket number into which the record was placed. ? Record retrieve(int key) retrieve the record with the specified key from the hash file. If it does not exist in the file, return an empty record (id = 0) ? revealTable() - retrieve each bucket, from 0 through numBuckets-1, and print its contents as follows: ? close() - close the underlying hash file Notes You may use an in-memory assist, but you do not have to For any errors, or if the table is full, just throw an Exception to terminate the program Entire buckets must be read/written at once. We do not read/write individual records!!! Bucket 0 Record 1: id=42 name=Larry Record 2: id=0 Bucket 1 Record 1: id=53 name=George Record 2: id=99 name=Linda . . . CSS 532 Advanced Data Structures Spring 2018 Hashing Algorithm Your hash file will use a Double Hashing scheme for collision resolution: Primary hash function: key % numBuckets Secondary HashFunction key % (numBuckets 2) + 1 Main Program Your main program will do the following: 1. Construct a hash file with 7 buckets, 2 records per bucket. 2. Loop ? Prompt user to enter an id and name. ? If id = 0, exit the loop. ? Create a data record using this data, and store it in the hash file using the insert() method. ? Print the data record (id and name), and the bucket number where the record was stored (which is returned from the insert() method) 3. Show the table using the revealTable() method 4. Loop ? Prompt user to enter an id. ? If id = 0, exit the loop. ? Retrieve the data record with this id using the retrieve() method. ? If the data record is found, print the id and name. ? If the data record is not found, print the id and a Not Found message. Input Data First Loop Input Data Second Loop id name ---------- 21 Albert 10 Daniel 55 Fred 101 Debra 203 Amy 444 Bob 700 Brenda 600 Elmo 78 Elizabeth 801 Cindy id --- 101 999 (not found) 21 78 700 203 888 (not found)

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago