I am clueless about making my test generator program to generate random questions.... Help

2002-03-22 Thread FLAHERTY, JIM-CONT

I have a script that generates test questions  and grades them .  I was
asked to make them generate in a random order , can someone point me in the
right direction 
 
They come in two files  make_test.cgi   and grade.cgi 
 
 
 
#! /usr/bin/perl
#
#make test  for Cram Program
#
#   version 0.02  mar 18 2002
#

require "subparseform.lib";
&Parse_Form;
 
$name = $formdata{'name'};
$test = $formdata{'test1'};
 
##
#  connect to DB

use DBI;
my $database = "cram";
my $data_source = "DBI:mysql:$database";
my $username = "root";
my $password = "elaine";
 


##  make sure they havent taken the test before

 
# $dbh = DBI -> connect($data_source, $username, $password)
 

# my $sth = $dbh1 -> prepare("select * from scores where name = '$name' and
test = '$test'");
 
# $sth -> execute
 

# $result = "$result
 
# if($result ne "") {
 
 
 
 
 
 
 
 
 

# my Arrary
 
 
 
 
 
 
 
 
 
 
 
 
 
##
###Make Random   # 
##
 
 
 
 
 
 
 
 
 
 
 

$dbh =DBI ->connect($data_source, $username, $password) or die "cant connect
to
$data_source : my $dbh-> errstr\n";
 
 
 
 
 
 
 
 
 
my $sth1 = $dbh -> prepare("select * from tests where subject = '$test' ");
$sth1 -> execute or die " unable to execute query ";
#$sth1 -> finish;
 
 
 
 
 
 
 
##
#   make count
  $count = 0;
###
# make Page

print "content-type: text/html\n\n";
print "\n";
print " Welcome ";
print "$name";
print " \n";
print "\n";
 
print "\n\n";
 
print "$name  \n";
print "$test Test \n";
print "\n";
 
print "\n";
print "\n";
print "\n";
 
print "\n";
print "\n";
print "\n";
my $array_ref = $sth1 -> fetchall_arrayref();
 
   foreach $row(@$array_ref){
 
##
#   Count Routine
##
#
 $count ++;
#
my($num, $subject, $ques,$quesA, $quesB, $quesC, $quesD,$quesE,$ans) =
@$row;
 
$tot_ans = 0;
 
print "\n";
 
print "$num\n";
print " \n";
print "$ques\n";
 
$c_ans = $num."c_ans";
 
print "    \n";
 
print "  \n";
print "\n";
 
$ques1a = $num."a";
if ($quesA ne ""){
$tot_ans++;
print "\n\n";
print " \n\n";
 
print " A.\n";
 
print "$quesA  \n";
print "\n";
 
}
 

$ques1b = $num."b";
if ($quesB ne ""){
$tot_ans++;
print "\n";
 
$num_a = $num;
print " \n";
 
print " B.\n";
print "$quesB\n";
print "\n";
 
}
 
 
 
$ques1c = $num."c";
 
if ($quesC ne ""){
$tot_ans++;
print "\n";
print " \n";
 
print " C.\n";
print "$quesC\n";
print "\n";
 
}
 

$ques1d = $num."d";
 
if ($quesD ne ""){
 
$tot_ans++;
print "\n";
 
print " \n";
 

print " D.\n";
print "$quesD \n";
print "\n";
 
}
 
 
 
if ($quesE ne ""){
$tot_ans++;
$ques1e = $num."e";
 
print "\n";
print " \n";
 
print " E.\n";
print "$quesE \n";
print "\n";
 
}
 

$ques1f = $num."f";
 
if ($quesf ne ""){
 
$tot_ans++;
print "\n";
 
print " \n";
 

print " f.\n";
print "$quesf \n";
print "\n";
 
  }
 
$tot_ans1 = $num."tot_ans1";
print "\n";
 

}
 
print "\n";
 
 
 
print "\n";
print "\n";
print "\n";
 
print "\n";
print "\n";
 

print "\n";
print "\n";
 
 
 
 
 
 
 
 
 
 
#! /usr/bin/perl
#user grading script
#
#   Mar 18, 2002 ver 0.02

require "subparseform.lib";
&Parse_Form;
 
 
 
$test = $formdata{'test12'};
$sname = $formdata{'name'};
 
 
 

##
#  connect to DB

use DBI;
my $database = "cram";
my $data_source = "DBI:mysql:$database";
my $username = "root";
my $password = "elaine";
 
$dbh =DBI ->connect($data_source, $username, $password) or die "cant connect
to
$data_source : my $dbh-> errstr\n";
 
my $sth1 = $dbh -> prepare("select * from tests where subject = '$test' ");
 

$sth1 -> execute or die " unable to execute query ";
#$sth1 -> finish;
 

###
# make Page

print "content-type: text/html\n\n";
print "\n";
print " Welcome ";
print "$sname";
print " \n";
print "\n";
 
print "https://kins2158/cram/notebook.jpg\";
 >\n";
 
print "$sname  \n";
print " Test results for Test : $test \n";
print "\n";
my $array_ref = $sth1 -> fetchall_arrayref();
 
 
 


###   Get Date   ###

 
@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday",
  "Friday","Saturday");
@months = ("January","February","March","April","May","June",
   "July","August","September","October","November",
 

RE: I am clueless about making my test generator program to generate random questions.... Help

2002-03-22 Thread Nikola Janceski

This worked for me while I was a TA.

my $numberOfStudents = scalar keys %Grade;

my @studentGrades = map { rand(100) } (1 .. $numberOfStudents);

foreach my $student (keys %Grade){
%Grade{$student} = shift @studentGrades;
}

> -Original Message-
> From: FLAHERTY, JIM-CONT [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 22, 2002 1:51 PM
> To: Jim (E-mail); Beginners (E-mail)
> Subject: I am clueless about making my test generator program to
> generate random questions Help
> 
> 
> I have a script that generates test questions  and grades 
> them .  I was
> asked to make them generate in a random order , can someone 
> point me in the
> right direction 
>  
> They come in two files  make_test.cgi   and grade.cgi 
>  
>  
>  
> #! /usr/bin/perl
> #
> #make test  for Cram Program
> #
> #   version 0.02  mar 18 2002
> #
> 
> require "subparseform.lib";
> &Parse_Form;
>  
> $name = $formdata{'name'};
> $test = $formdata{'test1'};
>  
> ##
> #  connect to DB
> 
> use DBI;
> my $database = "cram";
> my $data_source = "DBI:mysql:$database";
> my $username = "root";
> my $password = "elaine";
>  
> 
> 
> ##  make sure they havent taken the test before
> 
>  
> # $dbh = DBI -> connect($data_source, $username, $password)
>  
> 
> # my $sth = $dbh1 -> prepare("select * from scores where name 
> = '$name' and
> test = '$test'");
>  
> # $sth -> execute
>  
> 
> # $result = "$result
>  
> # if($result ne "") {
>  
>  
>  
>  
>  
>  
>  
>  
>  
> 
> # my Arrary
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> ##
> ###Make Random   # 
> ##
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> 
> $dbh =DBI ->connect($data_source, $username, $password) or 
> die "cant connect
> to
> $data_source : my $dbh-> errstr\n";
>  
>  
>  
>  
>  
>  
>  
>  
>  
> my $sth1 = $dbh -> prepare("select * from tests where subject 
> = '$test' ");
> $sth1 -> execute or die " unable to execute query ";
> #$sth1 -> finish;
>  
>  
>  
>  
>  
>  
>  
> ##
> #   make count
>   $count = 0;
> ###
> # make Page
> 
> print "content-type: text/html\n\n";
> print "\n";
> print " Welcome ";
> print "$name";
> print " \n";
> print "\n";
>  
> print " print "background=\"notebook.jpg\">\n\n";
>  
> print "$name  \n";
> print "$test Test \n";
> print "\n";
>  
> print "\n";
> print "\n";
> print "\n";
>  
> print "  
> print " method=\"post\" ";
> print " name=\"cramtest\">\n";
> print "\n";
> print "\n";
> my $array_ref = $sth1 -> fetchall_arrayref();
>  
>foreach $row(@$array_ref){
>  
> ##
> #   Count Routine
> ##
> #
>  $count ++;
> #
> my($num, $subject, $ques,$quesA, $quesB, $quesC, $quesD,$quesE,$ans) =
> @$row;
>  
> $tot_ans = 0;
>  
> print "\n";
>  
> print "$num\n";
> print " \n";
> print "$ques\n";
>  
> $c_ans = $num."c_ans";
>  
> print "     value=\"$ans\">\n";
>  
> print "  \n";
> print "\n";
>  
> $ques1a = $num."a";
> if ($quesA ne ""){
> $tot_ans++;
> print "\n\n";
> print "  name=\"$ques1a\"\n";
> print "value=\"ON\">\n\n";
>  
> print " A.\n";
>  
> print "$quesA  \n";
> print "\n";
>  
> }
>  
> 
> $ques1b = $num."b";
> if ($quesB ne ""){
> $tot_ans++;
> print "\n";
>  
> $num_a = $num;
> print "  name=\"$ques1b\" "