[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

生成(批阅)简单计算题的VBS

  1. set ws=createobject("wscript.shell")
  2. set fso=createobject("scripting.filesystemobject")
  3. '----------------------------------------------------------------------------
  4. if wscript.arguments.count=0 then
  5.         do
  6.                 n=replace(inputbox("请输入您要生成的算法及题目个数:" & vbcrlf & vbcrlf & "A 加法练习(+)" & vbcrlf & "B 减法练习(-)"& vbcrlf & "C 乘法练习(×)"& vbcrlf & "D 除法练习(÷)" & vbcrlf & "E 混合运算练习(+,-,(,))" & vbcrlf & vbcrlf &"生成100道加法练习请输入:(A100)","系统提示","A100")," ","")
  7.                 if n="" or n=false then wscript.quit:msgbox "脚本退出!",4096
  8.                 if asc(lcase(left(n,1)))<97 or asc(lcase(left(n,1)))>101 then
  9.                         msgbox "1输入错误,请重新输入!",16+4096,"错误"
  10.                 elseif not isnumeric(mid(n,2)) then
  11.                         msgbox "2输入错误,请重新输入!",16+4096,"错误"
  12.                 else
  13.                         exit do
  14.                 end if
  15.         loop
  16.         Select Case lcase(left(n,1))
  17.                 Case "a":jiafa(mid(n,2))
  18.                 Case "b":jianfa(mid(n,2))
  19.                 Case "c":chengfa(mid(n,2))
  20.                 Case "d":chufa(mid(n,2))
  21.                 Case "e":hunhe(mid(n,2))
  22.         End Select
  23.         msgbox "文件已生成,练习完成后可以把练习题拖动到该脚本上进行批阅!",4096+48,"友情提示"
  24. else
  25.         if lcase(right(wscript.arguments(0),3))<>"txt" then msgbox "对不起,你拖放的不是文本文件!",16+4096,"错误":wscript.quit
  26.         piyue(wscript.arguments(0))
  27. end if
  28. '----------------------------------------------------------------------------
  29. sub jiafa(a) '100以内加法练习
  30.         randomize
  31.         for i=1 to a
  32.                 s1=s1 & int(rnd()*50) & "+" & int(rnd()*50) & "=" & vbcrlf & vbcrlf
  33.         next
  34.         call createfile("加法练习.txt",s1)
  35. end sub
  36. '----------------------------------------------------------------------------
  37. sub jianfa(a) '减法练习
  38.         randomize
  39.         for i=1 to a
  40.                 x=int(rnd()*100)
  41.                 y=int(rnd()*100)
  42.                 if x<y then tmp=x:x=y:y=tmp
  43.                 s2=s2 & x & "-" & y & "=" & vbcrlf & vbcrlf
  44.         next
  45.         call createfile("减法练习.txt",s2)
  46. end sub
  47. '----------------------------------------------------------------------------
  48. sub chengfa(a) '九九表练习(个位数的乘法)
  49.         randomize
  50.         for i=1 to a
  51.                 s3=s3 & int(rnd()*10) & "×" & int(rnd()*10) & "=" & vbcrlf & vbcrlf
  52.         next
  53.         call createfile("个位数的乘法.txt",s3)
  54. end sub
  55. '----------------------------------------------------------------------------
  56. sub chufa(a) '除法练习(个位数的除法)
  57.         randomize
  58.         m=split("1÷1;2÷1;3÷1;4÷1;5÷1;6÷1;7÷1;8÷1;9÷1;2÷2;4÷2;6÷2;8÷2;10÷2;12÷2;14÷2;16÷2;18÷2;3÷3;6÷3;9÷3;12÷3;15÷3;18÷3;21÷3;24÷3;27÷3;4÷4;8÷4;12÷4;16÷4;20÷4;24÷4;28÷4;32÷4;36÷4;5÷5;10÷5;15÷5;20÷5;25÷5;30÷5;35÷5;40÷5;45÷5;6÷6;12÷6;18÷6;24÷6;30÷6;36÷6;42÷6;48÷6;54÷6;7÷7;14÷7;21÷7;28÷7;35÷7;42÷7;49÷7;56÷7;63÷7;8÷8;16÷8;24÷8;32÷8;40÷8;48÷8;56÷8;64÷8;72÷8;9÷9;18÷9;27÷9;36÷9;45÷9;54÷9;63÷9;72÷9;81÷9",";")
  59.         l=ubound(m)
  60.         for i=1 to a
  61.                 s4=s4 & m(int(rnd()*l)) & "=" & vbcrlf & vbcrlf
  62.         next
  63.         call createfile("除法练习.txt",s4)
  64. end sub
  65. '----------------------------------------------------------------------------
  66. sub hunhe(a) '混合运算
  67.         randomize
  68.         for i=1 to a
  69.                 w=int(rnd()*3)
  70.                 select case w
  71.                         case 0 'a+b+c或a+(b+c)
  72.                                 x=int(rnd()*33):y=int(rnd()*33):z=int(rnd()*33)
  73.                                 if y mod 2=0 then
  74.                                         s5=s5 & x & "+" & y & "+" & z &"=" & vbcrlf & vbcrlf
  75.                                 else
  76.                                         s5=s5 & x & "+(" & y & "+" & z &")=" & vbcrlf & vbcrlf
  77.                                 end if
  78.                         case 1 'a+b-c或a-b+c或a+(b-c)
  79.                                 x=int(rnd()*100)
  80.                                 y=int(rnd()*100)
  81.                                 if x<y then tmp=x:x=y:y=tmp
  82.                                 if x mod 2=0 then
  83.                                         if y mod 2=0 then
  84.                                                 s5=s5 & int(rnd()*50) & "+" & x & "-" & y &"=" & vbcrlf & vbcrlf
  85.                                         else
  86.                                                 s5=s5 & int(rnd()*50) & "+(" & x & "-" & y &")=" & vbcrlf & vbcrlf
  87.                                         end if
  88.                                 else
  89.                                                 s5=s5 & x & "-" & y & "+" & int(rnd()*50) &"=" & vbcrlf & vbcrlf
  90.                                 end if
  91.                         case 2 'a-b-c或a-(b-c)或a-(b+c)
  92.                                 x=int(rnd()*100)
  93.                                 y=int(rnd()*100)
  94.                                 if x<y then tmp=x:x=y:y=tmp
  95.                                 h=x-y
  96.                                 z=int(rnd()*100)
  97.                                 if z=<h then
  98.                                         s5=s5 & x & "-" & y & "-" & z & "=" & vbcrlf & vbcrlf
  99.                                 elseif z>=x+y then
  100.                                         if z mod 2=0 then
  101.                                                 s5=s5 & z & "-" & x & "-" & y & "=" & vbcrlf & vbcrlf
  102.                                         else
  103.                                                 s5=s5 & z & "-(" & x & "+" & y & ")=" & vbcrlf & vbcrlf
  104.                                         end if
  105.                                 else
  106.                                         s5=s5 & z & "-(" & x & "-" & y & ")=" & vbcrlf & vbcrlf
  107.                                 end if
  108.                 end select
  109.         next
  110.         call createfile("混合运算.txt",s5)
  111. end sub
  112. '----------------------------------------------------------------------------
  113. sub createfile(name,a)
  114.         set file=fso.createtextfile(name)
  115.         file.write a
  116.         file.close
  117. end sub
  118. '----------------------------------------------------------------------------
  119. sub piyue(a)
  120.         dui=0:chuo=0
  121.         set file=fso.opentextfile(a)
  122.         do while file.atendofstream<>true
  123.                 t=file.readline:t=replace(t," ",""):t=replace(t,"○",""):t=replace(t,"●",""):l=instr(t,"=")
  124.                 if t<>"" and mid(t,l+1)<>"" then
  125.                         tc=replace(t,"×","*"):tc=replace(tc,"÷","/")
  126.                         if eval(left(tc,l-1))=cint(mid(t,l+1)) then
  127.                                 ts=ts & t & space(30-len(t)) & "○" & vbcrlf
  128.                                 dui=dui+1
  129.                         else
  130.                                 ts=ts & t & space(30-len(t)) & "●" & vbcrlf
  131.                                 chuo=chuo+1
  132.                         end if
  133.                 else
  134.                         if t<>"" then
  135.                                 ts=ts & t & space(30-len(t)) & "●" & vbcrlf
  136.                                 chuo=chuo+1
  137.                         else
  138.                                 ts=ts & t & vbcrlf
  139.                         end if
  140.                 end if
  141.         loop
  142.         file.close
  143.         set file=fso.createtextfile(a)
  144.         file.write ts
  145.         file.close
  146.         cj="共:"&dui+chuo&"道题,答对"&dui&"道题,得分:"& left(dui/(dui+chuo)*100,5)
  147.         ws.run chr(34) & a & chr(34)
  148.         msgbox cj,48+4096,"成绩"
  149. end sub
复制代码

好东西 ! 怎么没有人顶呢? 谢谢,,,,,

TOP

返回列表