vb程序题(4)

上传人:简****9 文档编号:109663134 上传时间:2019-10-27 格式:DOCX 页数:5 大小:70.73KB
返回 下载 相关 举报
vb程序题(4)_第1页
第1页 / 共5页
vb程序题(4)_第2页
第2页 / 共5页
vb程序题(4)_第3页
第3页 / 共5页
vb程序题(4)_第4页
第4页 / 共5页
vb程序题(4)_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《vb程序题(4)》由会员分享,可在线阅读,更多相关《vb程序题(4)(5页珍藏版)》请在金锄头文库上搜索。

1、1在窗体Form1中实现函数MarkClass。mark参数为成绩,函数对成绩的评价。成绩评价方法为:90及以上优秀,80及以上良好,70及以上中等,60及以上及格,60以下不及格。Public Function MarkClass(mark As Long) As StringEnd FunctionPublic Function markclass(mark As Long) As StringDim s$If mark = 90 Thens = 优秀 ElseIf mark = 80 Thens = 良好 ElseIf mark = 70 Thens = 中等 ElseIf mark =

2、 60 Thens = 及格 Else:s = 不及格End Ifmarkclass = sEnd Function2在窗体Form1中实现函数MySgn。当参数x0时,函数MySgn返回1;当参数x 0 Thenmysgn = 1ElseIf x = 0 Thenmysgn = 0Elsemysgn = -1End IfEnd Function3在窗体Form1中实现函数TriangleArea。a,b,c三个参数为三角形三条边,若三边能构成三角形,函数返回三角形面积;否则返回0。提示: 海伦公式为: , Public Function TriangleArea(a As Long, b A

3、s Long, c As Long) As DoubleEnd FunctionPublic Function trianglearea(a As Long, b As Long, c As Long) As DoubleDim s%, p%p = (a + b + c) / 2s = Sqr(p * (p - a) * (p - b) * (p - c)If a + b = c Or a + c = b Or b + c = a Thentrianglearea = 0Elsetrianglearea = sEnd IfEnd Function4在窗体Form1中实现函数TriangleCl

4、ass。a,b,c三个参数为三角形三条边,函数返回三角形的形状。可能的三角形形状为以下4种:等边三角形,等腰三角形,一般三角形,不构成三角形。Public Function TriangleClass(a As Long, b As Long, c As Long) As StringEnd FunctionPublic Function triangleclass(a As Long, b As Long, c As Long) As StringDim s$If a + b = c Or b + c = a Or a + c b And a c Then max = aIf b a And

5、 b c Then max = bIf c b And c a Then max = cIf a b And a c Then min = aIf b a And b c Then min = bIf c b And c y Then Max = x Else Max = y End IfEnd Function7在窗体Form1中实现子程序Swap。Swap功能为:使第一个实参变量为较大值,第二个实参变量为较小值。Public Sub Swap(x As Long, y As Long)End SubSub swap(x As Long, y As Long) Dim t As Long I

6、f x 0: b3 = y Mod 400 = 0 leap = b1 And b2 Or b3 Select Case m Case 1, 3, 5, 7, 8, 10, 12 days = 31 Case 4, 6, 9, 11 days = 30 Case 2 If leap Then days = 29 Else days = 28 End If End SelectEnd Function9在窗体Form1中实现子程序MaxMin。参数中的a,b,c为三个数,通过max和min将找到的最大值和最小值以参数的形式返回。Public Sub MaxMin(a As Long, b As

7、Long, c As Long, max as Long, min as Long)End SubSub MaxMin(a As Long, b As Long, c As Long, max As Long, min As Long) If a b And a c Then max = a If b a And b c Then max = b If c a And c b Then max = c If a b And a c Then min = a If b a And b c Then min = b If c a And c b Then min = cEnd Sub10在窗体Form1中实现函数Perfect。如果参数x为完全数,该函数返回True;否则返回False。(完全数:真因子(除自身以外的因子)之和为其本身)Public Function Perfect(x As Long) As BooleanEnd FunctionFunction perfect(x As Long) As BooleanDim i%, s%For i = 1 To x - 1If x Mod i = 0 Thens = s + iEnd IfNext iIf s = x Thenperfect = TrueElseperfect = FalseEnd IfEnd Function

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号