Solved

Variables

Posted on 1998-05-11
12
153 Views
Last Modified: 2013-12-25
Is there a clean way in CGI to present a series of questions that will be 'graded' and a rolling total maintained throughout the questions. The questions might be on a series of pages. I know little to nothing about CGI. I do have appropriate tools for creating HTML and I program in C++ all the time.
0
Comment
Question by:flfmdll
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1828404
There are several ways to do this.

The easiest way is to store the score in a hidden field of the html pages.  For example, suppose you have 3 pages, each containing one question, the first page does not need to contain anything special.  When the user submit the first one, your cgi will check its answer and give it a score, the score should be written to an hidden field in the 2nd page, this means that the 2nd page must be dynamically generated (normally you will use a template html and then the cgi just replace the score), after user submit the 2nd, your cgi need to retrieve the score and then add it with the score for the current page, then generate the 3rd page.

Another way is to use cookie, which means you store the score in a cookie, this is actually quite similar to the 1st solution.

The 3rd way is to store the score in a database (or any storage on the server), this is more complicated, because you of course need to ask the user to logon so that you can store the score along with the user id.

If this score is not something very important, I suggest that you use the 1st or 2nd way.
0
 

Author Comment

by:flfmdll
ID: 1828405
I agree that 1 or 2 seem like good methods Where can I find an example to 'modify' and play around with?
0
 
LVL 7

Expert Comment

by:faster
ID: 1828406
most of such cgi are written in perl.  but using c++ is also quite easy.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1828407
I'd generally prefer the 1st method, since users seldom configure their browsers to reject hidden fields.
0
 
LVL 1

Expert Comment

by:Topace
ID: 1828408
Well, Here is a piece of code I designed.  Feel free to use it if you want.  It is in C++, so it will need to be compiled before it is placed on the net:  (It's also a multiple choice test)

<#include iostream.h>

char answer1;
char answer2;

main();
{
 cout >> "Question 1\n";   // Your first Question
 cout >> "(A) Answer 1\n"; // Possible Answers
 cout >> "(B) Answer 2\n";
 cout >> "(C) Answer 3\n";
 cout >> "(D) Answer 4\n";
 cin << answer1;

 cout >> "Question 2\n";   // Your second Question
 cout >> "(A) Answer 1\n"; // Possible Answers
 cout >> "(B) Answer 2\n";
 cout >> "(C) Answer 3\n";
 cout >> "(D) Answer 4\n";
 cin << answer2;

  if (answer1 = 'a' && answer2 = 'a')
   {
    cout >> "You have recieved an 'A' !\n"
   }
  else if )(answer1 != 'a' && answer2 = 'a')
   {
    cout >> "You have recieved a 'B' !"
   }
  else if (answer1 = 'a' && answer2 != 'a')
   {
    cout >> "You have recieved a 'B' !"
   }
  else
   {
    cout >> "You have failed this test.  Have a nice day."
   }

 return 0;

}


I may have mixed up a few things, as I am a little new to C++, but this seems like it would work.  Tell me if it does.


Topace


0
 

Author Comment

by:flfmdll
ID: 1828409
Either my question wasn't worded correctly or I don't understand your answer. These questions span multiple HTML pages. I don't see how your solution would track the score across pages.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:Topace
ID: 1828410
Hmmm....  If you adapted the code a little so that the forms from each of the pages were put in as variables, then the program could total it throughout the pages.  It wouldn't be hard....Let me think about it.  


Topace
0
 
LVL 1

Expert Comment

by:Topace
ID: 1828411
Hmmmm...

I have been thinking about this, and there has GOT to be a logical way to do it in Javascript.  However, what I have come up with is that the questions will need to be multiple choice unless you want to have it match against a string that is correct.

Do you want the questions to be multiple choice?


Topace  


0
 

Author Comment

by:flfmdll
ID: 1828412
The questions will either be Yes/No or multiple choice. At least there is nothing in the current requirements that suggest a string answer. How much harder will that make it?
0
 
LVL 1

Expert Comment

by:Topace
ID: 1828413
Here's what I have:

First off, you want javascript on your first HTML page to determine whether or not the answer chosen is correct.  Then, it should run the CGI, if the answer was correct, initilizing a variable to 1, otherwise initializing it to 0.  Then, have the CGI script pass the next HTML page on to the user, setting (If Wanted) a different question depending on whether or not the variable is 1.  Then, just increment the variable every time the client types in a right answer, with each step (Again, If Wanted) creating a new HTML question depending on whether or not the last one was correct.  Then, when you get to the last HTML page, just show them their score (The Orginal Variable) out of how many possible (A constant created with how many points are possible), and then divide the variable by the constant and multiply by 100 into a new variable to show them the percentage.  I would reccommend the last variable (Percentage) be a short unsigned, that way there will be no decimal.  

School is out tomorrow, and I will have time to type up some code illustrating this for you in the form of answer.  

I hope this helped you to understand what I have been trying (Unsuccessfully) to show you what I am going to do.


Topace
0
 
LVL 1

Accepted Solution

by:
Topace earned 50 total points
ID: 1828414
Okay, here is what I have come up with:

HTML PAGE #1:

<HTML>
<HEAD> yada yada yada...some code...</HEAD>

<BODY BACKGROUND="whatever.gif" TEXT=#whatever>
<CENTER><h1>Question 1</h1></CENTER>
<FORM NAME="theNumberOne" METHOD=POST ACTION="/cgi-bin/thescript.cgi>
<SELECT NAME="answer1">
                          <OPTION> Possible Answer1 </OPTION>
                          <OPTION> Possible Answer2 </OPTION>
                          <OPTION> Possible Answer3 </OPTION>
                          <OPTION> Possible Answer4 </OPTION>
                          </SELECT><br>
<CENTER><INPUT TYPE=SUBMIT VALUE="CHOOSE THIS ANSWER">

</BODY>
</HTML>


Now, HERE is the SCRIPT:

<#include iostream.h>  // For cout ( You can use whatever)
#define Correct_Answer1 something_here
short unsigned int No_Correct = 0;
char *pGrabbed_Answer;
pGrabbbed_Answer = getenv("QUERY_STRING");

 main()
{
 cout >> "Content-Type: text/html\n\n"
 cout >> "<HTML>"

if (pGrabbed_Answer == NULL){
 cout >> "<H1>ERROR: No content was recieved."};

else if (pGrabbed_Answer ==  Correct_Answer1){
 cout >> "<BODY BACKGROUND='whatever' TEXT=#Whatever>"
 cout >> "<CENTER><h1>NEXT QUESTION</h1></CENTER><br>"
 cout >> "<FORM NAME='Question2'><br><SELECT NAME='Answer2'>"
 cout >> "Yada Yada...Next Question CODE"
 No_Correct++;
}

else {

cout >> "<H1> SORRY, YOUR ANSWER WAS INCORRECT.</h1>

 };

}



Hope this helps, if not...I will add more.


Topace

0
 

Author Comment

by:flfmdll
ID: 1828415
Got it. Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now