版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.实验三第1题 四则运算题设计如下窗体,为五个命令按钮编写5段代码完成四则运算及退出程序,其中在计算除法时,如果第二个数是零,在消息框中显示信息“除数为零”。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text TextBox3.Text = a + b End Sub Private S
2、ub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text TextBox3.Text = a - b End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim a, b
3、 As Single a = TextBox1.Text b = TextBox2.Text TextBox3.Text = a * b End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim a, b As Single a = TextBox1.Text b = TextBox2.Text If b = 0 Then MessageBox.Show(除数为零) Else TextBox3.Text = a /
4、 b End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click End End SubEnd Class第2题 一元二次方程求解输入系数后,单击“求解”按钮后,根据判别式的3种不同情况,分别显示如下的不同结果。 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventA
5、rgs) Handles Button1.Click Dim a, b, c, delta As Double a = TextBox1.Text b = TextBox2.Text c = TextBox3.Text delta = b * b - 4 * a * c If delta 0 Then Label5.Visible = True Label6.Visible = True Label4.Text = 方程有两个不相等实根 Label5.Text = X1= & (-b + Math.Sqrt(delta) / 2 / a) Label6.Text = X2= & (-b - M
6、ath.Sqrt(delta) / 2 / a) ElseIf delta = 0 Then Label4.Text = 方程有两个相等实根 Label5.Visible = True Label5.Text = X1=X2= & (-b / 2 / a) Label6.Visible = False Else Label4.Text = 方程没有实根 Label5.Visible = False Label6.Visible = False End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVa
7、l e As System.EventArgs) Handles Button2.Click End End SubEnd Class第3题 文本框中前景色和背景色的不同组合目的:单选按钮的使用(1)设计窗体如下所示窗体中包含两组单选按钮、两个框架和一个命令按钮。(2)程序功能:分别单击不同的前景色和背景色按钮,在文本框中显示颜色的改变。(3)设置控件的主要属性1)窗体的文本属性为“不同前景色背景色的组合”2)初始前景色为红色、背景色为黄色3)其它属性根据图中显示来设置(4)事件代码Public Class Form1 Private Sub RadioButton1_CheckedChang
8、ed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged TextBox1.ForeColor = Color.Red End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged TextBox1.ForeColor = Color
9、.Green End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged TextBox1.ForeColor = Color.Black End Sub Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
10、RadioButton4.CheckedChanged TextBox1.BackColor = Color.White End Sub Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged TextBox1.BackColor = Color.Yellow End Sub Private Sub Form1_Load(ByVal sender As System.Object,
11、 ByVal e As System.EventArgs) Handles MyBase.Load End SubEnd Class第4题 三位整数的反序显示在窗体中添加二个文本框、二个标签和一个命令按钮,在一个文本框中输入一个三位的整数,单击命令按钮后,在另一个框中按相反顺序显示该数,例如,输入123,则在另一个文本框中显示321。 提示:本题先将每位上的数字分解出来,这要用到整除和计算余数的运算符,例如123整除100后的结果1就是百位,而123除以10的余数就是个位,至于十位,大家可以自己确定。分解后的三位数再倒序组合成新的三位整数。Public Class Form1 Private
12、Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c, d, y As Single a = TextBox1.Text b = a 100 c = (a - 100 * b) 10 d = a - 100 * b - 10 * c TextBox2.Text = d & c & b End SubEnd Class试验五第1题 累加编写程序,计算1100之间的所有偶数之和,程序窗口界面及控件自行设计。Public Class
13、 Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, sum As Long For i = 2 To 100 Step 2 sum += i Next TextBox1.Text = sum End SubEnd Class第2题 使用循环求解水仙花数的问题要求:(1)参考教材上例4-3关于水仙花数的定义。(2)程序窗口界面及控件与例4-3的结果即图4-3一样。 (3)单击“开始”按钮后,在文本框中显示求
14、出的结果。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim M, k1, k2, k3 As Integer TextBox1.Clear() For M = 100 To 999 k1 = M 100 k2 = (M 10) Mod 10 k3 = M Mod 10 If M = k1 3 + k2 3 + k3 3 Then TextBox1.Text += M.ToString(
15、) + = + k1.ToString() + 3+ + k2.ToString() + 3+ + k3.ToString() + 3 + vbCrLf End If Next End SubEnd Class第3题 统计整数的因子编写程序,向一个文本框输入一个整数,单击“开始”按钮后,找出该数的所有因子,并统计因子的个数和总和,结果在另一个文本框中显示,共有三行,其中第一行该数的所有因子,第二行显示该数的因子个数,最后一行显示该数所有因子之和,窗体界面如下:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.
16、Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c, d As Long c = 0 a = TextBox1.Text b = 1 While b = a If a Mod b = 0 Then c += 1 d += b TextBox2.Text = 该整数的因子是: & +=CStr(b) + , + vbCrLf + 因子个数为: + c.ToString() + vbCrLf + 因子之和为: + d.ToString() End If b = b + 1 End While End SubE
17、nd Class第4题 判断素数编写程序,判断某个整数是否是素数,在一个文本框中输入一个整数,单击命令按钮后,在另一个文本框中显示该数是否是素数,程序代码可以参考例4-10的代码,在此基础上改写。以下是输入不同整数后的两种不同的结果,窗体结构也参照下图。 Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, j As Integer Dim flag As Boolean = Tru
18、e i = TextBox1.Text j = 2 While j 5 Then k = a(i) a(i) = a(11 - i) a(11 - i) = k TextBox1.Text += a(11 - i).ToString + Else k = a(11 - i) a(11 - i) = a(i) a(i) = k TextBox1.Text += a(i).ToString + End If Next完整程序; Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
19、 System.EventArgs) Handles Button1.Click Dim a(10), k As Integer For i = 1 To 10 a(i) = InputBox(请输入整数) TextBox1.Text += a(i).ToString + Next k = 0 TextBox1.Text += vbCrLf + 交换后: For i = 1 To 10 If i 5 Then k = a(i) a(i) = a(11 - i) a(11 - i) = k TextBox1.Text += a(11 - i).ToString + Else k = a(11 -
20、 i) a(11 - i) = a(i) a(i) = k TextBox1.Text += a(i).ToString + End If Next TextBox1.Text = 交换前: + TextBox1.Text End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End SubEnd Class第2题 元素平均编写程序,通过使用inputbox将10个整数放入一个一维数组中,然后计算这10个整数的平均值,在文本框中
21、显示平均值和这10个数中低于平均值的数Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(10), sum, i As Integer Dim av As Single For i = 1 To 10 a(i) = InputBox(请输入整数) sum += a(i) Next av = sum / 10 For i = 1 To 10 If a(i) av Then TextBo
22、x1.Text += a(i).ToString + End If Next TextBox1.Text = 该组数的平均值为: + av.ToString + vbCrLf + 小于平均值的数有: + TextBox1.Text End SubEnd Class第3题 矩阵转置编写程序,实现矩阵转置,即矩阵的行、列互换,将一个3行4列的矩阵转换为4行3列,要示在文本框中分别显示转换前后的两个矩阵。提示: str = 交换前: + vbCrLf For i = 0 To 3 For j = 0 To 2 str += a(i, j).ToString() + b(j, i) = a(i, j)
23、 Next str += vbCrLf Next str += 交换后: + vbCrLf For i = 0 To 2 For j = 0 To 3 str += b(i, j).ToString + Next str += vbCrLf Next完整程序:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(,) As Integer = 1, 2, 3, 4, 4, 5, 6,
24、7, 6, 7, 8, 9 Dim i, j, b(3, 2) As Integer, str As String str = 交换前: + vbCrLf For i = 0 To 2 For j = 0 To 3 str += a(i, j).ToString() + b(j, i) = a(i, j) Next str += vbCrLf Next str += 交换后: + vbCrLf For i = 0 To 3 For j = 0 To 2 str += b(i, j).ToString() + Next str += vbCrLf Next TextBox1.Text = str
25、 End SubEnd Class试验七:第1题 完全数编写程序,找出22000之间的所有完全数。完全数是指某个整数的每个因子之和正好等于该数本身,例如: 因为6=1+2+3,28=1+2+4+7+14,所以这两个数都是完全数。要求:(1)程序窗口界面及控件自行设计。 (2)单击“开始”按钮后,在文本框中显示求出的结果。(3) 请用进度条提示.Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
26、Dim a, b, c, d, i As Integer For a = 2 To 2000 c = 0 For b = 1 To a - 1 d = a Mod b If d = 0 Then c += b End If Next If a = c Then TextBox1.Text += a.ToString + End If ProgressBar1.Value = a Next End SubEnd Class第2题 杨辉三角形打印以下的杨辉三角形(打印10行)。11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1提示:(1)使用一个二维数组a保存这些数据(2
27、)第0列、主对角线上元素都为1(3)其它元素为其上一行元素与上一行左侧元素之和,即: a(I,j)=a(i-1,j)+a(i-1,j-1)Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(10, 10) As Integer Dim i, j As Integer a(1, 1) = 1 For i = 2 To 10 a(i, 1) = 1 For j = 2 To i a(i,
28、 j) = a(i - 1, j - 1) + a(i - 1, j) Next Next For i = 1 To 10 For j = 1 To i TextBox1.Text += a(i, j).ToString + Next TextBox1.Text += vbCrLf Next End SubEnd Class第3题 求最小值建立一个4行3列的二维数组,找出其中最小的元素所在的行和列,并在文本框中输出该值及其行、列位置。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal
29、 e As System.EventArgs) Handles Button1.Click Dim a(,) As Integer = 45, 21, 13, 42, 15, 16, 37, 18, 29, 39, 51, 62 Dim i, j, m, b As Integer Dim min As Integer = 100 For i = 0 To 3 For j = 0 To 2 If a(i, j) min Then min = a(i, j) m = i + 1 : b = j + 1 End If Next Next TextBox1.Text += min.ToString +
30、 + m.ToString + 行 + b.ToString + 列 End SubEnd Class试验八:第1题 计算阶乘设计如下的窗体,向第一个文本框中输入一个整数,单击“计算”按钮,在另外一个文本框中显示该整数的阶乘,要求,阶乘的计算在按钮的单击事件中完成。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c As Integer a = TextBox1.Text
31、 b = 1 For c = 1 To a Step 1 b = b * c Next TextBox2.Text = b End SubEnd Class第2题 计算阶乘设计窗体与第1题相同,向第一个文本框中输入一个整数,单击“计算”按钮,在另外一个文本框中显示该整数的阶乘,要求采用SUB子过程计算阶乘,整数通过参数传递,阶乘在子过程中显示。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
32、Dim a As Integer a = TextBox1.Text jch(a) End Sub Sub jch(ByVal n As Integer) Dim i, s As Integer s = 1 For i = 1 To n s = s * i Next TextBox2.Text = s End SubEnd Class第3题 计算阶乘设计窗体与第1题相同,向第一个文本框中输入一个整数,单击“计算”按钮,在另外一个文本框中显示该整数的阶乘,要求采用FUCTION 函数过程,整数通过参数传递,阶乘由该过程返回。Public Class Form1 Private Sub Butto
33、n1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As Integer a = TextBox1.Text TextBox2.Text = jch(a) End Sub Function jch(ByVal n As Integer) Dim i, s As Integer s = 1 For i = 1 To n s = s * i Next Return s End FunctionEnd Class第4题 找出一维数组元素中的最大值和最小值设计窗
34、体如下图,单击“开始”按钮后,从键盘输入10个整数,输入到一维数组中,输入时采用inputbox函数,见图(2),然后找出这10个数中的最大值和最小值,并在文本框中输出,见图, Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(9), b, c, i As Integer a(0) = InputBox(输入第一个数) a(1) = InputBox(输入第二个数) a(2) =
35、InputBox(输入第三个数) a(3) = InputBox(输入第四个数) a(4) = InputBox(输入第五个数) a(5) = InputBox(输入第六个数) a(6) = InputBox(输入第七个数) a(7) = InputBox(输入第八个数) a(8) = InputBox(输入第九个数) a(9) = InputBox(输入第十个数) b = a(0) : c = a(0) For i = 0 To 9 If a(i) c Then c = a(i) End If TextBox1.Text += a(i).ToString + Next TextBox1.Te
36、xt = TextBox1.Text + vbCrLf + 最大数为: + c.ToString + vbCrLf + 最小数为: + b.ToString End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End SubEnd Class试验九:第1题 计算数列之和求a+aa+aaa+aaaa+. .+aa.a(n个),其中a为19之间的整数。 例如:当a = 1, n = 3时,求1+11+111之和;
37、当a = 5, n = 7时,求5555555555555555555555之和。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, n, s, i, m, b As Integer a = TextBox1.Text n = TextBox2.Text b = n For i = 1 To n m = a * (10 (i - 1) * b b = b - 1 s = s + m
38、 Next TextBox3.Text = s End SubEnd Class第2题 计算长方形的面积和周长设计如下的窗体,向前两个文本框中分别输入长和宽,单击“计算”,在另外一个文本框中显示长方形的面积,要求采用FUNCTION 函数过程计算面积,长和宽通过参数传递。Function area(ByRef a As Integer, ByRef b As Integer) As Long Dim m As Long m = a * b Return m End Function Function ccc(ByRef a As Integer, ByRef b As Integer) As
39、Integer Dim n As Integer n = 2 * (a + b) Return n End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c As Integer Dim s As Long a = TextBox1.Text b = TextBox2.Text s = area(a, b) c = ccc(a, b) TextBox3.Text = s TextBox4.
40、Text = c End SubEnd Class第3题 综合题,统计各个分数段的人数设计窗体如下:编程要求:(1)单击“开始”按钮后,显示如下的消息框,向框中输入总的人数:如果输入的人数小于1,则显示下列的消息框,然后重新输入人数(2)输入人数后,接下来分别输入这些学生的分数,如果输入的分数不在0100之间,则显示下面的消息框,然后重新输入(3)输入分数时同时统计每个分数段的人数,每个分数段按下列的规定:90100:优8089:良7079:中6069:及格60分以下:不及格(4)最后按下图显示统计后的结果:(图中是输入10个分数后的结果)Public Class Form1 Private
41、Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim str As String Dim a As Integer str = 请输入学生人数 a = InputBox(str) If a 1 Then MessageBox.Show(请重新输入) End If Dim s(a), i As Integer For i = 1 To a str = 请输入分数 s(i) = InputBox(str) If s(i) 100 Then Mes
42、sageBox.Show(分数不对,请重新输入) End If Next Dim you, liang, zhong, ji, bu As Integer For i = 1 To a If s(i) = 90 Then you += 1 ElseIf s(i) = 80 Then liang += 1 ElseIf s(i) = 70 Then zhong += 1 ElseIf s(i) = 60 Then ji += 1 Else : bu += 1 End If Next str = For i = 1 To a str += s(i).ToString + Next TextBox1.Text = 分数: + vbCrLf + str + vbCrLf + 总人数 + = + a.ToString + vbCrLf + 各等级分数的人数: + vbCrLf + 优秀 + = + y
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 教育创新策略SWOT分析与应用探索
- 聊天室java课程设计
- 2024-2030年中国无线网桥行业发展现状及投资运作模式分析报告
- 2024-2030年中国方钻杆滚子补心行业供需状况发展战略规划分析报告
- 2024-2030年中国新媒体行业运营模式及未来发展战略预测报告
- 2024-2030年中国数字地图生态系统行业发展前景与投资盈利预测报告
- 2024至2030年菠萝格地板项目投资价值分析报告
- 2024-2030年中国报废汽车回收拆解行业发展动态及投资策略分析报告版
- 2024-2030年中国建筑用石行业供需状况发展战略规划分析报告
- 2024-2030年中国工程监理行业营销策略分析及投资规划研究报告
- 山东省潍坊市2025届高三上学期开学调研检测语文试题 含解析
- 《音乐鉴赏(第二版)》大学生音乐鉴赏全套教学课件
- 期末卷(试题)-2024-2025学年二年级上册数学苏教版
- 光谱内镜技术用于喉癌预后预测
- 《成人有创机械通气气道内吸引技术操作》标准解读
- 国家开放大学(广西)《云计算及应用》作业1-5参考答案
- 2020海湾GST-HX-240B火灾声光警报器安装使用说明书
- GB/T 44068-2024LTE移动通信终端支持北斗定位的技术要求
- 2024年秋新北师大版七年级上册数学教学课件 4.2.1 角
- PFMEA课件培训学习
- 《建筑施工测量标准》JGJT408-2017
评论
0/150
提交评论