《西科大网络教育《程序设计语言VB》指导书作业参考答案.docx》由会员分享,可在线阅读,更多相关《西科大网络教育《程序设计语言VB》指导书作业参考答案.docx(13页珍藏版)》请在第一文库网上搜索。
1、西科大网络教育程序设计语言VB指导书作业参考答案第1题PrivateSubCommand1_C1ick()DimaAs1ongDimnAsIntegern=0a=Va1()DoIfa100000Thena=a*2n=n+1E1seExitDoEndIf1oopMSgBOX”共翻“&n&”倍”EndSub第2题PrivateSubCommand1_C1ick()Fori=1To50Forj=2To50Step2Fork=5To50Step5Ifi+j+k=50ThenPrinti&”个1分+“&j&”个2分+&k&”个5分”EndIfNextkNextjNextiEndSub第3题Private
2、SubCommand1_C1ick()Dimprod(4)AsSing1eDima1IprodAsSing1eDimmaxAsSing1eDimposAsInteger,最大数位置a1Iprod=0max=0pos=0Fori=1To4prod(i)=InPUtBoX(输入第“&i&”个季度的产量”)a1Iprod=a1Iprod+prod(i)Ifmaxprod(i)Thenmax=prod(i)EndIfNextiFori=1To4Print&i&季度的产量占全年的百分比=&prod(i)/a11prod*100&%Ifprod(i)=maxThenpos=iEndIfNextiPrint
3、”最大产量的季度=&POSEndSub第4题PrivateSubCommand1_C1ick()DimaAsSing1eDimnAsIntegern=Oa=Va1()Doa=a*0.5n=n+1Ifa0.001ThenExitDoEndIf1oopMSgBOX分半的次数=&nEndSub第5题PrivateSubCommand1_C1ick()DimscoreAsSing1eDima,b,c,dAsIntegera,b,c,d分别为各分数段的人数Fori=1To6score=Va1(InPUtBox(请输入第“&i&”位学生的成绩”)Ifscore60Thena=a+IEIseIfscore=
4、70Thenb=b+1E1seIfscore=800Anda2000Thenb=a*0.05EndIfMSgBOX”应收税=&b&”元EndSub第7题PrivateSubCommand1_C1ick()Dima,sAsIntegern=InPUtBOX(请输入需要计算的次数)s=0Fori=1Tons=s+i*(i+1)NextiMsgBox,S=&sEndSub第8题PrivateSubCommand1_C1ick()DimaAsIntegerDima11AsIntegera11=0a=Va1()Ifa100ThenMsgBox”输入的数应在0-100之间”E1seFori=0ToaSte
5、p2a11=a11+iNextiEndIfMSgBOX”小于此数的偶数之和为:”&a11EndSub第9题PrivateSubCommand1_C1ick()DimnAsInteger,定义个数DimscoreAsInteger,定义单个成绩Dima1!ScoreAsInteger定义成绩的累加DimmaxAsInteger,定义存放最大数的变量DimminAsInteger,定义存放最小数的变量max=0min=10n=Oa11Score=0Doscore=Va1(InPUtBOx(请输入第”&(n+1)&”位评委的成绩”)Ifscore10ThenMSgBoX”成绩应在010之间,请重输”
6、GoTo10,跳转到10EIseIfscore0ThenExitDoE1seIfmaxscoreThenmin=scoreEndIfa11Score=a11Score+scoren=n+1EndIf101oopa11Score=a11Score-max-min,去掉一个最大数和一个最小数n=n-2=a11Score*1#/n*1.0的目的是将整数转换为小数EndSub第10题PrivateSubCommand1_C1ick()DimpriceAsSing1e,票价DimnumAsInteger,订票数DimmonthAsInteger月份price=InPUtBOx(请输入票价)num=InP
7、UtBOx(请输入订票数”)month=InPUtBox(”请输入月份)Ifmonth=7Andmonth20Thenprice=price*num*(I-0.15),优惠15%EIseIfnum10Thenprice=price*num*(I-0.05),优惠5%EndIfE1seIfmonth=IAndmonth20Thenprice=price*num*(I-0.25),优惠25%EIseIfnum10Thenprice=price*num*(I-0.15),优惠15%EndIfEndIf=priceEndSub第11题PrivateSubCommand1_C1ick()Dimstr1A
8、sStringstr1=IfMid(Str1,1,3)=358Then,mid函数中第2个参数代表取子串的起始位置,第3个参数代表取子串的长度on=”一等奖”E1seIfMid(str1,1,2)=,35Thenon二二等奖”E1seIfMid(str1,1,1)=3,Thenon二三等奖”E1seon二谢谢参与”EndIfEndSub第12题Dima,b,cAsIntegerDimx1,x2AsSing1ePrivateSubCommand1_C1ick()a=Va1()b=Va1()c=Va1()Ifb*b-4*a*c0ThenPrint”此方程无实根”EIseIfb*b-4*a*c=OT
9、henx1=b/(2*a)Print”实根x1=x2=&x1E1sex1=(b+Sqr(b*b-4*a*c)/(2*a)x1=(b-Sqr(b*b-4*ac)/(2*a)Print”实根x1=&x1Print”实根x2=&x2EndIfEndSub第13题PrivateSubOption1_C1ick()EndSubPrivateSubOption2_C1ick()_IIHEndSuhPrivateSubOption3_C1ick()=GoodEndSub第14题PrivateSubCheck1_C1ick()If=CheckedAnd=UncheckedAnd=CheckedThen=He1
10、1oE1se_IHIEndIfEndSubPrivateSubCheck2_C1ick()If=CheckedAnd=UncheckedAnd=CheckedThen=He11oE1se_IHIEndIfEndSubPrivateSubCheck3_C1ick()If=CheckedAnd=UncheckedAnd=CheckedThen=He11oE1se_IHIEndIfEndSub第15题-111PrivateSubCommand1_C1ick()Jtf1.Dimstr1AsStringPrivateSubText1_GotFocus()=str1EndSubPrivateSubText
11、1_1ostFocus()str1=_IHIEndSubPrivateSubText2_GotFocus()=str1EndSubPrivateSubText2_1ostFocus()str1=一H11EndSub第16题PrivateSubCommand1_C1ick()Dima(5,5)AsIntegerDimmax,maxi,maxjAsIntegermax=0Fori=1To5Forj=1To5a(i,j)=Int(Rnd*99)+1NextjNextiFori=1To5Forj=1To5Printa(i,j);,”;NextjPrintNextiFori=1To5Forj=1To5Ifmaxsc(j)Then,按从小到大顺序排列temp=sc(i)咬换SC与sc(j冲的数据sc(i)=sc(j)sc(j)=temptempi=a(i)交换a(i)与a(j)中的数据(即名次也得交换)a(i)=a(j)a(j)=temp1EndIfNextjNex