Question: The Pseudocode is given. Now need the code in C++ I. Inputs: There will be two inputs to the program: a) inFile (use argv[1]): A

The Pseudocode is given. Now need the code in C++

I. Inputs: There will be two inputs to the program:

a) inFile (use argv[1]): A text file contains a list of triplets {

For example,

+ Longcheng Ochilov

+ Sweyaksha Webster

- Longcheng Ochilov

+ Pengdwende Cesa

? David Chowdhury

+ Kushal Zheng

+ Mohammed Aucacama

- Sweyaksha Kim

:

b) BucketSize (use argv[2]): Run your program twice, first with bucket size = 29 and next with bucket size 43,

1

***********************************

II. outputs: There will be two output files:

a) outFile1 (use argv [3]): Print the final result of the hash table: B ordered linked lists, one linked list per text line.

For example (let B be the bucketSize):

HashTabel [0]: (dummyFirst dummyLast next's firstName) (firstName lastName next's firstName) . HashTabel [1]: (dummyFirst dummyLast next's firstName) (firstName lastName next's firstName) . :

:

HashTabel [B-1]: (dummyFirst dummyLast next's firstName) (firstName lastName next's firstName) ..

b) outFile2 (use argv [4]): Print all intermediate outputs, to help you debugging!

********************************

III. Data structure:

********************************

- listNode class

friend of hashTable

- (string) firstName

- (string) lastName

- (listNode *) next

methods:

- constructor (firstName, lastName) //create a node with given data

- printNode (node) // use the format:

(this node's firstName, this nodes lastName, next nodes firstName )

// see example given in the above.

- hashTable class

- (char) op // either '+' or '- or '?'

- (int) bucketSize // via argv[2]

- (listNode *) hashTable [bucketSize]

method:

- createHashTable (...) // The method dynamically allocates hashTable [], size of bucketSize, //where each entry point to a dummy node: (dummyfirst, dummylast, null)

// On your own! You should know how to do this.

- (int) Doit (lastName) // Given the lastName, the method returns the index between 0 to bucketSize-1 // The function can be found in the lecture note.

- informationProcessing (inFile, outFile2) // see algorithm below.

- (listNode *) findSpot (index, firstName, lastName) // search thru hashTable[index] linked list to locate the record with firstName and lastName. See algorithm below.

- hashInsert () // see algorithm below.

- hashDelete () // see algorithm below.

- hashRetrieval () // see algorithm below.

- printList (index, outFile) // print the linked list of hashTable [index], use the format given in the above. - printHashTable (outFile) // output the entire hashTable, call printList (), index from 0 to bucketSize -1.

2

******************************************

IV. Main ( )

******************************************

Step 1: inFile open input file using argv[1]

bucketSize argv[2]

outFile1, outFile2 open output files using argv[3] and argv[4]

Step 2: createHashTable ()

Step 3: informationProcessing (inFile, outFile2)

Step 4: printHashTable (outFile1)

Step 5: close all files

******************************************

VI. informationProcessing (inFile, outFile2)

******************************************

Step 1: op, firstName, lastName get from inFile

Step 2: outFile2 print op, firstName, lastName (with description)

Step 3: index Doit (lastName)

outFile2 print index (with description)

Step 4: printList (index, outFile2)

Step 5: if op == '+'

hashInsert (index, firstName, lastName outFile2)

else if op == '-'

hashDelete (l index, firstName, lastName outFile2)

else if op == '?'

hashRetrieval (index, firstName, lastName outFile2)

Step 6: repeat step 1 to step 5 until inFile is empty.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!