浙江计算机等级考试二级VB上机调试题.docx
- 文档编号:27105295
- 上传时间:2023-06-27
- 格式:DOCX
- 页数:24
- 大小:19.95KB
浙江计算机等级考试二级VB上机调试题.docx
《浙江计算机等级考试二级VB上机调试题.docx》由会员分享,可在线阅读,更多相关《浙江计算机等级考试二级VB上机调试题.docx(24页珍藏版)》请在冰豆网上搜索。
浙江计算机等级考试二级VB上机调试题
程序调试题答案
1.----------------------------------------------------------------------------------------------------------------
PublicFunctionnFactor(ByValnAsInteger)AsDouble
DimiAsInteger
DimtempAsDouble
temp=1’----1----
Fori=1Ton
temp=temp*i
Nexti
nFactor=temp‘----2----
EndFunction
PublicSubsummary()
DimsumAsDouble
DimiAsInteger
DimnAsInteger
n=20
Fori=1Ton
sum=sum+nFactor(i)’----3----
Nexti
Form1.Print"sum="&sum‘----4----
EndSub
2.----------------------------------------------------------------------------------------------------------------
PublicSubcalculate()
Dima(1To100)AsInteger
Dimx(1To10)AsInteger
DimiAsInteger,pAsInteger
'产生100个[0,99]范围内的随机整数
'每行10个打印出来
Fori=1To100
'********错误1***********
a(i)=Int(Rnd*100)
Ifa(i)<10Then
Form1.PrintSpace
(2);a(i);
Else
Form1.PrintSpace
(1);a(i);
EndIf
IfiMod10=0ThenForm1.Print
Nexti
'统计个位上的数字分别为1,2,3,4,5,6,7,8,9,0的数的个数
'并将统计结果保存在数组x
(1),x
(2),...,x(10)中,将统计结果打印出来
Fori=1To100
'********错误2**********
p=a(i)Mod10'求个位上的数字
Ifp=0Thenp=10
'********错误3**********
x(p)=x(p)+1
Nexti
Form1.Print"统计结果"
Fori=1To10
p=i
Ifi=10Thenp=0
'********错误4*********
Form1.Print"个位数为"+Str(p)+"共"+Str(x(i))+"个"
Nexti
EndSub
3.----------------------------------------------------------------------------------------------------------------
PublicSubFindat()
'在字符串str1中查找"at"
Dimstr1AsString
DimlengthAsInteger'字符串长度
DimsumAsInteger'查到的个数
DimiAsInteger
str1=InputBox("请输入一个字符串")
length=len(str1)‘----1----
i=1
sum=0
DoWhilei<=length‘----2----
Ifmid(str1,i,2)="at"Then‘----3----
sum=sum+1
EndIf
i=i+1
Loop
Ifsum=0Then‘----4----
MsgBox"没有找到!
"
Else
MsgBox"找到了"&Str(sum)&"个"
EndIf
EndSub
4.----------------------------------------------------------------------------------------------------------------
PublicSubGuess()
DimRAsInteger
DimXAsInteger
DimtimesAsInteger
Randomize
'******错误1******
R=Int(Rnd*100)+1'产生一个1--100的任意整数
times=1
Do
X=Val(InputBox("输入猜数X"))
SelectCaseX
CaseR
Form1.Print"猜中了"
ExitDo
'*****错误2******
CaseIs>R
Form1.Print"太大了,继续猜!
"
CaseElse
Form1.Print"太小了,继续猜!
"
EndSelect
times=times+1
'******错误3******
LoopWhiletimes<=5
Iftimes>5Then
Form1.Print"猜数失败,游戏结束!
"
'******错误4******
Form1.Print"正确答案为"&Str(R)
EndIf
EndSub
5.----------------------------------------------------------------------------------------------------------------
PublicSubArmstrongNumber()
DimarmstrongAsInteger
DimiAsInteger
DimhundredAsInteger'百位上的数字
DimtenAsInteger'十位上的数字
DimoneAsInteger'个位上的数字
Fori=1To999
hundred=i\100‘----1----
ten=(IMod100)\10‘----2----
one=IMod10‘----3----
IfI=hundred^3+ten^3+one^3Then‘----4----
Form1.Printi;"isarmstrongnumber"
EndIf
Nexti
EndSub
6.----------------------------------------------------------------------------------------------------------------
PublicSubCountTo60()
'从一堆一分、二分、五分的硬币中取出20枚,使其总值为60分
'输出取法的数量及每一种取法的一分、二分、五分的个数
DimoneAsInteger'一分硬币个数
DimtwoAsInteger'二分硬币个数
DimfiveAsInteger'五分硬币个数
Constn=20'总数20枚
DimkAsInteger'取法数量
k=0
Forone=1Ton
'*******错误1********
Fortwo=1Ton-one
five=n-one-two
'*******错误2*********
Ifone+two*2+five*5=60Then
k=k+1
Form1.Print"one=";one;"two=";two;"five=";five
EndIf
'*******错误3********
Nexttwo
'******错误4******
Nextone
Form1.Print"k=";k
EndSub
7.----------------------------------------------------------------------------------------------------------------
PrivateConstn=10
Privatea(1Ton)AsInteger
'TJ过程是将一批数据中小于零的数及它们的积打印出来
'数据由SCSJ过程产生,数据的取值范围为-10~10之间的随机整数
PublicSubTJ()
DimiAsInteger
DimtAsSingle
t=1‘--------1--------
Fori=1To10
Ifa(i)<0Then‘--------2--------
t=t*a(i)
EndIf
Nexti
Form1.Print"T=";t
EndSub
PublicSubSCSJ()
Randomize
Form1.Print"原始数据"
DimiAsInteger
DimjAsInteger
Fori=1Ton
'随机产生0或1,为0时取负,为1时取正
j=Int(Rnd*2)
Ifj=0ThenJ=-1‘------3-----
a(i)=j*Int(Rnd*(n+1))
Form1.Printa(i);
Nexti
Form1.Print
EndSub
8.----------------------------------------------------------------------------------------------------------------
Dimsalary(7)AsInteger
PublicSubMoney()
DimhundredAsInteger,totalhundredAsInteger'100元票面数量、总数量
DimfiftyAsInteger,totalfiftyAsInteger'50元票面数量、总数量
DimtenAsInteger,totaltenAsInteger'10元票面数量、总数量
DimfiveAsInteger,totalfiveAsInteger'5元票面数量、总数量
DimoneAsInteger,totaloneAsInteger'1元票面数量、总数量
DimtotalsalaryAsInteger'工资总计
DimiAsInteger,tempAsInteger
totalhundred=0
totalfifty=0
totalten=0
totalfive=0
totalone=0
totalsalary=0
Fori=1To7
temp=salary(i)‘----1----
hundred=Int(temp/100)
temp=salary(i)Mod100‘----2----
fifty=Int(temp/50)
temp=temp-fifty*50
ten=Int(temp/10)
temp=temp-ten*10
five=Int(temp/5)
temp=temp-five*5
one=temp‘----3----
totalhundred=totalhundred+hundred
totalfifty=totalfifty+fifty
totalten=totalten+ten
totalfive=totalfive+five
totalone=totalone+one
totalsalary=totalfifty+totalten+totalfive+totalone‘----4----
Nexti
Form1.Print"共需100元"&Str(totalhundred)&"张"
Form1.Print"共需50元"&Str(totalfifty)&"张"
Form1.Print"共需10元"&Str(totalten)&"张"
Form1.Print"共需5元"&Str(totalfive)&"张"
Form1.Print"共需1元"&Str(totalone)&"张"
Form1.Print"合计"&Str(totalsalary)&"元"
EndSub
PublicSubSalaryData()
salary
(1)=1398
salary
(2)=1765
salary(3)=689
salary(4)=1500
salary(5)=832
salary(6)=590
salary(7)=1200
EndSub
9.----------------------------------------------------------------------------------------------------------------
Dima(1To5,1To4)AsInteger
Dimave(1To5)AsInteger
PublicSubMaxLine()
DimiAsInteger
DimjAsInteger
DimtempAsInteger
DimLine_noAsInteger'最大平均值的行号
'找出最大平均值所在行
Line_no=1
Fori=2To5
'******错误1*******
Ifave(Line_no) '******错误2******* Line_no=i EndIf Nexti '交换第一行与最大平均值所在行 Forj=1To4 temp=a(1,j) '******错误3****** a(1,j)=a(Line_no,j) a(Line_no,j)=temp Nextj '交换对应行的平均值 temp=ave (1) ave (1)=ave(Line_no) ave(Line_no)=temp '打印交换后的数据 Form1.Print"交换后的数据和平均值" PrintArray EndSub PublicSubDataProduce() DimiAsInteger DimjAsInteger '产生5*4数组 Fori=1To5 Forj=1To4 a(i,j)=Int(100*Rnd) Nextj Nexti EndSub PublicSubAverage() DimiAsInteger DimjAsInteger DimsumAsInteger '计算各行平均值 Fori=1To5 sum=0 Forj=1To4 '******错误4****** sum=sum+a(i,j) Nextj ave(i)=sum/4 Nexti '将数组和平均值打印出来 Form1.Print"原始数据和平均值" PrintArray EndSub PublicSubPrintArray() DimiAsInteger DimjAsInteger Fori=1To5 Forj=1To4 Form1.Printa(i,j);Spc(3); Nextj Form1.Print"平均值=";ave(i) Nexti EndSub 10.---------------------------------------------------------------------------------------------------------------- PublicSubWrap() DimlengthAsInteger Dimstr1AsString DimstrleftAsString DimstrrightAsString DimkAsInteger str1=InputBox("请输入任意的字符串")'输入任意字符串 '****错误1***** length=Len(str1) k=1 Do '****错误2***** strleft=Mid(str1,k,1)'从左边起逐个取出一个字符 '****错误3***** strright=Mid(str1,length-k,1)'从右边起逐个取出一个字符 '****错误4**** Ifstrleft<>strrightThen ExitDo EndIf k=k+1 LoopWhilek<=length/2 Ifk>length/2Then Form1.Printstr1&"是回文" Else Form1.Printstr1&"不是回文" EndIf EndSub 11.---------------------------------------------------------------------------------------------------------------- PrivateConstn=10 Privatea(1Ton)AsInteger 'BubbleSort过程是冒泡排序 'Swap过程交换两个变量数值 'GenerateData过程产生10个[1,20]之间互不相同的随机整数 PublicSubBubbleSort() DimiAsInteger,jAsInteger i=1 Do Forj=i+1Ton Ifa(j)>a(i)Then '*******1********* CallSwap(a(j),a(i)) EndIf Nextj i=i+1 '*******2******* LoopWhileI<=n Form1.Print"排序结果" Fori=1Ton Form1.Printa(i); Nexti EndSub PublicSubGenerateData() DimiAsInteger DimjAsInteger DimbAsBoolean Fori=1Ton b=False DoWhileNotb a(i)=Int(20*Rnd+1) b=True '******3****** Forj=1ToI-1 Ifa(i)=a(j)Then b=False ExitFor EndIf Nextj Loop Form1.Printa(i) Nexti EndSub '********4******** PublicSubSwap(aAsInteger,bAsInteger) DimtempAsInteger temp=a a=b b=temp EndSub 12.---------------------------------------------------------------------------------------------------------------- PublicSubTransfer() DimHexAsString'十六进制数 DimDecAsDouble'十进制数 DimtempAsString DimiAsInteger DimnAsInteger Hex=InputBox("输入一个十六进制整数") '******错误1******* n=Len(Hex) i=0 Do '******错误2******* temp=Mid(Hex,i+1,1) '******错误3******* Dec=Dec+number(temp)*16^i i=i+1 LoopWhilei '******错误4****** Form1.PrintHex&"转换为十进制数为"&str(Dec) EndSub PublicFunctionnumber(strAsString)AsInteger SelectCasestr Case"a","A" number=10 Case"b","B" number=11 Case"c","C" number=12 Case"d","D" number=13 Case"e","E" number=14 Case"f","F" number=15 CaseElse number=Val(str) EndSelect EndFun
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 浙江 计算机等级考试 二级 VB 上机 调试