Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So were supposed to use the top code to solve the bottom section (that is red).

ID: 673742 • Letter: S

Question

So were supposed to use the top code to solve the bottom section (that is red). Now the answer is in red, I just want an explanation what every line is doing, particularly in regards to the instructions given between the two codes. Thank you!

struct crop { char name (256); // May contain Spaces float width; I/In Feet float length ; I/In Feet float cost PerSqFoot; // Dollars per sq foot float profit PersqFoot;// Dollars per sq foot Complete the following Cmethod that increases the size of the input array by one, copies the old elements and cleans up as is necessary. struct crop* Increase (struct crop * data , intsize) | struct crop newnum = malloc(sizeof(struct crop)* (*size + 1); forint i=0; i

Explanation / Answer

Here we have a predefined structure named crop which takes in some parameters.

Now what we are doing with function increase is that we are creating a bigger space to keep structure objects i.e we are increasing the size by 1 and we are declaring a new variable struct named newnum.

With the below for loop the values are copied from the structure data to this new structure newnum.

and the Size variable is set to *size+1. Since the data occupied by data structure is now copied we don't need it and therefore we are freeing the space occupied by it with free(data).