Advertisement
Guest User

working_survey.cpp

a guest
May 23rd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. // File: Survey.cpp
  2. // Author:Raul A. Rodriguez M.
  3. // cs102 Online
  4. // Date:5/24/2019
  5. // Description: This program retrieves three form fields and sends the result
  6. // back to the browser
  7.  
  8. #include <iomanip>
  9. #include <iostream>
  10. #include <cstring>
  11. #include <cstdlib>
  12. #include <string>
  13. #include "WebApps.h"
  14. using namespace std;
  15.  
  16. WebApps wo;
  17.  
  18. const int cnt = wo.get_cnt();
  19.  
  20. ////////////functions/////////////
  21. void build_form () {
  22. cout << "<html>";
  23. cout << "<head></head>";
  24. cout << "<title> Survey shit </title>";
  25. cout << "<body>";
  26. cout << "<form action = \"survey.cgi\" method=\"GET\">";
  27. cout << "</form>";
  28. cout << "</body>";
  29. cout << "</html>";
  30. //simple HTML form to get started
  31. //use the one from survey_start.txt if you wish
  32. }
  33. /**********************************************************************************
  34. *********************************main begins***************************************
  35. **********************************************************************************/
  36. int main()
  37. {
  38. void build_form();
  39.  
  40. FIELDS *name_value_pairs = wo.create_array(wo.get_cnt());
  41.  
  42.  
  43. string qs(getenv("QUERY_STRING"));
  44. //string qs("first=fred&last=flint&color=red");
  45. //cout << "Content-type:text/html\n\n";
  46. //cout << "debug with qs: " << qs << "<p>" << endl;
  47.  
  48.  
  49. wo.parse(wo.get_qs(), name_value_pairs);
  50.  
  51. // debug to show content of name_value_pairs
  52. /*
  53. cout << "debug to show content of name_value_pairs array: " << endl << "<br>";
  54. for (int index = 0; index<cnt; index++) {
  55. cout << "name: " << name_value_pairs[index].name << " ";
  56. cout << "value: " << name_value_pairs[index].value << endl << "<br>";
  57. }
  58. */
  59.  
  60.  
  61. // Three fields data are retrieved from the param function
  62. string first = wo.param("first", name_value_pairs, cnt);
  63. string last = wo.param("last", name_value_pairs, cnt);
  64. string answer = wo.param("answer", name_value_pairs, cnt);
  65.  
  66. // code an HTML page, which includes the three fields
  67. // received.
  68. cout << "<html>" << endl;
  69. cout << "<head>" << endl;
  70. cout << "<title>Your Bowser Chosen</title>" << endl;
  71. cout << "</head>" << endl;
  72. cout << "<body>" << endl;
  73. cout << "<body background=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRASxpfsyKdmtMvTDuTjm3obSuoKtPseCVBaVi_MpYMIazneNrE/%22%3E\"" << endl;
  74. cout << "<form action=\"survey.cgi\" method=\"GET\">" << endl;
  75. cout << "<h1>";
  76. if(answer=="Google")
  77. {
  78. cout << first << " " << last <<", I knew you liked Google!<br>"<< endl;
  79. cout << "<img src=\"https://i.ytimg.com/vi/-QAFVAoWGuM/maxresdefault.jpg\" alt=\"GoogleMan\">";
  80. }
  81. if(answer=="Yahoo")
  82. {
  83. cout << first << " " << last << ", Slide and say Yahooo!<br>" << endl;
  84. cout << "<img src=\"https://i.ytimg.com/vi/5DpspOXs1rM/maxresdefault.jpg\" alt=\"Yahoo\">";
  85. }
  86. if(answer=="Bing")
  87. {
  88. cout <<"BING BING<br> "<< first << " " << last << ", Someone is at the Door Bell<br>"<< endl;
  89. cout << "<img src=\"https://digitalreadymarketing.com/wp-content/uploads/2015/05/Bing-question.jpg\" alt=\"bing?\">";
  90. }
  91.  
  92. cout << "</h1>";
  93. cout << "</form>";
  94. cout << "</body>";
  95. cout << "</html>";
  96.  
  97.  
  98.  
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement