mardi 28 novembre 2017

syntax error at the end of input (classes)

#include <iomanip>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

struct FIELDS
{
    string name;
    string value;
};

const int cnt =3;

void parse(string, FIELDS []);
string param(string, FIELDS[], int);

class WebApps {
public:
void parse (string qs, FIELDS f_name_value_pairs[])
{
    cout << "debug in parse<br>\n" << 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 << "<br>" << 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);
            cout << "value: " << value << "<br>" << endl;
            start_pos = pos + 1;
            f_name_value_pairs[counter].name=name;
            f_name_value_pairs[counter].value=value;
    }

    }

string param(string lookUp, FIELDS f_name_value_pairs[], int f_cnt)
{
 string found="";
for(int i=0;i<f_cnt;i++)
{
if(lookUp==f_name_value_pairs[i].name)
{
found=f_name_value_pairs[i].value;
return found;

}
}
};
int main()
{
WebApps wo;
FIELDS name_value_pairs[cnt];

string qs(getenv("QUERY_STRING")); 
            //string qs("first=fred&last=flint&color=red");
    cout << "Content-type:text/html\n\n";
    cout << "debug with qs: " << qs << "<p>" << endl;
 wo.parse(qs, name_value_pairs);
 // debug to show content of name_value_pairs
    cout << "debug to show content of name_value_pairs array: " << endl 
  << "<br>";
    for (int index = 0; index<cnt; index++) {
    cout << "name: " << name_value_pairs[index].name << endl << "<br>";
    cout << "value: " << name_value_pairs[index].value << endl << "<br>";
}


    // Three fields data are retrieved from the param function
    string firstname = wo.param("firstname", name_value_pairs, cnt);
    string lastname = wo.param("lastname", name_value_pairs, cnt);
    string season = wo.param("season", name_value_pairs, cnt);

    // code an HTML page, which includes the three fields
    // received.

    cout << "<html><head><title>Four Seasons</title></head>";
    cout << "<body><center>";
    cout<<"Hey, "<<firstname<<" your favourite season is ";
    cout<<season<<"<br>";

    if(season=="winter"){
    cout << "<img src=\"http://ift.tt/2AGT8CA\">";
    cout <<" <br> You are as cute as Olaf from Frozen! :]";
    else if(season=="spring"){
    cout << "<img src=\"http://ift.tt/2Ag6hl7?\">";
    cout <<" <br> You are a very very sweet person! Everybody blooms around your presence :]";
      }
    else if(season == "summer"){
    cout << "<img src=\"http://ift.tt/2AGxUEM\">";
    cout <<" <br> You have a hot personality that everybody loves :]";
     }
      else{
    cout << "<img src=\"http://ift.tt/2AcOM58\">";
    cout << "<br> Great things are coming for you! Just sitback and relax :]";
     }
    cout << "</center></body>";
    cout << "</html>";

return 0;
}

Above is my code for an class assignments. It is to turn the parse() and param() functions into classes. I cant find any mistakes in my code but it seems to say "syntax error at the end of the input" on the last line of code

Duplicate retrieve_form.cpp as retrieve_form_OOP.cpp, along with it counterpart html file as web_form_OOP.html.

1.Create a class named WebApps

2.This class will contain (under public:) two functions (methods), parse and param. Use the existing function - no change necessary.

3.Leave the class definition above 'main', as demonstrated in the first video.

4.Create an object from the WebApps class and name it 'wo' (for web object).

help :]

Aucun commentaire:

Enregistrer un commentaire