QuestionQuestion

During this week, you will create a class and several objects. Classes are basically structures containing functions and data. Of course, there is quite a bit more to OOP but at least you will create the basics of that environment.

Agenda:
1. Get the basics from youtube videos.
2. Modify retrieve_form.cpp to transform the parse() and param() functions as objects in a class.
3. Review pointers by creating more objects to work with .parse and .param

Here is what to do, in order:
1. As directed above, make a back up of the work so far and work with the new version named retrieve_form_OOP_2.cpp.

2. These additions to the class will require a 'private:' area to hold the cnt and qs variables, a 'constructor' function, as well as additional functions to access the variables in the 'private' area, as explained in videos at 1b and 1c.

3. Cheat sheet for the 'class' modification - adopt this structure to help modify your existing class: class_start.txt

The way to approach these changes is as always - one step at a time:
1. First create the constructor by adding following lines (from class_start.txt) into your existing class :

2. cout << "Content-type:text/html\n\n"; set_qs(getenv("QUERY_STRING")); cout << "debug with get_qs: " << get_qs();

3. Next create the two functions set_qs() and get_qs().

4. Now compile until it does and runs giving the proper debug message.

5. Use similar approach with 'cnt' (as get_qs() and set_qs() above) - will need function 'how_many()', which can be adapted from parse() fairly easily.

6. Once cnt works, then parse and param will need modifying to replace the variable by its call get_cnt() to produce the value from 'private:'

7. The next step would be to create the dynamic array, of which function will also reside in the class. But the calls will come from main() from this point.

Note: no need to use pointer notation with this dynamic array - treat it as a regular array (which it is, of course, since arrays are pointers).

8. Beware of the wo.get_cnt() and other object substitutions in main as well

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

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

struct FIELDS
{
string name;
string value;
};

const int cnt = 4;

class WebApps
{
public:
WebApps(){}
~WebApps(){}
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;
}
}
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$40.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats