✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Part 1 (5 marks)
int string_hash (char* string_1, int starting_value)
Write a C function string_hash that takes in the following input arguments:
Step 1: Find the smallest prime number that is greater than starting_value and stores this as the current prime value (current_prime)
Step 2: For each character in the string (except the terminating NULL character), calculate the product of the ASCII value of the current character and current_prime.
Step 3: Add the result of the calculation in Step 2 to the accumulator value (accumulator), which is initialized as zero at the start of the function.
Step 4: Calculate the sum of accumulator and current_prime, and then assign the result as the new value of accumulator.
Step 5: Find the next smallest prime number that is greater than the current_prime and assign this as the new value of current_prime.
Step 6: Repeat steps 2-5 until all non-NULL characters in the string have been considered.
Step 7: Return the value of accumulator upon exit.
Part 2 (5 marks)
Write a C code inside the main function that performs the following activities:
Scan a string (string_1) and integer (starting_value) as input from the user
Call the hash_string function written in part 1, using string_1 and starting_value as the inputs
Scan a string as input from the user, representing a filename
Opens the file and appends an new line to the file which contains string_1, starting_value, and the accumulator in the following format:
<string_1><whitespace><starting_value><whitespace>-<whitespace><accumulator>
Note: