Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix the error on the c++ program! #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace cgicc;

Please fix the error on the c++ program!

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

using namespace cgicc;

int main ()

{

Cgicc cgi;

Cgicc formData;

bool biking_flag, reading_flag, fishing_flag, swimming_flag;

const_cookie_iterator cci;

std::cout << "HTTP_ACCEPT_LANGUAGE\ten-US,en;q=0.9 ";

std::cout << "HTTP_CONNECTION\tkeep-alive ";

std::cout << "HTTP_HOST\tobi.kean.edu ";

std::cout << "HTTP_USER_AGENT\tMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62 ";

std::cout << "QUERY_STRING\t ";

std::cout << "REMOTE_ADDR\t10.136.32.118 ";

std::cout << "REMOTE_PORT\t61952 ";

std::cout << "REQUEST_METHOD\tGET ";

std::cout << "REQUEST_URI\t/~manoranl/cgi-bin/CPS3525/p2test1 ";

std::cout << "HTTP_REFERER\thttp://obi.kean.edu/~manoranl/courses/CPS3525/p2test1.html ";

std::cout << "CPS 3525 project 3 test 2 ";

std::cout << "Using GET Method in C++ ";

std::cout << "Number 1: 1 ";

std::cout << "Number 2: 2 ";

std::cout << "Sum of 1+2 = 3 ";

std::string name = std::getenv("QUERY_STRING");

std::string sex = std::getenv("QUERY_STRING");

std::string age = std::getenv("QUERY_STRING");

std::string gpa = std::getenv("QUERY_STRING");

std::string birthday = std::getenv("QUERY_STRING");

std::string interests = std::getenv("QUERY_STRING");

std::string dropdown = std::getenv("QUERY_STRING");

std::string textarea = std::getenv("QUERY_STRING");

std::cout << "Name: " << name << std::endl;

std::cout << "Sex: " << sex << std::endl;

std::cout << "Age: " << age << std::endl;

std::cout << "GPA: " << gpa << std::endl;

std::cout << "Birthday: " << birthday << std::endl;

std::cout << "Interests: " << interests << std::endl;

std::cout << "Dropdown: " << dropdown << std::endl;

std::cout << "Textarea: " << textarea << std::endl;

std::cout << "Content-type: text/html ";

std::cout << "Web Inputs";

std::cout << "

Web Inputs

";

std::cout << "

Name: " << name << "

";

std::cout << "

Sex: " << sex << "

";

std::cout << "

Age: " << age << "

";

std::cout << "

GPA: " << gpa << "

";

std::cout << "

Birthday: " << birthday << "

";

std::cout << "

Interests: " << interests << "

";

std::cout << "

Dropdown: " << dropdown << "

";

std::cout << "

Textarea: " << textarea << "

";

std::cout << "";

std::cout << "Set-Cookie:Path = /perl; ";

std::cout << "Set-Cookie:UserID = XYZ; ";

std::cout << "Set-Cookie:Password = XYZ123; ";

std::cout << "

";

form_iterator fi = formData.getElement("user_name");

if( !fi->isEmpty() && fi != (*formData).end()) {

cout << "User name: " << **fi << endl;

} else {

cout << "No text entered for user name" << endl;

}

cout << "
";

fi = formData.getElement("sex");

if( !fi->isEmpty() && fi != (*formData).end()) {

cout << "No text entered for radio box selected: " << **fi << endl;

}

cout << "
";

fi = formData.getElement("age");

if( !fi->isEmpty() &&fi != (*formData).end()) {

cout << "Age: " << **fi << endl;

} else {

cout << "No text entered for age" << endl;

}

cout << "
";

fi = formData.getElement("gpa");

if( !fi->isEmpty() &&fi != (*formData).end()) {

cout << "GPA: " << **fi << endl;

} else {

cout << "No text entered for gpa" << endl;

}

fi = formData.getElement("interest");

biking_flag = formData.queryCheckbox("biking");

if( biking_flag ) {

cout << "Biking Flag: ON " << endl;

} else {

cout << "Biking Flag: OFF " << endl;

}

reading_flag = formData.queryCheckbox("reading");

if( reading_flag ) {

cout << "Reading Flag: ON " << endl;

} else {

cout << "Reading Flag: OFF " << endl;

}

fishing_flag = formData.queryCheckbox("fishing");

if( fishing_flag ) {

cout << "Fishing Flag: ON " << endl;

} else {

cout << "Fishing Flag: OFF " << endl;

}

swimming_flag = formData.queryCheckbox("swimming");

if( swimming_flag ) {

cout << "Swimming Flag: ON " << endl;

} else {

cout << "Swimming Flag: OFF " << endl;

}

cout << "
";

fi = formData.getElement("dropdown");

if( !fi->isEmpty() && fi != (*formData).end()) {

cout << "Value Selected: " << **fi << endl;

}

cout << "
";

fi = formData.getElement("textcontent");

if( !fi->isEmpty() && fi != (*formData).end()) {

cout << "Text Content: " << **fi << endl;

} else {

cout << "No text entered" << endl;

}

// get list of files to be uploaded

const_file_iterator file = cgi.getFile("userfile");

if(file != cgi.getFiles().end()) {

// send data type at cout.

cout << HTTPContentHeader(file->getDataType());

// write content at cout.

file->writeToStream(cout);

}

// get environment variables

const CgiEnvironment& env = cgi.getEnvironment();

for( cci = env.getCookieList().begin();

cci != env.getCookieList().end();

++cci ) {

cout << "

";

}

cout << " ";

cout << "Setting cookies" << endl;

cout << "
";

cout << " ";

cout << " ";

const int HEIGHT = 6;

const int WIDTH = 7;

char board[HEIGHT][WIDTH] = {

{'B', 'B', 'B', 'B', 'B', 'B', 'B'},

{'B', 'T', 'T', 'B', 'B', 'T', 'B'},

{'B', 'B', 'B', 'B', 'B', 'B', 'B'},

{'B', 'B', 'B', 'T', 'B', 'B', 'B'},

{'B', 'T', 'T', 'T', 'B', 'B', 'B'},

{'B', 'B', 'B', 'B', 'B', 'B', '#'}

};

// Print board

cout << "Height: " << HEIGHT << ", width: " << WIDTH << endl;

for (int i = 0; i < HEIGHT; i++) {

cout << i+1 << ":";

for (int j = 0; j < WIDTH; j++) {

cout << board[i][j];

}

cout << endl;

}

// Print board coordinates and characters

for (int i = 0; i < HEIGHT; i++) {

for (int j = 0; j < WIDTH; j++) {

cout << "(" << j << "," << i << "): " << board[i][j] << endl;

}

}

// Count characters

int numB = 0, numT = 0, totalChars = 0;

for (int i = 0; i < HEIGHT; i++) {

for (int j = 0; j < WIDTH; j++) {

if (board[i][j] == 'B') {

numB++;

} else if (board[i][j] == 'T') {

numT++;

}

totalChars++;

}

}

// Print character count and guess

cout << "Total number of char: " << totalChars << ", number of B is " << numB << ", number of T is " << numT << endl;

int guess = 2;

cout << "Your guess is " << guess << " and there are " << totalChars << " characters" << endl;

if (guess == totalChars) {

cout << "You are correct!" << endl;

} else {

cout << "You are wrong!" << endl;

}

// Write to file

ofstream outputFile("output.txt");

if (outputFile.is_open()) {

outputFile << "Height: " << HEIGHT << ", width: " << WIDTH << endl;

for (int i = 0; i < HEIGHT; i++) {

outputFile << i+1 << ":";

for (int j = 0; j < WIDTH; j++) {

outputFile << board[i][j];

}

outputFile << endl;

}

outputFile << "Total number of char: " << totalChars << ", number of B is " << numB << ", number of T is " << numT << endl;

outputFile.close();

cout << "File uploaded and saved successfully" << endl;

} else {

cout << "Error: Unable to open file" << endl;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions


" << cci->getName() << "";

cout << cci->getValue();

cout << "