logo

Crowdly

Browser

Додати до Chrome

ECE2071 - Systems Programming - MUM S1 2026

Шукаєте відповіді та рішення тестів для ECE2071 - Systems Programming - MUM S1 2026? Перегляньте нашу велику колекцію перевірених відповідей для ECE2071 - Systems Programming - MUM S1 2026 в learning.monash.edu.

Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!

A hash function is a function that maps any arbitrary data into a fixed-size value within a specified range. The values returned by a hash function are called hash values, or “hashes”. Hash functions are used in a wide variety of applications, including encryption and data integrity.

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:

  1.  A pointer to character (string_1) representing a C string 
  2.  An integer (starting_value) greater than 0
and returns an integer according to the process outlined below:

  • 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.

For example: string_hash("New South Wales", 5) should return a value of 1647.

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:

  1. Your code MUST be submitted as a .txt file below BEFORE the end of the test. Late submissions cannot be accepted.
  2. Your .txt file should be named as q1_studentID.txt, eg q13_12345678.txt

  3. You should use good programming practices

Переглянути це питання

Хочете миттєвий доступ до всіх перевірених відповідей на learning.monash.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome