class and objects pls help

i have to use class and objects for this code and its not working . can someone pls help

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
  #include <iomanip>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

struct FIELDS 
{
	string name;
	string value;
}; 

const int cnt = 4;

class WebApps 
{
public:

void parse (string qs, FIELDS f_name_value_pairs []);

string param(string lookUp, FIELDS f_name_value_pairs[], int f_cnt);



//main begins
int main()
{

WebApps wo;
	FIELDS name_value_pairs [cnt];

	string qs;//(getenv("QUERY_STRING")); 
	cout << "Content-type:text/html\n\n"; 

	wo.parse(qs, name_value_pairs); 

	string first = wo.param("first", name_value_pairs, cnt);
	string last = wo.param("last", name_value_pairs, cnt);
	string color =wo.param("color", name_value_pairs, cnt);
	string witch =wo.param("witch", name_value_pairs, cnt);
    string about =wo.param("about", name_value_pairs, cnt);
	cout<<"<html>";
	cout<<"<style type='text/css'> .card { box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); transition: 0.3s; border-radius: 8px; width: 40%; margin: auto; border: 3px solid "<<color<<";} .card:hover { box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2); } .container { padding: 2px 16px; } img { border-radius: 8px 8px 0 0; } </style>";
	cout<<"<body><div><div class='card'>";
	cout<<"<img src='"<<witch<<"' style='width:100%'>";
	cout<<"<div class='container'><h4><b>FirstName: "<<first<<"</b></h4><h4><b>LastName :"<<last<<"</b></h4></div>"<<"About:"<<about<<"</b></h4><div>";
	cout<<"</div></div></body></html>"<<endl;
	
    return 0;

}

void parse (string qs, FIELDS f_name_value_pairs [])
{	
	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); 
		start_pos = pos + 1;  
		pos = qs.find("&", start_pos);
		if (pos == string::npos) {
			pos = qs.length();
		}
		value = qs.substr(start_pos, pos - start_pos); 
		start_pos = pos + 1;

		FIELDS field = {name, value};
		f_name_value_pairs[counter] = field;

		if (pos == qs.length()){
			return;
		}
	} 
}

//*******************************************
// 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 < f_cnt; counter++) {
		if (f_name_value_pairs[counter].name == lookUp){
			return f_name_value_pairs[counter].value;
		}
	}
	return "";
}

You should look in your textbook and learn about they syntax of classes.
This code now runs. I leave it to you to fix some the warnings - if your compiler shows them.
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
#include <iomanip>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>

using namespace std;

struct FIELDS
{
  string name;
  string value;
};

const int cnt = 4;

class WebApps
{
public:

  void parse(string qs, FIELDS f_name_value_pairs[])
  {
    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);
      start_pos = pos + 1;
      pos = qs.find("&", start_pos);
      if (pos == string::npos)
      {
        pos = qs.length();
      }
      value = qs.substr(start_pos, pos - start_pos);
      start_pos = pos + 1;

      FIELDS field = { name, value };
      f_name_value_pairs[counter] = field;

      if (pos == qs.length())
      {
        return;
      }
    }
  }

  string param(string lookUp, FIELDS f_name_value_pairs[], int f_cnt)
  {

    for (int counter = 0; counter < f_cnt; counter++) {
      if (f_name_value_pairs[counter].name == lookUp) {
        return f_name_value_pairs[counter].value;
      }
    }
    return "";
  }
};


//http://cpp.sh/#
//main begins
int main()
{

  WebApps wo;
  FIELDS name_value_pairs[cnt];

  string qs;//(getenv("QUERY_STRING")); 
  cout << "Content-type:text/html\n\n";

  wo.parse(qs, name_value_pairs);

  string first = wo.param("first", name_value_pairs, cnt);
  string last = wo.param("last", name_value_pairs, cnt);
  string color = wo.param("color", name_value_pairs, cnt);
  string witch = wo.param("witch", name_value_pairs, cnt);
  string about = wo.param("about", name_value_pairs, cnt);
  cout << "<html>";
  cout << "<style type='text/css'> .card { box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); transition: 0.3s; border-radius: 8px; width: 40%; margin: auto; border: 3px solid " << color << ";} .card:hover { box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2); } .container { padding: 2px 16px; } img { border-radius: 8px 8px 0 0; } </style>";
  cout << "<body><div><div class='card'>";
  cout << "<img src='" << witch << "' style='width:100%'>";
  cout << "<div class='container'><h4><b>FirstName: " << first << "</b></h4><h4><b>LastName :" << last << "</b></h4></div>" << "About:" << about << "</b></h4><div>";
  cout << "</div></div></body></html>" << endl;

  return 0;

}
Topic archived. No new replies allowed.