Question: This start file already contains a struct for the name/value pairs, an array, and two functions, one of which (parse()) is almost already complete. Complete

This start file already contains a struct for the name/value pairs, an array, and two functions, one of which (parse()) is almost already complete.

Complete the following:

Add code to the parse function, which will populate the name_value_pairs array.

Complete the function 'param()' based on the prototype, calls, and definition, which are already in place. The function 'param()'s job is to match the field name passed in its parameter to the corresponding array struct element. Once the appropriate structure is matched, the value for that field can be returned.

Return "" (an empty string) if the element for that name is not found in the array - (no match from the html form).

Use your own fields by modifying the html code appropriately (first, last, and color are not required, just examples) .

As a final touch, return the data received back to the browser in some creative way. For example the color chosen by the user could be used to change the background color of the page. Again, this is only an example - be creative.

 // File: retrieve_form_start.cpp // Author: // cs102 Online // Date: // Description: This program retrieves three form fields and sends the result // back to the browser #include  #include  #include  #include  #include  using namespace std; struct FIELDS { string name; string value; }; const int cnt = 3; //cnt should be set to the number of fields the html form contains // Prototypes void parse(string, FIELDS []); string param(string, FIELDS [], int); //main begins int main() { FIELDS name_value_pairs [cnt]; string qs(getenv("QUERY_STRING")); //string qs("first=fred&last=flint&color=red"); cout << "Content-type:text/html "; cout << "debug with qs: " << qs << "

" << endl; parse(qs, name_value_pairs); // debug to show content of name_value_pairs cout << "debug to show content of name_value_pairs array: " << endl << " "; for (int index = 0; index

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!