Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab, you are asked to complete similars.c program file which has been already given in Moodle. Inthis program, there are four functions, namely,

In this lab, you are asked to complete similars.c program file which has been already given in Moodle. Inthis program, there are four functions, namely, main, hash_text, strong_similar, and weak_similar.main function is already provided, and it is supposed to remain as it is (you should not change it). You arerequired to implement hash_text, strong_similar, and weak_similar functions. Although this lab is verysimilar to the previous lab, in this time, you will solve your problem using structures.There are a few global declarations in the program which are listed as below:Definitions of constant macros as follows: STR_LEN, MAX_ELEM, and HASHSIZE.A structure defined with several elements to keep the name, last name, name_lastname, andstrong hash and weak hash values. The name of the defined type is Student. The hash values,and all other critical information is kept as a record by using the structure of the type of Student. Prototypes of the functions listed above.Here are the operations performed in main function:An array of records in the type of Student is created and initialized to some values. Although thehash values are set to zero, the names are initialized.In the for loop, the name - lastname pairs are concatenated and the hash values for strongsimilarity are computed.strong_similar function is called to find the same name-lastname pairs and fill the twodimensionalarray called same to keep the mapping of similarities.The name-lastname pairs, the calculated hash values and similarity mapping is printed on thestandard output.weak_similar function is called to calculate the hash values of each name and surname separately,then build the weak similarity mapping using hash values calculated.The name - lastname pairs, and weak similarity mapping is printed on the standard output.Task 1: Implement hash_text function.unsigned int hash_text (char * list) ;A character pointer holding names and surnames is sent as an input, and the hash value of the input textis returned. During the calculation a basic formula is used as follows when the name is ali. The ascii codefor a is 97, for l is 108 and for i is 105. The function calculates the hash value by the following formula;hash =262*97+26*108+105The algorithm should be applied to all symbols including whitespaces between name and surname. At theend mod 1000 of hash value should be returned.hash = hash mod 1000 Consider the below example run:elements with hash valuesahmet yuksel 978mehmet arslan 88mustafa kemal 482ali kemal 314mustafa kemal 482mustafa kemal 482mehmet arslan 88kemal ahmet 506ali kaan 428kemal kaan 740 Task 2: Implement strong_similar function.void strong_similar (Student studentList[MAX_ELEM], intmap[MAX_ELEM][MAX_ELEM])Calculated hash values of all names-lastname pairs are sent to the function. The function modifies andreturns the map of exact matches. Exact matching of the entries is calculated only by using hashed values.Consider the below example run:The matches are calculated and printed through the main program by calling the strong_similarfunction. Once the strong_similar function is called in main function, the above output is printed.elements with hash valuesahmet yuksel 978mehmet arslan 88mustafa kemal 482ali kemal 314mustafa kemal 482mustafa kemal 482mehmet arslan 88kemal ahmet 506ali kaan 428kemal kaan 740elements with hash values and similarities:ahmet yuksel 978mehmet arslan 886mustafa kemal 48245ali kemal 314mustafa kemal 48225mustafa kemal 48224mehmet arslan 881kemal ahmet 506ali kaan 428kemal kaan 740 Task 3: Implement weak_similar function.void weak_similar (Student studentList[MAX_ELEM], int map[MAX_ELEM][MAX_ELEM])Array of structure of the type of Student is sent as input and previously calculated similarity map is sentas input-output parameter.The function calculates hash values of names and lastnames for each pair separately by calling hash_textfunction. Once the hash values of all names and lastanmes are calculated the function updates the maparray to mark the weak similarities (either names or surnames are same). For example;ali kemal and mustafa kemal are weakly similar. They both are weakly similar to kemal ahmet.Consider the below example run:Once the weakly_similar function is called in main function, the above output is printed.elements with weak similarities:ahmet yuksel 9787mehmet arslan 88mustafa kemal 482379ali kemal 314245789mustafa kemal 482379mustafa kemal 482379mehmet arslan 88kemal ahmet 506023459ali kaan 42839kemal kaan 740234578 Once the weakly_similar function is called in main function, the above output is printed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions