当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年全国计算机等级考试二级VFP课后练习题及答案(12)
发布时间:2010/9/28 15:44:21 来源:城市学习网 编辑:ziteng

练习题

一、写出下列程序的运行结果:
1.set  talk off
y=1
if y<>0
x=3
else
x=5
endif
if  x>4
if y<0
x=2
else
if x>0.and.y>0
x=12
else
x=30
endif
endif
else
x=5
endif
x
1、set talk off
a=100*rand( )
b=100*rand( )
c=100*rand( )
max=a
min=a
if max<b
max=b
endif
if min>b
min=b
endif
if max<c
max=c
endif
if min>c
min=c
endif
a,b

二、输入3个不同的数,将它们从大到小排列。如图,请写出“排序”按钮的单击事件代码。

三个数排序
三、
键盘输入一个数,判断它能否同时被3、5、7整除的命令文件。
四、键盘输入a,b,c的值,判断它们能否构成三角形的三条边,若能构成一个三角形,则计算三角形的面积。请用表单和建立命令文件两种方法。
五、建立一个表单,如图,开始自动显示系统时间,当在文本框中输入一个数值后,按“之前”或“之后”按钮,使可显示指定天数之前或之后的日期和星期。
 
显示几天前后的日期和星期
请写出表单的Init事件,“之前”、“之后”、“今天”和“退出”按钮的单击事件代码。 [NextPage]

练习题答案

一、写出下列程序的运行结果:
1.set  talk off
y=1
if y<>0
x=3
else
x=5
endif
if  x>4
if y<0
x=2
else
if x>0.and.y>0
x=12
else
x=30
endif
endif
else
x=5
endif
x
2、set talk off
a=100*rand( )
b=100*rand( )
c=100*rand( )
max=a
min=a
if max<b
max=b
endif
if min>b
min=b
endif
if max<c
max=c
endif
if min>c
min=c
endif
a,b
第1题:5
第二题:产生100以内的两个随机数

二、输入3个不同的数,将它们从大到小排列。如图,请写出“排序”按钮的单击事件代码。

三个数排序
*编程思想:将前一个数与后一个数比较,若前者较小,则二者交换位置
a=val(alltrim(Thisform.text1.value))
b=val(alltrim(Thisform.text2.value))
c=val(alltrim(Thisform.text3.value))
if a<b
x=a
a=b
b=x
endif
if b<c
x=b
b=c
c=x
endif
if a<b
x=a
a = b
b=x
endif
Thisform.label1.caption=str(a)
Thisform.label2.caption=str(b)
Thisform.label3.caption=str(c)

三、键盘输入一个数,判断它能否同时被3、5、7整除的命令文件。
*编程思想:一个数被3、5、7除的余数若都为零,即能同时被三个数整除
input  "请输入一个数:"  to  A
if  A%5=0  and  A%3=0  and  A%7=0
  A,"能同时被3,5,7整除"
 ELSE
  A,"不能同时被3,5,7整除"
ENDIF

四、键盘输入a,b,c的值,判断它们能否构成三角形的三条边,若能构成一个三角形,则计算三角形的面积。请用表单和建立命令文件两种方法。
* 命令文件形式
  input  "请输入第一边的边长:"  to  a
  input  "请输入第二边的边长:"  to  b
  input  "请输入第三边的边长:"  to  c
    if  (a+b)>c  and  (a-b)<c
        p=(a+b+c)/2
        S=sqrt(p*(p-a)*(p-b)*(p-c))
         "三角形的面积为:",S
        exit
      else
         "不能构成三角形,请重新输入正确的边长值"
      cancel
    endif
*command的click事件代码:
a=val(alltrim(thisform.text1.value))
b=val(alltrim(thisform.text2.value))
c=val(alltrim(thisform.text3.value))
p=(a+b+c)/2
if a+b<=c or a-b=>c
messagebox("输入的边长值不能组成三角形",0+16+0,"输入错误")
else
Thisform.label1.caption=sqrt(p*(p-a)*(p-b)*(p-c))
Endif

五、建立一个表单,如图,开始自动显示系统时间,当在文本框中输入一个数值后,按“之前”或“之后”按钮,使可显示指定天数之前或之后的日期和星期。
 
显示几天前后的日期和星期
请写出表单的Init事件,“之前”、“之后”、“今天”和“退出”按钮的单击事件代码。
Init事件代码:
ThisForm.label2.caption=alltrim(str(year(date())))+"年"+ alltrim(str(month(date())))+"月"+ alltrim(str(day(date())))+"日"
ThisForm.label3.caption= " 星期"+substr("日一二三四五六",2*dow(date())-1,2)
之前CLICK代码:
A=val(alltrim(Thisform.text1.value))
ThisForm.label2.caption=alltrim(str(year(date()-A)))+"年"+ alltrim(str(month(date()-A)))+"月"+ alltrim(str(day(date()-A)))+"日"
ThisForm.label3.caption= " 星期"+substr("日一二三四五六",2*dow(date()-A)-1,2)
Thisform.refresh
之后CLICK代码:
A=val(alltrim(Thisform.text1.value))
ThisForm.label2.caption=alltrim(str(year(date()+A)))+"年"+ alltrim(str(month(date()+A)))+"月"+ alltrim(str(day(date()+A)))+"日"
ThisForm.label3.caption= " 星期"+substr("日一二三四五六",2*dow(date()+A)-1,2)
Thisform.refresh
今天CLICK代码:
ThisForm.label2.caption=alltrim(str(year(date())))+"年"+ alltrim(str(month(date())))+"月"+ alltrim(str(day(date())))+"日"
ThisForm.label3.caption= " 星期"+substr("日一二三四五六",2*dow(date())-1,2)
Thisform.refresh
退出CLICK代码:
ThisForm.release

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved