Looking for ECE2071 - Systems Programming - MUM S1 2026 test answers and solutions? Browse our comprehensive collection of verified answers for ECE2071 - Systems Programming - MUM S1 2026 at learning.monash.edu.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Part 1 (15 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 composite number (integer greater than 1 and has more then 2 factors) that is greater than starting_value and stores this as the current composite value (current_composite)
Step 2: Starting from the first character, for each character in the string (except the terminating NULL character), calculate the sum of the ASCII value of the current character and current_composite.
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: Find the next smallest composite number that is greater than the current_composite and assign this as the new value of current_composite.
Step 5: Repeat steps 2-4 until all non-NULL characters in the string have been considered.
Step 6: 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) with a maximum of 20 non-NULL characters (inclusive of whitespaces) and an integer (starting_value) in one line as input from the user through the terminal. The two pieces of information should be separated using a comma delimiter.
Call the hash_string function written in Part 1, using string_1 and starting_value as the inputs
Prints string_1, starting_value and accumulator in the following format on the terminal:
<string_1><whitespace><starting_value><whitespace>-<whitespace><accumulator>'\n'
Note: