Question: Question 1 [10 points] Write a Makefile that builds a C program map.c and produces the executable object file map. Your Makefile should use

Question 1 [10 points] Write a Makefile that builds a C program map.c and produces the executable object fileQuestion 2 [90 points] In this question, you will write a program map.c implementing a 'dictionary' data(d) (10 points) Write a function called map-print that takes 2 arguments: (1) the array of structs(e) (20 points) Write a main () function that runs a loop which accepts from stdin a line containing a singleYou will need to use the following functions to compare and copy strings: strcmpstrcpy You can use man to find more information on these two functions. The syntax char *string is equivalent

Question 1 [10 points] Write a Makefile that builds a C program map.c and produces the executable object file map. Your Makefile should use the compiler flags discussed in class, and have the 'all' and 'clean' targets as shown previously. Question 2 [90 points] In this question, you will write a program map.c implementing a 'dictionary' data structure that keeps key-value pairs using an array of structs. Each struct will have two elements: a 'key' and a 'value'. The 'key' is a string of at most 63 characters (not including the null- terminator). The 'value' is a double type value that corresponds to the key. If the key is an empty string (the first character in the character array is '\0'), this means the struct at this array position is not currently used. You can assume a maximum of 128 key-value pairs will be needed. (a) (20 points) Write a function called map_add that takes 4 arguments: (1) the array of structs representing the dictionary, (2) the size of the array (i.e., 128), (3) a key to add, and (4) the value corresponding to the added key. The function finds an unused position in the array and sets the key-value pair. If the key-value pair was added successfully, the function should return 0. If no free position was found, the function returns -1. The return type is int. (b) (20 points) Write a function called map_find that takes 3 arguments: (1) the array of structs representing the dictionary, (2) the size of the array (i.e., 128), and (3) a key to check. If a dictionary entry matching the key was found, the function returns the array index at which the entry is found. If no such entry exists in the dictionary, the function should return -1. The return type is also int. (c) (20 points) Write a function called map_remove that takes 3 arguments: (1) the array of structs representing the dictionary, (2) the size of the array (i.e., 128), and (3) a key to remove. If the key is found, the key is set to an empty string and the function returns 0. If the key is not found, the function returns -1. The return type is int. Try not to have a loop in this function and instead use the previous function(s). (d) (10 points) Write a function called map-print that takes 2 arguments: (1) the array of structs representing the dictionary, and (2) the size of the array (i.e., 128). The function then prints all the valid (used) key-value pairs in the dictionary, each on a separate line. The output should be similar to the following: key1123.456789 a_key -> 322.000000 my_key > 2.000000 another_key -> 98.625000 abc -> 4.500000 (e) (20 points) Write a main () function that runs a loop which accepts from stdin a line containing a single character that corresponds to the desired operation, followed by more lines containing the arguments for the operation. The operations are as follows: 'a' for add; e.g., a my_key 2 This should add a key-value pair using the given key and value. 'f' for find; e.g., f my_key In this example, the output should be the value corresponding to "my_key" if the key exists in the dictionary, or "Key not found" if the key is not in the dictionary. 'r' for remove; e.g., r my_key The output should be "success" or "fail", depending on whether the key was found and removed. 'p' for print all; e.g., The output should be all key-value pairs using the function in part (d). 'q' to quit the program. You will need to use the following functions to compare and copy strings: strcmp strcpy You can use man to find more information on these two functions. The syntax char *string is equivalent to char string[]. You may assume that keys do not contain any spaces. Also, keep in mind that if you choose to use scanf() to get a string from stdin, you do not need to use the '&' operator. The reason for this will be revealed in the "Pointers" topic.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Write a function called mapadd that takes 4 arguments 1 the array of structs representing the dictionary 2 the size of the array 3 a key to add and 4 the value corresponding to the added key The fun... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!