第八章数组与自定义方法.docVIP

  • 78
  • 0
  • 约4.06千字
  • 约 6页
  • 2016-11-26 发布于重庆
  • 举报
第八章数组与自定义方法

第七章 数组与自定义函数、属性、方法 试验目的: 了解数组的概念,掌握数组的定义和使用方法 学习数组与数据表文件之间传递数据的若干命令 掌握主程序、子程序和过程文件的区别 掌握子程序和过程文件建立和调用的方法 掌握自定义函数的格式及其调用方法 了解自定义属性、方法概念、使用方法 掌握全局、局部、区域变量的作用和作用范围 掌握参数的地址传递、数值传递的使用 试验内容: 使用表单自定义方法编写求阶乘和求累加和。 n=thisform.text1.value s=0 for i=1 to n s=s+fact(i) endfor ?1!+2!+3!+...++alltrim(str(n))+!=+alltrim(str(s)) function fact PARAMETER NUM x=1 FOR m= 1 TO NUM x=x*m ENDFOR RETURN x END FUNCTION 使用“传址”方式传递参数,编写判断素数的自定义方法,验证哥德巴赫猜想:一个不小于6的偶数可以表示为两个素数之和。 ①在表单中增加一个判断素数的自定义方法Prime(),并编写其代码为: Lparameters m f=.T. if m3 for i=3 to SQRT(m) if m%i=0 f=.F. exit endif endfor endif return f ②编写命令按钮command的事件代码 n=thisform.text1.value if n%20 or n6 messagebox(‘必须输入大于六的偶数,请重新输入!’,64) else for x=3 to n/2 step 2 if thisform.prime(x) y=n-x if thisform.prime(y) thisform.text2.value=allt(str(x))+??allt(str(y))ct exit endif endif endfor endif thisform.text1.setfocus ③编写表单的activate事件代码This.container1.text1.setfocus ④编写文本框text1的interactivechange事件代码 Thisform.text2.value=‘’ 有一个8×6的矩阵,各元素的值由由计算机随机产生,求全部元素的平均值,并输出高于平均值的元素以及它们的行、列号。 ①编写form1的activate事件代码 public a(8,6) for n=1 to 48 a(n)=int(rand()*100) endfor this.edit1.value= for n=1 to 8 p= for m=1 to 6 p=p+str(a(n,m),3) endfor this.edit1.value=this.edit1.value+p+chr(13) endfor ②编写Form1的 unload 事件代码 release a Commandgroup1 click k=this.value DO case CASE k=1 s=0 FOR n=1 to 48 s=s+a(n) ENDFOR av=s%48 thisform.label1.caption= 平均值=+chr(13)+str(av,7,2) p= FOR n= 1 to 8 FOR m= 1 to 6 IF a(n,m)av p=p+a(+str(n,1)+,+str(m,1)+)=+str(a(n,m),2)+ ENDIF ENDFOR ENDFOR MESSAGEBOX(p,0,大于平均值的元素是) CASE k=2 thisform.activate thisform.label1.caption=平均值= ENDCASE 4.使用数组属性定义8×6的矩阵,各元素的值由由计算机随机产生,求全部元素的平均值,并输出高于平均值的元素以及它们的行、列号。 5.设有10个评委,有计算机随机产生5.00~10.00的数值代替打分,分别用10个文本框显示,去掉一个最高分、一个最低分,计算平均分。 dime a(10) for i=1 to 10 a(i)=rand()*5+5 endfor thisform.text1.value=a(1) thisform.text2.value=a(2) thisform.t

文档评论(0)

1亿VIP精品文档

相关文档