《西科大网络教育《程序设计语言VB》指导书作业参考答案.docx》由会员分享,可在线阅读,更多相关《西科大网络教育《程序设计语言VB》指导书作业参考答案.docx(14页珍藏版)》请在优知文库上搜索。
1、西科大网络教育程序设计语言VB指导书作业参考答案第1题PrivateSubCommand1_Click()DimaAsLongDimnAsIntegern=0a=Val()DoIfa100000Thena=a*2n=n+1ElseExitDoEndIfLoopMSgBOX”共翻“&n&”倍”EndSub第2题PrivateSubCommand1_Click()Fori=1To50Forj=2To50Step2Fork=5To50Step5Ifi+j+k=50ThenPrinti&”个1分+“&j&”个2分+&k&”个5分”EndIfNextkNextjNextiEndSub第3题Private
2、SubCommand1_Click()Dimprod(4)AsSingleDimalIprodAsSingleDimmaxAsSingleDimposAsInteger,最大数位置alIprod=0max=0pos=0Fori=1To4prod(i)=InPUtBoX(输入第“&i&”个季度的产量”)alIprod=alIprod+prod(i)Ifmaxprod(i)Thenmax=prod(i)EndIfNextiFori=1To4Print&i&季度的产量占全年的百分比=&prod(i)/allprod*100&%Ifprod(i)=maxThenpos=iEndIfNextiPrint
3、”最大产量的季度=&POSEndSub第4题PrivateSubCommand1_Click()DimaAsSingleDimnAsIntegern=Oa=Val()Doa=a*0.5n=n+1Ifa0.001ThenExitDoEndIfLoopMSgBOX分半的次数=&nEndSub第5题PrivateSubCommand1_Click()DimscoreAsSingleDima,b,c,dAsIntegera,b,c,d分别为各分数段的人数Fori=1To6score=Val(InPUtBox(请输入第“&i&”位学生的成绩”)Ifscore60Thena=a+IEIseIfscore=
4、70Thenb=b+1ElseIfscore=800Anda2000Thenb=a*0.05EndIfMSgBOX”应收税=&b&”元EndSub第7题PrivateSubCommand1_Click()Dima,sAsIntegern=InPUtBOX(请输入需要计算的次数)s=0Fori=1Tons=s+i*(i+1)NextiMsgBox,S=&sEndSub第8题PrivateSubCommand1_Click()DimaAsIntegerDimallAsIntegerall=0a=Val()Ifa100ThenMsgBox”输入的数应在0-100之间”ElseFori=0ToaSte
5、p2all=all+iNextiEndIfMSgBOX”小于此数的偶数之和为:”&allEndSub第9题PrivateSubCommand1_Click()DimnAsInteger,定义个数DimscoreAsInteger,定义单个成绩Dimal!ScoreAsInteger定义成绩的累加DimmaxAsInteger,定义存放最大数的变量DimminAsInteger,定义存放最小数的变量max=0min=10n=OallScore=0Doscore=Val(InPUtBOx(请输入第”&(n+1)&”位评委的成绩”)Ifscore10ThenMSgBoX”成绩应在010之间,请重输”
6、GoTo10,跳转到10EIseIfscore0ThenExitDoElseIfmaxscoreThenmin=scoreEndIfallScore=allScore+scoren=n+1EndIf10LoopallScore=allScore-max-min,去掉一个最大数和一个最小数n=n-2=allScore*l#/n*1.0的目的是将整数转换为小数EndSub第10题PrivateSubCommand1_Click()DimpriceAsSingle,票价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%EndIfElseIfmonth=IAndmonth20Thenprice=price*num*(I-0.25),优惠25%EIseIfnum10Thenprice=price*num*(I-0.15),优惠15%EndIfEndIf=priceEndSub第11题PrivateSubCommand1_Click()DimstrlA
8、sStringstrl=IfMid(Strl,1,3)=358Then,mid函数中第2个参数代表取子串的起始位置,第3个参数代表取子串的长度on=”一等奖”ElseIfMid(strl,1,2)=,35Thenon二二等奖”ElseIfMid(str1,1,l)=3,Thenon二三等奖”Elseon二谢谢参与”EndIfEndSub第12题Dima,b,cAsIntegerDimx1,x2AsSinglePrivateSubCommand1_Click()a=Val()b=Val()c=Val()Ifb*b-4*a*c0ThenPrint”此方程无实根”EIseIfb*b-4*a*c=OT
9、henxl=b/(2*a)Print”实根xl=x2=&xlElsexl=(b+Sqr(b*b-4*a*c)/(2*a)xl=(b-Sqr(b*b-4*ac)/(2*a)Print”实根xl=&xlPrint”实根x2=&x2EndIfEndSub第13题PrivateSubOptionl_Click()EndSubPrivateSubOption2_Click()_IIHEndSuhPrivateSubOption3_Click()=GoodEndSub第14题PrivateSubCheckl_Click()If=CheckedAnd=UncheckedAnd=CheckedThen=Hel
10、loElse_IHIEndIfEndSubPrivateSubCheck2_Click()If=CheckedAnd=UncheckedAnd=CheckedThen=HelloElse_IHIEndIfEndSubPrivateSubCheck3_Click()If=CheckedAnd=UncheckedAnd=CheckedThen=HelloElse_IHIEndIfEndSub第15题-lllPrivateSubCommand1_Click()Jtfl.DimstrlAsStringPrivateSubTextl_GotFocus()=strlEndSubPrivateSubText
11、l_LostFocus()strl=_IHIEndSubPrivateSubText2_GotFocus()=strlEndSubPrivateSubText2_LostFocus()strl=一HllEndSub第16题PrivateSubCommand1_Click()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)