求VB高手帮忙编程 三个题目 谢谢了 急
输入半径,求圆的周长和面积。在文本框输入一串字符,统计其中大写字母、小写字母、其他字符出现的次数生成20个范围在10~99之间随机整数,在窗体上显示成两行。然后计算出其中...
输入半径,求圆的周长和面积。
在文本框输入一串字符,统计其中大写字母、小写字母、其他字符出现的次数
生成20个范围在10~99之间随机整数,在窗体上显示成两行。然后计算出其中峰值的个数。(对于序列中的Xn, Xn-1<Xn>Xn+1, 则Xn为峰值) 展开
在文本框输入一串字符,统计其中大写字母、小写字母、其他字符出现的次数
生成20个范围在10~99之间随机整数,在窗体上显示成两行。然后计算出其中峰值的个数。(对于序列中的Xn, Xn-1<Xn>Xn+1, 则Xn为峰值) 展开
1个回答
展开全部
窗体上添加3个按钮,1个文本框:
Option Explicit
Private Sub Command1_Click()
'输入半径,求圆的周长和面积。
Dim r As Single
Dim l As Single
Dim s As Single
r = InputBox("输入半径")
l = 2 * 3.14 * r
s = 3.14 * r * r
Print "周长="; l, "面积="; s
End Sub
Private Sub Command2_Click()
'在文本框输入一串字符,统计其中大写字母、小写字母、其他字符出现的次数
Dim LinStr As String
Dim UpS As Integer
Dim LoS As Integer
Dim OTh As Integer
Dim i As Integer
UpS = 0
LoS = 0
OTh = 0
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) >= "A" And Mid(Text1.Text, i, 1) <= "Z" Then
UpS = UpS + 1
ElseIf Mid(Text1.Text, i, 1) >= "a" And Mid(Text1.Text, i, 1) <= "z" Then
LoS = LoS + 1
Else
OTh = OTh + 1
End If
Next i
Print "大写字母: "; UpS; " 个"
Print "小写字母: "; LoS; " 个"
Print "大写字母: "; OTh; " 个"
End Sub
Private Sub Command3_Click()
'''生成20个范围在10~99之间随机整数,在窗体上显示成两行。然后计算出其中峰值的个数。
'''(对于序列中的Xn, Xn-1<Xn>Xn+1, 则Xn为峰值)
Dim d(20) As Integer
Dim i As Integer
Dim x As Integer
Dim YesNo As Boolean
Dim F As Integer
Randomize
For i = 1 To 20
x = Int((90 * Rnd) + 10) ' 生成 10 到 99 之间的随机数值。
d(i) = x
Print d(i); " ";
Next i
Print
F = d(1)
YesNo = False
For i = 2 To 20
If YesNo Then
If d(i) < d(i - 1) Then
Print d(i - 1)
YesNo = False
End If
Else
If d(i) > d(i - 1) Then
YesNo = True
End If
End If
Next i
End Sub
Option Explicit
Private Sub Command1_Click()
'输入半径,求圆的周长和面积。
Dim r As Single
Dim l As Single
Dim s As Single
r = InputBox("输入半径")
l = 2 * 3.14 * r
s = 3.14 * r * r
Print "周长="; l, "面积="; s
End Sub
Private Sub Command2_Click()
'在文本框输入一串字符,统计其中大写字母、小写字母、其他字符出现的次数
Dim LinStr As String
Dim UpS As Integer
Dim LoS As Integer
Dim OTh As Integer
Dim i As Integer
UpS = 0
LoS = 0
OTh = 0
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) >= "A" And Mid(Text1.Text, i, 1) <= "Z" Then
UpS = UpS + 1
ElseIf Mid(Text1.Text, i, 1) >= "a" And Mid(Text1.Text, i, 1) <= "z" Then
LoS = LoS + 1
Else
OTh = OTh + 1
End If
Next i
Print "大写字母: "; UpS; " 个"
Print "小写字母: "; LoS; " 个"
Print "大写字母: "; OTh; " 个"
End Sub
Private Sub Command3_Click()
'''生成20个范围在10~99之间随机整数,在窗体上显示成两行。然后计算出其中峰值的个数。
'''(对于序列中的Xn, Xn-1<Xn>Xn+1, 则Xn为峰值)
Dim d(20) As Integer
Dim i As Integer
Dim x As Integer
Dim YesNo As Boolean
Dim F As Integer
Randomize
For i = 1 To 20
x = Int((90 * Rnd) + 10) ' 生成 10 到 99 之间的随机数值。
d(i) = x
Print d(i); " ";
Next i
F = d(1)
YesNo = False
For i = 2 To 20
If YesNo Then
If d(i) < d(i - 1) Then
Print d(i - 1)
YesNo = False
End If
Else
If d(i) > d(i - 1) Then
YesNo = True
End If
End If
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询