1、数组应用实验七 数组应用一、实验目的1掌握一维数组的用法2掌握二维数组的用法3. 掌握控件数组的用法二.、实验内容1、随机输入20个3位整数,并用冒泡法对其进行排序(可参照例7.12)程序:Private Sub Command1_Click()Dim x%, c(1 To 20) As Integer, a%, i%, t%, n%n = 0For x = 1 To 20c(x) = InputBox(请输入第 & x & 个3位数, 输入3位数) If c(x) 999 Or c(x) c(i + 1) Then t = c(i): c(i) = c(i + 1): c(i + 1) =
2、t End If Next NextFor i = 1 To 20If i Mod 7 = 0 ThenText2.Text = Text2.Text & & vbCrLf Text2.Text = Text2.Text & & c(i)Else Text2.Text = Text2.Text & & c(i) End If NextEnd Sub运行结果:2、输入两个可以相乘的矩阵,计算两个矩阵的乘法程序:运行结果:3、用控件数组实现简单计算器的编程(可以参考例7.14)程序:Dim ops1#, ops2#Dim res As BooleanDim As DoublePrivate Sub
3、 clear_Click()dataout.Caption = End SubPrivate Sub Form_Load()res = FalseEnd SubPrivate Sub number_Click(I1 As Integer) = 3.141592654If Not res Then If I1 = 10 Then dataout.Caption = dataout.Caption & . Else If I1 = 11 Then dataout.Caption = 3.141592654 Else dataout.Caption = dataout.Caption & I1 En
4、d If End IfElse If I1 = 10 Then dataout.Caption = 0# Else If I1 = 11 Then dataout.Caption = 3.141592654 Else dataout.Caption = I1 res = False End If End IfEnd IfEnd SubPrivate Sub operator_Click(I2 As Integer)ops1 = dataout.Captionop = I2dataout.Caption = End SubPrivate Sub operator1_Click(I3 As Int
5、eger)Dim op1 As Byteops1 = dataout.Captionop1 = I3Select Case op1Case 0 dataout.Caption = Int(ops1)Case 1 dataout.Caption = Sqr(ops1)Case 4 dataout.Caption = Log(ops1)Case 9 dataout.Caption = ops1 2Case 7 dataout.Caption = ops1 3Case 6 dataout.Caption = Abs(ops1)Case 2 dataout.Caption = Sin( / 180 *
6、 ops1)Case 5 dataout.Caption = Cos( / 180 * ops1)Case 8 dataout.Caption = Tan( / 180 * ops1)Case 3 dataout.Caption = Int(Rnd * 100) + 1Case 10 dataout.Caption = ops1 ops2Case 11 dataout.Caption = ops1 Mod ops2End Selectres = tureEnd SubPrivate Sub result_Click() = 3.141592654 ops2 = dataout.CaptionSelect Case opCase 0 dataout.Caption = ops1 + ops2Case 1 dataout.Caption = ops1 - ops2Case 2 dataout.Caption = ops1 * ops2Case 3 dataout.Caption = ops1 / ops2End Selectres = tureEnd Sub运行结果:三、思考题1、选择法排序和冒泡法排序的区别,其各自的关键代码是什么2、建立控件数组的方法3、可调数组和普通数组的定义有什么不同4、数组的下界默认为多少,如何改变数组的默认下界,如何获得数组的上下界
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1