您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
利用ASP+XML架设在线考试系统
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 13:33:15
nbsp;   //count no of answers
    for(i=0;i<aAnswer.length;i++){
      if(aAnswer[i] == 1)
      rights++;
    }
    strRes = "<h2 align=center><br>";

    //if all the answers are correct then greet
    if(rights == aAnswer.length)
      strRes += "<br><br>Congratulations...!";

    strRes += "<br><br>your score is " + rights;
    strRes += " out of " + aAnswer.length + "</h2>";

    document.write(strRes);
  }

  var timeCount = 0;
  function timer(){
    timeCount++;  //increment the time by one second

    //to display the time in the status bar,
    // uncomment the next line
    //window.status = "..." + timeCount + " secs" ;

    //to display the time
    temp =  "Time:   " + parseInt(timeCount/60);
    temp += "  min : " + (timeCount%60) + " sec ";
    TBlock.innerText = temp;

    //if the time is up
    if (timeCount == ExamDuration) {
      alert("Sorry, time is up");
      showResult();
    }
  }
</script>

<body>
<h2 align=center><font color=green>OnLine Exam</font></h2>

<form name=frm >
<table border=1 width=95% bgcolor=DarkSeaGreen align=center>
<tr><td align=right><b id=TBlock></b></td></tr>
<tr><td>
<p id="QArea">
<center>
<br>
Relax...! The duration of this exam is 5 minutes.
<br>
There is no order to answer a question. You may use Next as
well as Previous button to get a question to answer.
<br>
<br>
<input type=button name=btnFinish value="Start the Exam"
onClick="init()">
</center>
</p>
<input type=hidden name=ansNo>
</td></tr></table>
</form>

</body>
</html>





OLExam.asp


<%
Response.expires = 0
'create an instance of MS XMLDOM Object
'and load the QBank.xml file where all the questions are.

set obj = server.createobject("Microsoft.XMLDOM")
obj.async = false
obj.load(Server.MapPath("QBank.xml"))

'very first request from the client
if trim(request("Action")) = "Start" then
  'set no of questions per exam
  Dim NoQ,TotalQ
  
  NoQ = 5 'set no less than the totalquestions
  
  'count no of questions in the xml file
  '( or from database)
  TotalQ = obj.selectNodes("data/question").length

  Dim aQuest(),temp,isExist, strQ
  ReDim aQuest(0) 'to store the question ids
  
  'generate (=NoQ) question ids randomly
  while ubound(aQuest) < NoQ
    isExist = false
    temp = Int((TotalQ * Rnd) + 1)
    for i = 1 to ubound(aQuest)
      if aQuest(i) = temp then
        isExist = true
        exit for
      end if
    next
    if Not isExist then
      Redim Preserve aQuest(ubound(aQuest)+1)
      aQuest(ubound(aQuest)) = temp
      strQ = aQuest(i) & "," & strQ
    end if
  wend
  
  'remove the last comma ',' from strQ
  strQ = left(strQ,len(strQ)-1)
  
  'send the question in the strQ to the client
  response.write strQ
  
'all further requests - after the first request
elseif trim(request("Action")) = "NextQ" then
  'fetch the question from the XML Object
  'and form the output string
  temp = "data/question[@id=" & trim(request("QNo")) & "]"

  set Node = obj.selectSingleNode(temp)

  strXML = "<data>"
  strXML = strXML & "<qtext>"
  strXML = strXML & Node.selectSingleNode("qtext").text
  strXML = strXML & "</qtext>"
  strXML = strXML & "<answer>"
  strXML = strXML & Node.selectSingleNode("answer").text
  strXML = strXML & "</answer>"

  set Node = Node.selectNodes("choices/choice")

  for i = 0 to Node.length-1
    strXML = strXML & "<choice>"
    strXML = strXML & Node.item(i).text
    strXML = strXML & "</choice>"
  next

  strXML = strXML & "</data>"

  'send the output to the client
  Response.Write (strXML)
end if
%>





QBank.xml

<?xml version="1.0"?>
<data>
  <question id="1">
    <qtext>What does KB stand for?</qtext>
    <choices>
      <choice>Kilo Bits</choice>
      <choice>Key Board</choice>
      <choice>Kilo Bytes</choice>
      <choice>None</choice>
    </choices>
    <answer>3</answer>
  </question>
  <question id="2">
    <qtext>CPU stands for</qtext>
    <choices>
      <choice>Central Processing Unit</choice>
      <choice>Central Power Unit</choice>
      <choice>Core Processing Unit</choice>
      <choice>Core Power Unit</choice>
    </choices>
    <answer>1</answer>
  </question>
  <question id="3">
    <qtext>1 KB equals</qtext>
    <choices>
      <choice>1000 Bytes</choice>
      <choice>1024 Bytes</choice>
      <choice>1000 Bits</choice>
      <choice>1024 Bits</choice>
      <choice>Nothing</choice>
    </choices>
    <answer>2</answer>
  </question>
  <question id="4">
    <qtext>RAM is </qtext>
    <choices>
      <choice>Random Access Modifier</choice>
      <choice>Primary Memory</choice>
      <choice>Secondary Memory</choice>
      <choice>Read And Modify</choice>
    </choices>
    <answer>2</answer>
  </question>
  <question id="5">
    <qtext>Hard Disk is </qtext>
    <choices>
      <choice>Hard to break</choice>
      <choice>Primary Memory Storage</choice>
      <choice>Temporary Memory Storage</choice>
      <choice>Secondary Memory Storage</choice>
    </choices>
    <answer>4</answer>
  </question>
  <question id="6">
    <qtext>Computer Monitor is used </qtext>
    <choices>
      <choice>To monitor activities</choice>
      <choice>To control Computer</choice>
      <choice>As display unit</choice>
      <choice>None</choice>
    </choices>
    <answer>3&l

上一页  [1] [2] [3] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |