#include #include //for the macros EXIT_SUCCESS and EXIT_FAILURE #include //for class string and the functions stoi, stod #include "cgi.h" //for class cgi using namespace std; int main() { cout << "Content-type: text/html\n\n" //CGI MIME-type header, 2 newlines << "\n" << "\n" << "\n" << "BMI\n" << "\n" << "\n" << "\n" << "

BMI (Body Mass Index)

\n"; //The constructor of c reads the data from the form that launched this //C++ program, or else it outputs an error message. const cgi c; const map& m {c.get_input()}; int feet {0}; auto it {m.find("feet")}; if (it == end(m)) { cout << "
Could not get feet.\n"; } else if (it->second == "") { feet = 0; } else { feet = stoi(it->second); //string to integer } double inches {0.0}; it = m.find("inches"); if (it == end(m)) { cout << "
Could not get inches.\n"; } else if (it->second == "") { inches = 0.0; } else { inches = stod(it->second); //string to double } double pounds {0.0}; it = m.find("pounds"); if (it == end(m)) { cout << "
Could not get pounds.\n"; } else if (it->second == "") { pounds = 0.0; } else { pounds = stod(it->second); } if (pounds <= 0.0) { cout << "
Your weight must be positive.\n"; } const double total_inches {12.0 * feet + inches}; if (total_inches <= 0.0) { cout << "
Your height must be positive.\n"; } //Compute the BMI (Body Mass Index). const double centimeters {2.54 * total_inches}; const double meters {centimeters / 100.0}; const double kilograms {0.45359237 * pounds}; const double bmi {kilograms / (meters * meters)}; cout << "

\n" << "With a height of " << feet << " feet " << inches << " inches, or " << centimeters << " centimeters,\n" << "
\n" << "and a weight of " << pounds << " pounds, or " << kilograms << " kilograms,\n" << "
\n" << "your BMI is " << bmi << ".\n" << "
\n" << "That’s "; //HTML right single quote struct category { string name; double bmi; }; const category a[] { {"obese", 30.0}, //obese if this number or above {"overweight", 25.0}, {"healthy", 18.5}, {"underweight", 0.0} }; for (auto cat: a) { if (bmi >= cat.bmi) { cout << cat.name; //Output the name of your category. break; } } const string url {"https://www.nhlbi.nih.gov/calculate-your-bmi"}; cout << ", according to the\n" << "NIH.\n" << "

\n\n"; string firstname, lastname, borough; it = m.find("firstname"); if (it == end(m)) { cout << "
Could not get first name.\n"; } else if (it->second == "") { cout << "
First name is empty.\n"; } else { firstname = it->second; //dont need string to integer } it = m.find("lastname"); if (it == end(m)) { cout << "
Could not get last name.\n"; } else if (it->second == "") { cout << "
last name is empty.\n"; } else { lastname = it->second; //dont need string to integer } it = m.find("borough"); if (it == end(m)) { cout << "
Could not get borough.\n"; } else if (it->second == "") { cout << "
borough is empty.\n"; } else { borough = it->second; //dont need string to integer } cout << "

\n" << "Hello, " << firstname << " " << lastname << "\n" << "
\n" << "A person from " << borough << "\n" << "

\n\n"; cout << "\n" "\n"; return EXIT_SUCCESS; }