Question: c++ ----using web form html i created this i need help with this code. i am having problems with the if else statements.. this is

c++ ----using web form html i created this i need help with this code. i am having problems with the if else statements..

this is the web form html

p>The switch statement will execute a block of code based on your input.

First Name:

Last Name

Favorite Witch

Harry Potter Hermione Granger Ron Weasley

#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; indexf (Witch=="Harry Potter") { cout<<"You are brave"< } //50 cout << "Content-type:text/html "; cout<<" "; cout<<" "; cout<<"

Which witch are you?

"; cout<<" Parameter Parser"; cout<<" "; cout<<" "; cout<<" first value="<"; cout<<" "; // code an HTML page, which includes the three fields // received. cout<<" "; return 0; } //******************************************* //******** Functions begin ****************** //******************************************* //******************************************* // parse() // This will separate the name/value pairs found after the ? in // the URL and populate the name_value_pairs array of structures //******************************************* void parse (string qs, FIELDS f_name_value_pairs []) { cout << "debug in parse " << endl; string name, value; int start_pos = 0, pos; for (int counter=0; counter < cnt; counter++) { pos = qs.find("=", start_pos); name = qs.substr(start_pos, pos - start_pos); cout << "name: " << name << " " << endl; start_pos = pos + 1; pos = qs.find("&", start_pos); if (pos == string::npos) { pos = qs.length(); } value = qs.substr(start_pos, pos - start_pos); f_name_value_pairs[counter].name=name; //store the name of current parameter in array f_name_value_pairs[counter].value=value; //store the value of current parameter in array start_pos = pos + 1; } } //******************************************* // param() // This will find the field value based on the // field name //******************************************* string param(string lookUp, FIELDS f_name_value_pairs[], int f_cnt) { for(int counter=0; counter

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!