用VB怎么设计一个算术题出题程序?
补充:要用数组,产生随机数,加号减号也随机产生,之后怎么计算,还要判断正误,评分
答案:Option Explicit
Dim Num1 As Integer, Num2 As Integer '两个操作数
Dim SExp As String
Dim Result As Single '计算结果
Dim NOk As Integer, NError As Integer '统计计算正确与错误数
Private Sub Command2_Click()
Me.Picture1.Cls
End Sub
Private Sub Form_Load() '通过产生随机数生成表达式
Dim NOp As Integer, Op As String * 1 '操作符 Randomize
'初始化随机数生成器
Num1 = Int(10 * Rnd + 1) '产生1-10之间的操作数
Num2 = Int(10 * Rnd + 1) '产生1-10之间的操作数
NOp = Int(4 * Rnd + 1) '产生1-4之间的操作代码
Select Case NOp
Case 1
Op = "+"
Result = Num1 + Num2
Case 2
Op = "-"
Result = Num1 - Num2
Case 3
Op = "×"
Result = Num1 * Num2
Case 4
Op = "÷"
Result = Num1 / Num2
End Select
SExp = Num1 & Op & Num2 & "="
Label1 = SExp
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1) = Result Then
Picture1.Print SExp; Text1; Tab(10); "√ " '计算正确
NOk = NOk + 1
Else
Picture1.Print SExp; Text1; Tab(10); "×" '计算错误
NError = NError + 1
End If
Text1 = "" '下一个表达式生成
Text1.SetFocus
Form_Load
End If
End Sub
Private Sub Command1_Click()
On Error Resume Next
Label1 = ""
Picture1.Print "----------------------------------"
Picture1.Print "一共计算 " & (NOk + NError) & " 道题,";
Picture1.Print "得分 " & Int(NOk / (NOk + NError) * 100)
End Sub
算术题
dim a,b,c
a=1
b=1
c=a+b
msgbox c
Dim Answer As Integer
Private Sub Command1_Click()
Dim num(1 To 4) As Integer
Dim count(1 To 3) As String
Dim s
Me.Cls
For i = 1 To 4
num(i) = Int(Rnd * 10)
Next i
Answer = num(1)
For i = 1 To 3
count(i) = Int(Rnd * 2)
Select Case (count(i))
Case 0
count(i) = "+"
Answer = Answer + num(i + 1)
Case 1
count(i) = "-"
Answer = Answer - num(i + 1)
End Select
s = s & num(i) & count(i)
Next i
s = s & num(4)
Print "请计算" & s & 的值
End Sub
Private Sub Command2_Click()
If Val(Text1.Text) = Answer Then
MsgBox "回答正确"
Else
MsgBox "回答错误 答案为" & Answer
End If
End Sub
'command1 为生成 题目 command2为 判断正误 text1 为 输入 答案
你的运气太好了,我们老师刚刚留完这个作业。加我腾讯聊天工具的号码吧,唔思留留令其山吧久
上一个:怎样编程,vb语言是什么
下一个:vb CreateProcess函数可以用来做什么呢。