who is tryna help me

I am just getting so many errors... HELP

// File: retrieve_form_OOP_2.cpp
// Author: Komal Dhillon
// cs102 Online
// Date: 04/09/18
// Description: This program retrieves three form fields and sends the result
// back to the browser

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

struct FIELDS
{
string name;
string value;
};



class WebApps
{
private:

string qs;
int cnt;

public: //public access specifier.



void parse(string qs, FIELDS f_name_value_pairs[]); //declared public member function parse for the class WebApps

string param(string lookUp, FIELDS f_name_value_pairs[], int f_cnt);//declared public member function param for the class WebApps

WebApps (){ //constructor

cout << "Content-type:text/html\n\n"; //get ready to print on browser
set_qs(getenv("QUERY_STRING")); //save string to private qs
//cout << "debug with get_qs: " << get_qs(); //testing functions
set_cnt(how_many(get_qs()));
//cout << "<br>debug with get_cnt: " << get_cnt();//testing functions

void set_qs(string f_getenv)
{
qs = f_getenv;
}

void set_cnt(int f_how_many)
{
cnt = f_how_many;
}

string get_qs()
{
return qs;
}

int get_cnt()
{
return cnt;
}

};


//main begins
int main()
{
WebApps wo; //created wo object of instance WebApps

FIELDS *name_value_pairs = wo.create_array(wo.get_cnt());

wo.parse(wo.get_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<wo.get_cnt; index++) {
cout << "name: " << name_value_pairs[index].name << " ";
cout << "value: " << name_value_pairs[index].value << endl << "<br>";
}


cout << "Content-type:text/html\n\n";

cout << "debug with qs: " << wo.get_qs() << " " << endl;

wo.parse(wo.get_qs(), name_value_pairs); //calling parsefunction of object wo

string first = wo.param("first", name_value_pairs, wo.get_cnt());//calling param function of object wo and storing the returned value in first

string last = wo.param("last", name_value_pairs, wo.get_cnt());//calling param function of object wo and storing the returned value in last

string season = wo.param("season", name_value_pairs, wo.get_cnt());//calling param function of object wo and storing the returned value in color


int summer,winter,fall;


cout<<"\n\n<html>";
cout<<"\n<head>";
cout<<"\n<h2>Which Season is your favorite?</h2>";
cout<<"\n<title>Parameter Parser</title>";
cout<<"\n</head>";
cout<<"\n<body>";
cout<<"\nfirst value="<<first<<"<br>";
cout<<"\nlast value="<<last<<"<br>";
cout<<"\nseason value="<<season<<"<br>";

if (season=="summer")
{
cout<< "Hello " <<first << " " << last << " You enjoy hot weather"<<endl;
}
else if (season=="winter"){
cout<< "Hello " << first << " " << last << " You like snow or cold weather"<<endl;
}
else if (season=="fall")
{
cout<< "Hello " << first << " " << last << " You enjoy Sweater Weather (so do I)"<<endl;
}

cout<<"\n</body>";
cout<<"\n</html>";
cout<<"\n\n";

return 0;
}

}

void set_qs(string f_getenv)
{
qs = f_getenv;
}

void set_cnt(int f_how_many)
{
cnt = f_how_many;
}

string get_qs()
{
return qs;
}

int get_cnt()
{
return cnt;
}

/////////////////////////////////////////////////////
// how_many()
// This will count and return how many = signs in the QUERYSTRING
////////////////////////////////////////////////////
int WebApps::how_many(string f_qs) {

int f_cnt = 0;
for (int i=0; i<f_qs.length(); i++) {
if (f_qs[i] == '=') {
f_cnt++;
}
}
return f_cnt;
}




////////////////////////////////////////////////////
//create_array
// Creates a dynamic array
////////////////////////////////////////////////////
FIELDS* WebApps:: create_array (int f_cnt) {

{

FIELDS fields[f_cnt];

return fields;

}

/////////////////////////////////////////////
// parse()
// This will separate the name/value pairs found after the ? in the URL
/////////////////////////////////////////////

void WebApps::parse (string f_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 < wo.get_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);
f_name_value_pairs[counter].name = name;
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].value = value;
}
}

/////////////////////////////////////////////
// param()
// Will receive the value for any given form field
/////////////////////////////////////////////

string WebApps::param(string lookUp, FIELDS f_name_value_pairs[], int wo.get_cnt()){
string value;
int i = 0;


for(i = 0; i< wo.get_cnt(); i++)
{
if ( lookUp == f_name_value_pairs[i].name) {
value = f_name_value_pairs[i].value;
}

}
return value;
}

};


Last edited on
Interestingly, the topic asks who is not trying to help, in archaic speech.
Here is your code with the syntax errors fixed. Be sure to enable warnings when compiling this. There are still some problems that the compiler will warn you about.

A few notes:
- When you're a beginner, write one or two functions at a time. Then compile the code and fix syntax errors. If you wait until you've created a long program (like this), you'll have so many errors that it's really hard to fix them.

- Pretty much the only thing you do with f_name_value_pairs is pass it to methods of the class WebApps. That's a pretty good hint that f_name_value_pairs should itself be a member of WebApps.
- There's no need to pass the count to parse(). I've removed it. After all, the onlyreasonable value to pass is the number of fields,which you get with get_cnt()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// File: retrieve_form_OOP_2.cpp
// Author: Komal Dhillon
// cs102 Online
// Date: 04/09/18
// Description: This program retrieves three form fields and sends the result
// back to the browser

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

struct FIELDS
{
    string name;
    string value;
};

class WebApps
{
  private:

    string qs;
    int cnt;

    int how_many(string f_qs);

  public:			//public access specifier.

    void parse(string qs, FIELDS f_name_value_pairs[]);	//declared public member function parse for the class WebApps

    string param(string lookUp, FIELDS f_name_value_pairs[]);	//declared public member function param for the class WebApps

    FIELDS *create_array(int f_cnt);

      WebApps()
    {						 //constructor

	cout << "Content-type:text/html\n\n";	 //get ready to print on browser
	set_qs(getenv("QUERY_STRING"));	//save string to private qs
//cout << "debug with get_qs: " << get_qs(); //testing functions
	set_cnt(how_many(get_qs()));
//cout << "<br>debug with get_cnt: " << get_cnt();//testing functions
    }

    void set_qs(string f_getenv)
    {
	qs = f_getenv;
    }

    void set_cnt(int f_how_many)
    {
	cnt = f_how_many;
    }

    string get_qs()
    {
	return qs;
    }

    int get_cnt()
    {
	return cnt;
    }

};

//main begins
int
main()
{
    WebApps wo;			//created wo object of instance WebApps

    FIELDS *name_value_pairs = wo.create_array(wo.get_cnt());

    wo.parse(wo.get_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 < wo.get_cnt(); index++) {
	cout << "name: " << name_value_pairs[index].name << " ";
	cout << "value: " << name_value_pairs[index].value << endl << "<br>";
    }

    cout << "Content-type:text/html\n\n";

    cout << "debug with qs: " << wo.get_qs() << " " << endl;

    wo.parse(wo.get_qs(), name_value_pairs);	 //calling parsefunction of object wo

    string first = wo.param("first", name_value_pairs);	//calling param function of object wo and storing the returned value in first

    string last = wo.param("last", name_value_pairs);	//calling param function of object wo and storing the returned value in last

    string season = wo.param("season", name_value_pairs);	//calling param function of object wo and storing the returned value in color

    int summer, winter, fall;

    cout << "\n\n<html>";
    cout << "\n<head>";
    cout << "\n<h2>Which Season is your favorite?</h2>";
    cout << "\n<title>Parameter Parser</title>";
    cout << "\n</head>";
    cout << "\n<body>";
    cout << "\nfirst value=" << first << "<br>";
    cout << "\nlast value=" << last << "<br>";
    cout << "\nseason value=" << season << "<br>";

    if (season == "summer") {
	cout << "Hello " << first << " " << last << " You enjoy hot weather" << endl;
    } else if (season == "winter") {
	cout << "Hello " << first << " " << last << " You like snow or cold weather"
	    << endl;
    } else if (season == "fall") {
	cout << "Hello " << first << " " << last <<
	    " You enjoy Sweater Weather (so do I)" << endl;
    }

    cout << "\n</body>";
    cout << "\n</html>";
    cout << "\n\n";

    return 0;
}

/////////////////////////////////////////////////////
// how_many()
// This will count and return how many = signs in the QUERYSTRING
////////////////////////////////////////////////////
int
WebApps::how_many(string f_qs)
{

    int f_cnt = 0;
    for (int i = 0; i < f_qs.length(); i++) {
	if (f_qs[i] == '=') {
	    f_cnt++;
	}
    }
    return f_cnt;
}

////////////////////////////////////////////////////
//create_array
// Creates a dynamic array
////////////////////////////////////////////////////
FIELDS *
WebApps::create_array(int f_cnt)
{

    FIELDS fields[f_cnt];

    return fields;

}

/////////////////////////////////////////////
// parse()
// This will separate the name/value pairs found after the ? in the URL
/////////////////////////////////////////////

void
WebApps::parse(string f_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 < get_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);
	f_name_value_pairs[counter].name = name;
	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].value = value;
    }
}

/////////////////////////////////////////////
// param()
// Will receive the value for any given form field
/////////////////////////////////////////////

string
WebApps::param(string lookUp, FIELDS f_name_value_pairs[])
{
    string value;
    int i = 0;

    for (i = 0; i < get_cnt(); i++) {
	if (lookUp == f_name_value_pairs[i].name) {
	    value = f_name_value_pairs[i].value;
	}

    }
    return value;
}

Topic archived. No new replies allowed.