Description:You will write a C program that will create a simple array hash table. First yourprogram will create an input set of data. It will take a random number seed and generate an arrayof random...

Description:You will write a C program that will create a simple array hash table. First yourprogram will create an input set of data. It will take a random number seed and generate an arrayof random integers. Next it will create a second array that is a simple array hash table andinitialize all the elements to zeros. Third it will process the input data set into the simple array hashtable.Generating Random Numbers:To use the random() function to generate a random numbers, you first must "seed" the randomnumber generator. Your program will use argv[1] as its random number seed. Remember that youwill have to convert the argv[1] cstring to an actual integer. Do not use srand(). Use srandom()instead:srandom(seed); // Reminder: You will need to #include This statement should only be called one time, before any calls to the random() function are made.Using malloc():The malloc() function is used to allocate memory for your programs when the size of the neededmemory is unknown until runtime. It takes a single parameter, an integer value depicting thenumber of bytes necessary for allocation. Traditionally, this value is determined by multiplyingthe size of the particular type by the number of elements needed:malloc(sizeof(int) * N)Because of the possibility that there may not be enough free, adjacent memory to handle therequested number of bytes, every call to malloc() should be followed with a check of the returnvalue:double *myDoubleArray = malloc(sizeof(double) * 32);if (myDoubleArray == NULL){printf("Error allocating memory!");exit(1);}Also remember that for every call to malloc() there must also be a corresponding call to free(),once the memory is no longer needed.Create the input data set:Your program will need to generate integer values in the range 0..i, where i is argv[2]dataSetRange. Use the mod operator to keep the values within the range for each call to therandom() function using the following formula:int my_random_val = random()%(i + 1);Specifications:• Your program will have 3 integer values as its command line parameters:1. seed A random number seed2. dataSetRange The upper bound of the range of values for the integers in theinput data. This will be used to set the size of the simple array hash table. Recallthat in the example in the course materials if the range of values in the input data setis 0 – 12, the size of the simple array hash table will be 13. There will be onebucket for each value in the range. In this case, the upper bound would be 12. Thelower bound will always be zero.3. dataSetSize The size of the input data set. This will be the length of the inputarray.• Your program will start by printing an informational message, stating your name, labsection, and what the program will do.• In main() it will allocate memory for two arrays of ints. The inputArray will contain theset of random integers within the specified dataSetRange. The inputArray length can beany positive integer and is input on the command line in dataSetSize. It is recommended touse small numbers at first to more easily test whether your results are correct.The second array will be the simple array hash table, named simpleHashTable. The lengthwill be dataSetRange + 1.• The program will then perform the following steps:1. Call a function that will assign random integers within the data set range to theelements in this array. The prototype of the function should be:void CreateInputArray(int *inputArray, const int dataSetSize, int dataSetRange);2. After returning from the function described in 1 above, print the input array to thescreen. Use a single blank space between each number so the list fits on one line of an 80character wide terminal. (Suggestion: Make another function to do this. You don't have to,but you will if you want to be considered a good programmer.)3. A separate function is then called to create and initialize the hash table. The length ofthe hash table, htSize, will be dataSetRange + 1. The hash table values are initialized tozero. The prototype for this functions is:void InitializeHashTable(int *simpleHashTable, const int htSize);4. A separate function is then called to process the input data set and compute the elementvalues in simpleHashTable. This function will pass in parameters for the two arrays. Theprototype for this functions is:void processData(int *simpleHashTable, const int htSize,int *inputArray, const int dataSetSize);5. After returning from the function described in 4, the simple array hash table is printedto the screen. (Suggestion: Use the function that you created in step 2 to do this. Goodprogrammers make functions instead of duplicating code.)
Jul 07, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here