考試隨機(jī)出題程序_第1頁
考試隨機(jī)出題程序_第2頁
考試隨機(jī)出題程序_第3頁
考試隨機(jī)出題程序_第4頁
考試隨機(jī)出題程序_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、考試隨機(jī)出題程序-VB課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告這是一個(gè)隨機(jī)從題庫讀取題目并判斷是否做對了的程序一.程序簡介:1. 雙擊啟動程序后,會出現(xiàn)開始與結(jié)束兩個(gè)按鈕.單擊開始按鈕,選擇做題模式:選擇題模式,或者填空題模式.單擊選擇題模式后,將開始做選擇題.一共20道選擇題.在規(guī)定的時(shí)間內(nèi)完成所給的題目,程序能自動判斷對錯.填空題模式也是一樣.2. 程序模塊介紹:主程序背景調(diào)用了圖片 ”課程設(shè)計(jì)1.jpeg”3. 源代碼解釋在PUBLIC中,我把T(20)定義為boolean型,這樣的好處是可以判斷一道題是否已經(jīng)出過了,起始為false,默認(rèn)為沒有出現(xiàn)過這道題.出現(xiàn)后將這道題的T(i)設(shè)置為TRUE,這樣就能與沒

2、有出過的題區(qū)分開來.在確定的button中,我用了一個(gè)for 循環(huán)來判斷用戶輸入的答案是否與數(shù)據(jù)庫里的答案相同.為了能訪問數(shù)據(jù)庫,我用了data控件來與access數(shù)據(jù)庫連接.數(shù)據(jù)庫路徑使用的是相對路徑,這樣做的好處是無論程序放在哪個(gè)目錄下都能正確的讀取數(shù)據(jù)庫中的內(nèi)容.代碼中的整型變量n為做對題目的數(shù)量,整型變量a為累加器,每次加1,直到滿20道題.結(jié)束累加,并判斷正確題數(shù)的個(gè)數(shù).隨機(jī)函數(shù)前使用了randomize,利用系統(tǒng)時(shí)間對隨機(jī)函數(shù)的種子進(jìn)行初始化.timer初始化時(shí)enabled=false,當(dāng)選擇好做題類型后開始計(jì)時(shí).在做第一道題前做了一個(gè)用戶是否操作為空,如果沒有任何輸入,就返回最

3、開始,并提示用戶重新輸入一個(gè)答案.所有的變量定義在PUBLIC中,并為整型變量,便于使用.4. 附截圖兩個(gè) 5. 附源代碼:Option ExplicitDim i, n, m, max, min, x, j, a, timex, sec, total, tiankongti As IntegerDim T(20) As BooleanPrivate Sub Command1_Click()Timer1.Enabled = True For i = 0 To 3 If Option1(i).Value = True Then j = i + 1 n = n + 1 Exit For End I

4、f End If If Option1(0).Value = False And Option1(1).Value = False And Option1(2).Value = False And Option1(3).Value = False Then MsgBox "至少選擇一個(gè)選項(xiàng)" Exit Sub End If Next i If Not a = max - 1 Then a = a + 1 ElseIf a >= max - 1 Then If n >= 18 Then MsgBox "題目已做完" & "正確

5、的數(shù)目為" & n & "錯了" & max - n & "你真聰明啊!" Else MsgBox "題目已做完" & "正確的數(shù)目為" & n & "錯了" & max - n & "你還需努力啊!" End If Timer1.Enabled = False sec = 0 Label9.Caption = "" i = 0 a = 0 n = 0 m = 0 x = 0

6、 Text1.Visible = False Text2.Visible = False Text3.Visible = False Text4.Visible = False Text5.Visible = False Text6.Visible = False Command1.Visible = False Command4.Visible = False Command5.Visible = False Command6.Visible = False Command2.Visible = True Option1(0).Visible = False Option1(1).Visib

7、le = False Option1(2).Visible = False Option1(3).Visible = False Label1.Visible = False Label2.Visible = False Label3.Visible = False Label4.Visible = False Label5.Visible = False Label6.Visible = False Label7.Visible = False Label8.Visible = False For x = 0 To 20 T(x) = False Next x Exit Sub End If

8、countnum: Randomize x = Int(max - min) * Rnd() + min) If T(x) Then GoTo countnum End If T(x) = True For m = 0 To x - 1 Next mEnd SubPrivate Sub Command2_Click() timex = 60 Command4.Visible = True Command5.Visible = True max = 20 min = 0 Randomize x = Int(max - min) * Rnd() + min) T(x) = True For m =

9、 0 To x - 1 Next mEnd SubPrivate Sub Command3_Click() Unload Form1End SubPrivate Sub Command4_Click()Timer1.Enabled = TrueText1.Visible = TrueText2.Visible = TrueText3.Visible = TrueText4.Visible = TrueText5.Visible = TrueCommand1.Visible = TrueOption1(0).Visible = TrueOption1(1).Visible = TrueOptio

10、n1(2).Visible = TrueOption1(3).Visible = TrueLabel1.Visible = TrueLabel2.Visible = TrueLabel3.Visible = TrueLabel4.Visible = TrueLabel5.Visible = TrueLabel6.Visible = TrueLabel7.Visible = TrueCommand2.Visible = FalseCommand5.Visible = FalseEnd SubPrivate Sub Command5_Click()Timer1.Enabled = TrueText

11、1.Visible = TrueText2.Visible = TrueText3.Visible = TrueText4.Visible = TrueText5.Visible = TrueCommand1.Visible = FalseCommand2.Visible = FalseCommand4.Visible = FalseCommand6.Visible = TrueLabel5.Visible = TrueLabel6.Visible = TrueLabel7.Visible = TrueLabel8.Visible = TrueText6.Visible = TrueEnd S

12、ubPrivate Sub Command6_Click()If Text6.Text = "" ThenMsgBox "請輸入答案"GoTo hereEnd Ifn = n + 1End IfIf Not a = max - 1 Then a = a + 1 ElseIf a >= max - 1 Then If n >= 18 Then MsgBox "題目已做完" & "正確的數(shù)目為" & n & "錯了" & max - n & &qu

13、ot;你真聰明啊!" Else MsgBox "題目已做完" & "正確的數(shù)目為" & n & "錯了" & max - n & "你還需努力啊!" End If Timer1.Enabled = False sec = 0 Label9.Caption = "" i = 0 a = 0 n = 0 m = 0 x = 0 Text1.Visible = False Text2.Visible = False Text3.Visible = Fa

14、lse Text4.Visible = False Text5.Visible = False Text6.Visible = False Command1.Visible = False Command4.Visible = False Command5.Visible = False Command6.Visible = False Command2.Visible = True Label5.Visible = False Label7.Visible = False Label8.Visible = False For x = 0 To 20 T(x) = False Next x E

15、xit Sub End If Text6.Text = ""countnum: Randomize x = Int(max - min) * Rnd() + min) If T(x) Then GoTo countnum End If T(x) = True For m = 0 To x - 1 Next mhere:End SubPrivate Sub Form_Load()Text1.Visible = FalseText2.Visible = FalseText3.Visible = FalseText4.Visible = FalseText5.Visible =

16、FalseCommand1.Visible = FalseLabel1.Visible = FalseLabel2.Visible = FalseLabel3.Visible = FalseLabel4.Visible = FalseLabel5.Visible = FalseLabel6.Visible = FalseLabel7.Visible = FalseOption1(0).Visible = FalseOption1(1).Visible = FalseOption1(2).Visible = FalseOption1(3).Visible = FalseTimer1.Enable

17、d = FalseEnd SubPrivate Sub Timer1_Timer()If sec = 0 Then sec = 1total = timex - secLabel9.Caption = "請?jiān)?quot; & total & "秒內(nèi)做完"sec = sec + 1If total = 0 Then If n >= 18 Then MsgBox "時(shí)間到了!" & "題目已做完" & "正確的數(shù)目為" & n & "錯了&quo

18、t; & max - n & "你真聰明啊!" Else MsgBox "時(shí)間到了!" & "題目已做完" & "正確的數(shù)目為" & n & "錯了" & max - n & "你還需努力啊!" End If Timer1.Enabled = False sec = 0 Label9.Caption = "" i = 0 a = 0 n = 0 m = 0 x = 0 Text1.Visible = False Text2.

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論