自动编数学加法题目
小学生的作业之一就是让家长给小孩出加法题练习。我没有那么多时间出,就编写了一个小程序自动出题目。Public Function GetRndNotRepeat(ByVal NumMin As Integer, ByVal NumMax As Integer, ByVal N As Integer)
'获取NumMin~NumMax范围内的N个不重复随机整数
Dim arr() As Integer
Dim b() As Boolean
Dim x As Integer
Dim i As Integer
If N > NumMax - NumMin + 1 Or NumMax <= NumMin Or N < 1 Then
ReDim arr(-1 To -1)
GetRndNotRepeat = arr
Exit Function
End If
ReDim arr(N - 1)
ReDim b(NumMin To NumMax)
Randomize
For i = 0 To N - 1
Do
x = Int(Rnd * (NumMax - NumMin + 1)) + NumMin
Loop While b(x)
b(x) = True
arr(i) = x
Next i
GetRndNotRepeat = arr
End Function
Private Sub Command1_Click()
Dim n1 As Integer
n1 = Val(Text1.Text)
Open "d:\student.txt" For Output As #1
a = GetRndNotRepeat(1, n1, n1)
b = GetRndNotRepeat(1, n1, n1)
Print #1, Date, Time, "加法题"
Print #1, "*****************武汉工程大学 摩擦学实验室*******************"
If UBound(a) > -1 Then
For i = 0 To UBound(a)
Print #1, CStr(a(i)) & "+" & CStr(b(i)) & "= ";
Next i
End If
Close #1
Text1.Text = Int(100 * Rnd)
Shell "c:\program files\microsoft office\office11\winword.exe d:\student.txt", 1
End Sub
Private Sub Form_Load()
Text1.Text = Int(100 * Rnd)
End Sub
程序运行结果如下所示,在word里面自动打开显示。
2011-7-1
7:09:10
加法题
*****************武汉工程大学 摩擦学实验室*******************
50+68=
13+18=
11+39=
42+24=
29+22=
70+11=
59+53=
31+1=
35+28=
18+51=
61+35=
25+29=
6+42=
55+14=
45+8=
5+47=
3+58=
20+60=
38+32=
43+3=
26+50=
63+34=
58+37=
46+27=
53+6=
32+45=
7+62=
54+49=
47+48=
44+55=
10+13=
33+9=
30+59=
40+31=
16+56=
39+65=
64+33=
15+70=
9+2=
4+40=
51+19=
48+7=
60+44=
19+52=
2+17=
49+26=
37+21=
67+12=
12+66=
34+64=
57+23=
68+38=
1+41=
14+36=
27+20=
8+57=
21+61=
69+5=
36+46=
23+4=
56+15=
65+54=
22+30=
17+63=
28+16=
62+67=
52+10=
24+25=
66+69=
41+43=
;P 本帖最后由 caoer 于 2011-7-1 11:23 编辑
模仿lz,我也学习做了一个,电子版的。
有判断对错功能,省得动脑打分了。#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
main()
{
int num1, num2, num3,sum;
int q;
int qCur=1, count=0;
srand ( time(NULL) );
cout<< "Num of questions: "<< endl;
cin>> q;
do {
num1 = rand() % 100;
num2 = rand() % 100;
sum = num1+ num2;
cout<< num1<<" + " << num2 << " = ";
scanf ("%d",&num3);
if (sum == num3) count++;
qCur++;
} while (qCur <= q);
cout<< "You have " <<count<<" correct answers in total "<< q<<" questions.";
return 0;
system("AUSE");
}
caoer 发表于 2011-7-2 00:19 static/image/common/back.gif
模仿lz,我也学习做了一个,电子版的。
你这用得是C++啊 楼主用得是visual basic 呵呵 斑竹,很怀疑做这些题目的小盆友看得懂这么多英文么?
页:
[1]