计算机2级.docx
《计算机2级.docx》由会员分享,可在线阅读,更多相关《计算机2级.docx(40页珍藏版)》请在冰豆网上搜索。
![计算机2级.docx](https://file1.bdocx.com/fileroot1/2022-12/31/97bee9ca-4e52-45ee-ab57-e178b8fefd28/97bee9ca-4e52-45ee-ab57-e178b8fefd281.gif)
计算机2级
OptionBase1DimArr1(20)AsInteger
DimArr2(20)AsIntegerDimSumasInteger
SubReadData1()
OpenApp.Path&"\"&"datain1.txt"ForInputAs#1
Fori=1To20Input#1,Arr1(i)
NextIClose#1EndSubSubReadData2()
OpenApp.Path&"\"&"datain2.txt"ForInputAs#1Fori=1To20Input#1,Arr2(i)
NextiClose#1EndSub
SubWriteData(FilenameAsString,NumAsInteger)
OpenApp.Path&"\"&FilenameforOutputAs#1
Print#1,NumClose#1EndSub
PrivateSubC1_Click()
ReadData1
ReadData2EndSubPrivateSubC2_Click()
Dimarr3(20)AsInteger
Sum=0Fori=1To20
arr3(i)=Arr1(i)-Arr2(i)Sum=Sum+arr3(i)NextPrintSumEndSubPrivateSubC3_Click()WriteData"dataout.txt",Sum
PrivateFunctionisprime(aAsInteger)AsBoolean
DimflagAsBoolean
flag=True
b%=2
DoWhileb%<=Int(a/2)Andflag
IfInt(a/b%)=a/b%Then
flag=False
Else
b%=b%+1
EndIf
Loop
isprime=flag
EndFunction
PrivateSubC1_Click()
DimiAsInteger
i=18000Doi=i-1
LoopUntilisprime(i)Text1.Text=IEndSubPrivateSubC2_Click()Open"out5.txt"ForOutputAs#1Print#1,Text1.TextClose#1
PrivateSubC1_Click()
DimtempAsLong
DimiAsInteger,kAsInteger
temp=1
Fork=0To2
IfOp1(k).ValueThen
Fori=1ToVal(Op1(k).Caption)
temp=temp*i
Nexti
Text1.Text=temp
EndIfNextk
PrivateSubCommand1_Click()DimiAsIntegerDimsumAsLongsum=1
Ifn=10Orn=12ThenFori=nTo1Step-1sum=sum*iNext
ElseFori=nTo2Step-1
sum=sum+i
Next
EndIf
Text1.Text=sum
EndSub
1DimArr(100)AsInteDimtempAsIntegerSubReadData()OpenApp.Path&"\"&"datain1.txt"ForInputAs#1
Fori=1To100Input#1,Arr(i)NextIClose#1EndSub
SubWriteData(FilenameAsString,NumAsInteger)OpenApp.Path&"\"&FilenameForOutputAs#1Print#1,NumClose#1
PrivateSubCalc_Click()Text1.Text=""Fori=1To100Step2Text1.Text=Text1.Text&Arr(i)&Space(5)
temp=temp+Arr(i)NextIPrinttempEndSubPrivateSubRead_Click()ReadDataEndSub
PrivateSubSave_Click()WriteData"dataout.txt",tempEndSub
2PrivateSubCalc_Click()Text1.Text=""Fori=1To100IfArr(i)Mod3=0Then
Text1.Text=Text1.Text&Arr(i)&Space(5)temp=temp+Arr(i)EndIfNexti
PrinttempEndSub
PrivateSubRead_Click()ReadDataEndSub
PrivateSubSave_Click()WriteData"dataout.txt",tempEndSub
100个整数下届为1奇数元素显示在文本框中,求和并显示第二种是100个整数可以被3整除的显示并求和!
第三种100整数该数组中大于等于50的元素在文本框显示,并求和显示在窗体上
3PrivateSubCalc_Click()Text1.Text=""Fori=1To100IfArr(i)>=50Then
Text1.Text=Text1.Text&Arr(i)&Space(5)temp=temp+Arr(i)EndIfNextIPrinttempEndSubPrivateSubRead_Click()ReadDataEndSub
PrivateSubSave_Click()WriteData"dataout.txt",tempEndSub
第四种100个整数下标为偶数的元素显示在文本框中,求合并显示
PrivateSubCalc_Click()Fori=1To100IfiMod2=0ThenText1.Text=Text1.Text&Arr(i)&Space
(2)
sum=sum+Arr(i)EndIfNextiPrintsumEndSub
PrivateSubForm_Load()Text1.Text=""EndSub
PrivateSubRead_Click()ReadDataEndSub
PrivateSubSave_Click()WriteData"dataout.txt",sumEndSub
第五种100个整数数组中小于50的元素在文本框中显示,并求和显示
PrivateSubCalc_Click()Fori=1To100IfArr(i)<50ThenText1.Text=Text1.Text&Arr(i)&Space
(2)
sum=sum+Arr(i)EndIfNextIPrintsumEndSub
PrivateSubRead_Click()ReadDataEndSub
PrivateSubSave_Click()WriteData"dataout.txt",sumEndSub
3,7,11计算5000以内能被该数整除的所有数之和,放在Text1中PrivateSubC1_Click()IfCb1.Text=3Thendivide(3)ElseIfCb1.Text=7Thendivide(7)Elsedivide(11)Endif
PrivateSubdivide(xAsInteger)DimiAsIntegerDimtempAsLong
Fori=1To5000IfiModx=0Thentemp=temp+IEndIfNextIText1.Text=tempEndsub
1一个命令按钮一个文本框0-1000能被5或7整出的整数个数显示
SubSaveData()OpenApp.Path&"\"&"outtxt.txt"ForOutputAs#1Print#1,Text1.TextClose#1EndSub
FunctionFun()DimtempAsIntegerDimiAsIntegerFori=0To1000IfiMod5=0oriMod7=0Then
temp=temp+1EndIfNextIFun=tempEndFunction
PrivateSubCommand1_Click()d=Fun()Text1.Text=dSaveDataEndSub
2在0-100一个命令按钮一个文本框不能被7整除的所有整数的和在文本框显示
FunctionFun()DimiAsIntegerDimtempAsIntegerFori=0To100IfiMod7<>0Then
temp=temp+IEndIfNextIFun=tempEndFunction
3在0-1000一个命令按钮一个文本框不能被7整除的所有整数的个数显示在文本框
FunctionFun()DimiAsIntegerDimtempAsIntegerFori=0To1000IfiMod7<>0Then
temp=temp+1EndIfNextItext1.text=temp
4在0-200一个命令按钮一个文本框能被3整除的所有整数的和显示在文本框
FunctionFun()DimsumAsInteger,iAsIntegerFori=0To200IfiMod3=0Thensum=sum+I
EndIfNextIText1.Text=sumEndFunction
5在0-100一个命令按钮一个文本框所有偶数的平方和,显示在文本框
FunctionFun()DimiAsInteger,sumAsLongFori=0To100IfiMod2=0Thensum=sum+i*i
EndIfNextIText1.Text=sumEndFunction
PrivateSubCommand1_Click()
Image1.Picture=LoadPicture(App.Path&"\Misc34.ico")EndSub
PrivateSubCommand2_Click()
Image1.Picture=LoadPicture(App.Path&"\Misc37.ico")EndSub
PrivateSubCommand3_Click()
Image1.Picture=LoadPicture("")EndSub
PrivateSubDir1_Change()
File1.Path=Dir1.PathEndSub
PrivateSubDrive1_Change()
Dir1.Path=Drive1.DriveEndSub
PrivateSubFile1_Click()
Label2.Caption=File1.FileName
EndSub
OptionBase1Dima(5,8)AsSingle,athlete(5)AsString*8
PrivateSubCommand1_Click()DimchAsStringText1=""
OpenApp.Path&"\in5.dat"ForInputAs#1Fork=1To5
Input#1,chathlete(k)=chText1=Text1&ch&""
Forj=1To8Input#1,cha(k,j)=Val(ch)
Text1=Text1&ch&""Next
Text1=Text1&Chr(13)&Chr(10)NextkClose#1EndSub
PrivateFunctiongetmark(nAsInteger)AsSingle
s=a(n,1)maxnum=sminnum=sFork=2To7
s=s+a(n,k)IfmaxnumEndIfIfminnum>a(n,k)Thenminnum=a(n,k)EndIf
Nextks=(s-maxnum-minnum)/5getmark=s*3*a(n,8)EndFunction
PrivateSubCommand2_Click()'要求考生编写的程序
DimSorce(5)AsSingleDimiAsIntegerDimmaxSorceAsSingleDimmaxnumAsIntegerfori=1To5
Sorce(i)=getmark(i)NextmaxSorce=Sorce
(1)Fori=2To5IfSorce(i)>maxSorceThen
MaxSorce=Sorce(i)maxnum=IEndIfNextText2.Text=athlete(maxnum)Text3.Text=maxSorceEndSub
PrivateSubCommand3_Click()OpenApp.Path&"\out5.dat"ForOutputAs#1Print#1,Text2,Text3Close#1
EndSub
PrivateSubC1_Click()
DimkAsIntegerForm2.Show
Form2.PrintForm1.L1.Caption;Form1.Text1
Form2.PrintForm1.L2.Caption;Form1.Text2
Form2.PrintForm1.L3.Caption;Form1.Text3
Form2.PrintForm1.Frame1.Caption;":
";
Fork=0To1IfForm1.Op1(k).ValueThen
Form2.PrintForm1.Op1(k).Caption
EndIfNextkEndSub
PrivateSubForm_Load()Text2.PasswordChar="*"
PrivateSubC1_Click()
DimkAsInteger
k=0
While(kIfList2.Selected(k)=TrueThen
List1.AddItemList2.Text
List2.RemoveItemList2.ListIndex
EndIf
k=k+1
Wend
EndSub
PrivateSubC2_Click()
List2.AddItemList1.Text
List1.RemoveItemList1.ListIndexEndSub
text1中的大写转换成小写,小写转换成大写
Dima$,b$,k%,n%a$=""n%=Asc("a")-Asc("A")Fork%=1ToLen(Text1.Text)b$=Mid(Text1.Text,k%,1)Ifb$>="a"Andb$<="z"Then
b$=String(1,Asc(b$)-n%)Else
Ifb$>="A"Andb$<="Z"Thenb$=String(1,Asc(b$)+n%)
EndIfEndIfa$=a$+b$Nextk%Text1.Text=a$
PrivateSubC1_Click()Timer1.Enabled=TrueEndSub
PrivateSubC2_Click()Timer1.Enabled=FalseEndSub
PrivateSubTimer1_Timer()
P1.MoveP1.Left+20
EndSub
向Text1输入字符,单击统计按钮,在窗体上显示组合框列表项的个数
PrivateSubCommand1_Click()
Combo1.AddItemText1
EndSub
PrivateSubCommand2_Click()
PrintCombo1.ListCount
EndSub
单击加密按钮,根据选中的单选按钮后面的数字n,把明文中的每个字母改为它后面的第n个字母(z后是a,Z后是A)DimnasInteger,kAsInteger,mAsInteger
DimcAsString,aAsStringFork=0To2IfOp1(k).ValueThen
n=Val(Op1(k).Caption)EndIfNextkm=Len(Text1.Text)a=""Fork=1Tomc=Mid$(Text1.Text,k,1)c=String(1,Asc(c)+n)Ifc>"z"Orc>"Z"Andc<"a"Thenc=String(1,Asc(c)-26)EndIf
a=a+cNextkText2.Text=a
Endsub
打开文件默认为“文本文件”转换是把文本框中小写转换成大写,存盘是存在out5.dat文件中PrivateSubC1_Click()DimaAsString
CD1.Filter="所有文件|*.*|文本文件|*.txt|Word文件|*.doc|"
CD1.FilterIndex=2CD1.Action=1
OpenCD1.FileNameForInputAs#1Input#1,aClose#1Text1.Text=a
PrivateSubC2_Click()Text1.Text=UCase(Text1.Text)EndSub
PrivateSubC3_Click()CD1.FileName="out5.dat"CD1.Action=2OpenCD1.FileNameForOutputAs#1Print#1,Text1.TextClose#1
PrivateSubCommand1_Click()Text4=""
a=Val(Text1)b=Val(Text2)n=Val(Text3)Text4=Text4&a&""&bk=2DoWhileka=bb=cElsed=c\10Text4=Text4&""&da=dk=k+1
Ifk<=nThend=cMod10Text4=Text4&""&db=dEndIf
EndIfLoopEndSub
30个0~999的随机整数放入一个数组中,然后输出最大值,显示在窗体PrivateSubCommand1_Click()
DimarrN(30)AsIntegerDimMaxAsIntegerRandomize
Fori=1To30arrN(i)=Int(Rnd*1000)Nexti
Max=arrN
(1)Fori=2To30IfMaxMax=arrN(i)EndIfNextIPrintMax
20个0~999的随机整数放入数组,输出大于500的所有整数之和。
PrivateSubCommand1_Click()DimarrN(20)AsInteger
DimSumAsIntegerRandomizeFori=1To20arrN(i)=Int(Rnd*1000)
NextISum=0Fori=1To20IfarrN(i)>500ThenSum=Sum+arrN(i)EndIfNextIPrintSum
PrivateSubCommand1_Click()20个0-999的整数求平均值
DimarrN(20)AsIntegerDimAverAsSingleDimSumAsInteger,iRandomizeFori=1To20arrN(i)=Int(Rnd*1000)NextiSum=0Fori=1To20
Sum=Sum+arrN(i)NextiAver=Sum/20PrintAver
单击取数按钮,则把15个姓名读到数组a中,并显示在窗体。
Text中输入姓名或姓氏单