好文档 - 专业文书写作范文服务资料分享网站

VB期末考试试题及答案(1)

天下 分享 时间: 加入收藏 我要投稿 点赞

Private Sub Command1_Click() Dim a As Variant, s As Integer Dim i As Integer, j As Integer a = Array(1, 2, 3, 4) j = 1

For i = 3 To 0 Step -1 s = s + a(i) * j j = j * 10 Next i Print s

End Sub

5、程序运行时,单击Command1按钮,显示结果是___【5】___。

Private Sub Command1_Click() Dim i As Integer, n As Integer For i = 1 To 100 i = i + 4 n = n + 1 i = i + 2

If i > 30 Then Exit For Next i Print n, i

End Sub

五、 编写程序题

请将程序代码写在答题卷对应位置处,答在试卷上不得分。

1、生成大小为1到100的50个随机整数,使用选择排序法对这些数进行由小到大的排序,并将其显示出来。(8分)

2、编写一函数过程计算1到n的累乘,参数n在调用时传递,函数名为mul。在主程序中调用该函数完成计算sum=1!+2!+3!+4!+5!,然后把sum结果打印出来。(6分)

3、找出所有四位整数的回文数,并把找出的这些回文数保存在顺序文件”c:\\abc.txt”中。(顺读和倒读都一样的字符串称“回文”,如:“level”,“1221”) (6分)

第一部分:客观题

一、 单项选择题

1-5、 DDBDD 6 -10、 CBDDC 11-15、 DADBD 16-20、 CBBBC 21-25、 BBDBC 26-30 、DACBD

二、 判断题

1、B 2、B 3、B 4、A 5、A 6、B 7、B 8、B 9、B 10、B

第二部分:主观题

三、填空题

1、a^2+b^2 2、86.57

3、 157 4、 REM 5、 “A” 6、 属性

7、 100 8、 int(rnd*90+10) 9、 true 10、 false

四、读程序写结果题

1、3 2、11 3、22 4、1234 5、5, 35

五、编写程序题

1、生成大小为1到100的50个随机整数,使用选择法对这些数进行由小到大的排序,并将其显示出来。

Private Sub Command1_Click() Dim a(49) as integer (1分) Dim i as integer, k as integer Randomize Time For i=0 to 49

a(i)=Int(Rnd*(100-1+1)+1) (1分) next i

for i=0 to 48 (1分) k=I (1分) for j=i+1 to 49 (1分) if a(k)>a(j) then k=j (1分) next j

tmp=a(i): a(i)=a(k): a(k)=tmp (1分)

next i

for i=0 to 49 print a(i); (1分) next i End Sub

2、编写一函数过程计算1到n的累乘,参数n在调用时传递,函数名为mul。在主程序中调用该函数完成计算sum=1!+2!+3!+4!+5!,然后把sum结果打印出来。 Private Sub Command1_Click() Dim sum as Integer, I as integer Sum=0 (1分) For i=1 to 5

Sum=Sum+mul(i) (1分) Next i

Print sum (1分) End sub

Private Function mul(n as integer) as integer (1分) Dim s as integer, i as integer S=1 For i=1 to n

S=s*i (1分) Next i

Mul=s (1分) End Sub

3、找出所有四位整数的回文数,并把找出的这些回文数保存在顺序文件”c:\\abc.txt”中。(顺读和倒读都一样的字符串称“回文”,如:level,1221) Private Sub Command1_Click()

Dim i As Integer, n As Integer, s As String Dim j As Integer

Open “c:\\abc.txt” for Output As #1 (1分)

For i = 1000 To 9999 (1分) s = Trim(Str(i)) (1分)

If Mid(s, 1, 1) = Mid(s, 4, 1) And Mid(s, 2, 1) = Mid(s, 3, 1) Then (2分) Print #1, s (1分) End If Next i

Close #1 End Sub

ViSual Basic程序设计上机试题

考试要求:

1、考试时间为2个小时。

2、不得使用U盘,不得使用VB课件:违反此要求者按作弊处理。 3、考试目录为F:\\Source,要求将程序保存到该文件夹下。

4、每完成一题,在该文件夹中保存以题目序号命名的frm和vbp文件。例如第二题的结果保存为2.frm和2.vbp。

第一题:

1、设计一个算程序。其占20%,期和50%。程和1.vbp。

20分

如下界面的成绩计中总评成绩中平时中和期末各占30%序结果保存为1.frm

参考代码:

Private sub Command1_Click()

Label1.caption=0.2*val(text1)+0.3*val(text2)+0.5*val(text3) End Sub

Private sub Command2_Click()

Text1=””: Text2=”” : Text3=”” Text1.setfocus End Sub

第二题:20分

一个四位数,各位之和等于其前两位,各位之积各于其后二位,试求之。界面自定。 程序结果保存为2.frm和2.vbp。

参考答案:

该题的结果为1236

For a=1 to 9 For b=0 to 9 For c=0 to 9 For d=0 to 9

X=1000*a+100*b+10*c+d

If a+b+c+d=10*a+b and a*b*c*d=10*c+d then print x Next d,c,b,a

VB期末考试试题及答案(1)

PrivateSubCommand1_Click()DimaAsVariant,sAsIntegerDimiAsInteger,jAsIntegera=Array(1,2,3,4)j=1Fori=3To0Step-1s=
推荐度:
点击下载文档文档为doc格式
2ttpn9wb6d47le14lopx1jxus0hl5300vth
领取福利

微信扫码领取福利

微信扫码分享