《vfp實驗題整理》word版_第1頁
《vfp實驗題整理》word版_第2頁
《vfp實驗題整理》word版_第3頁
《vfp實驗題整理》word版_第4頁
《vfp實驗題整理》word版_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、Visual FoxPro實驗題匯總順序結(jié)構(gòu)程序設(shè)計1. 用過程化編成方式編寫本題。求解一元二次方程 (JFC.PRG) a=1b=4c=4x1=(-b+SQRT(b2-4*a*c)/(2*a)x2=(-b-SQRT(b2-4*a*c)/(2*a)?方程的一個根是:,x1,space(10),另一個根是:,x22.理解大小寫轉(zhuǎn)換函數(shù)。在文本框中輸入文本串,按“轉(zhuǎn)大寫”按鈕,文本中的英文字母變?yōu)榇髮?,按“轉(zhuǎn)小寫”按鈕,文本中的英文字母變?yōu)樾懀ㄈ鐖D所示)。:Public a:Thisform.text1.value=a:Thisform.text1.value=upper(a):Thisform

2、.text1.value=lower(a):Thisform.text1.value=a3.班上集體購買課外讀物,在文本框中輸入3種書的單價、購買數(shù)量,計算并輸出所用的總金額。:a=val(thisform.text1.value)b=val(thisform.text2.value)c=val(thisform.text3.value)d=val(thisform.text4.value)e=val(thisform.text5.value)f=val(thisform.text6.value)thisform.text7.value=a*b+c*d+e*f4. 在文本框中輸入小時、分、秒,

3、化成共有多少秒,然后輸出之。a=val(thisform.text1.value)b=val(thisform.text2.value)c=val(thisform.text3.value)thisform.text4.value=a*3600+b*60+c5. 編程序輸出在指定范圍內(nèi)的3個隨機數(shù),范圍在文本框中輸入。:Thisform.label3.caption=str(int(b-a+1)*rand()+a)Thisform.label4.caption=str(int(b-a+1)*rand()+a)Thisform.label5.caption=str(int(b-a+1)*rand

4、()+a)6.編寫例題4-8求圓面積,用對話框輸出結(jié)果:r=val(thisform.text1.value)a=”圓的面積為:”+alltrim(str(3.14*r2)messagebox(a,0,”計算圓的面積”)thisform.text1.selstart=0thisform.text1.sellength=len(thisform.text1.text)順序結(jié)構(gòu)程序1. 輸入3個不同的數(shù),將它們從大到小排序。:a=val(thisform.text1.value)b=val(thisform.text2.value)c=val(thisform.text3.value)do cas

5、ecase a=max(a,b,c)thisform.text4.value=alltrim(str(a)case a=min(a,b,c)thisform.text6.value=alltrim(str(a)otherwisethisform.text5.value=alltrim(str(a)endcasedo casecase b=max(a,b,c)thisform.text4.value=alltrim(str(b)case b=min(a,b,c)thisform.text6.value=alltrim(str(b)otherwisethisform.text5.value=all

6、trim(str(b)endcasedo sasecase c=max(a,b,c)thisform.text4.value=alltrim(str(c)case c=min(a,b,c)thisform.text4.value=alltrim(str(c)otherwisethisform.text5.value=alltrim(str(c)endcase2. 創(chuàng)建一個檢查輸入口令的表單,口令設(shè)定為“SOFTWARE”,允許用戶輸入三次口令。如果三次輸入錯誤,則顯示相關(guān)信息,并禁止再次輸入口令:如果正確,則顯示“歡迎使用本系統(tǒng)!”字樣,請編寫該程序。:a=ALLTRIM(thisform.c

7、ontainer1.text1.value)if a=SOFTWARE thisform.label1.caption=歡迎使用本系統(tǒng)! thisform.container1.visible=.F. thisform.label1.visible=.T. mand1.visible=.t.else b=b+1 if b=3 messagebox(你已第+str(b,3)+次輸入錯誤,+chr(13); +不能使用該系統(tǒng),48,錯誤提示) thisform.release ELSE messagebox(你已第+str(b,3)+次輸入錯誤!,48,錯誤提示) thisform.contain

8、er1.text1.selstart=0 thisform.container1.text1.sellength=len(ltrim(thisform.container1.text1.value) RETURN 0 endifendif:Thisform.release3. 輸入一個數(shù)字(06),用中英文顯示星期幾。:do casecase a=”0” &注意帶”,字符型thisform.text2.value=”星期日”thisform.text3.value=”Sunday”case a=”1”thisform.text2.value=”星期一”thisform.text3.value=

9、”Monday”case a=”2”thisform.text2.value=”星期二”thisform.text3.value=”Tuesday”case a=”3”thisform.text2.value=”星期三”thisform.text3.value=”Wednesday”case a=”4”thisform.text2.value=”星期四”thisform.text3.value=”Thursday”case a=”5”thisform.text2.value=”星期五”thisform.text3.value=”Friday”case a=”6”thisform.text2.v

10、alue=”星期六”thisform.text3.value=”Saturday”otherwisemessagebox(“對不起,只能輸入0-6的整數(shù)”,48,”提示”)endcasethisform.text1.selstart=0 &以下可不寫thisform.text1.sellength=len(thisform.text1.text)4. 若基本工資大于等于600元,增加工資20%;若小于600元大于等于400元,則增加工資15%;若小于400元則增加工資10%。請根據(jù)用戶輸入的基本工資,計算出增加后的工資。:x=val(thisform.text1.value)do caseca

11、se x=600y=x*1.2case x=400y=x*1.15case x400y=x*1.1endcasethisform.text2.value=y5. 輸入圓的半徑r,利用選項按鈕,選擇運算:計算面積、計算周長等。r=val(thisform.text1.value)n=This.valueDo caseCase n=1Y=alltrim(str(2*3.14*r)A=圓的周長為:+yCase n=2Y=alltrim(str(3.14*r2)A=圓的面積為:+yEndcaseThisform.label2.caption=a6. 設(shè)計一個電子游動標題板,標題“使用VFP設(shè)計動畫”在

12、表單的黃色區(qū)域(容器中)自左至右地反復移動。單擊“暫?!卑粹o,標題停止移動,按鈕變成“繼續(xù)”。 單擊“繼續(xù)”按鈕,標題繼續(xù)移動,按鈕又變回“暫停”:10 &動畫移動的快慢,數(shù)字越大移動越慢:If thisform.container1.label1.left+thisform.container1.width670 &”670”大于container的寬度和label的寬度加和數(shù).即動畫要完全過去才能再開始.thisform.container1.label1.left=thisform.container1.label1.left+1elsethisform.container1.label

13、1.left=-360 &”-360”絕對值要大于container的寬度endif:If mand1.caption=”暫停”Tmand1.caption=”繼續(xù)”Thisform.container1.timer1.enabled=.f.ElseTmand1.caption=”暫停”Thisform.container1.timer1.enabled=.t.Endif7設(shè)計一個計算一元二次方程根的程序:從文本框輸入一元二次方程的三個系數(shù):A,B,C,計算并輸出方程的兩個根X1、X2。當A0時,有兩個根。當B*B-4*A*C0時,有兩個不等的實根。當B*B-4*A*C=0時,有兩個相等的實根

14、。當B*B-4*A*C0時,有兩個不等的虛根。:a=val(thisform.text1.value)b=val(thisform.text2.value)c=val(thisform.text3.value)m=b2-4*a*cdo casecase a=0 x=-c/bthisform.label4.caption=”該方程不是二次方程,只有一個根,X=”+alltrim(str(x)otherwise do case case m0 x1=(-b+sqrt(m)/(2*a) x2=(-b-sqrt(m)/(2*a) thisform.label4.caption=”該方程有兩個不相等的實

15、根,X1=”+alltrim(str()+space(5); +”X2=”+alltrim(str(x2) Case m=0 X=-b/(2*a) Thisform.label4.caption=”該方程有兩個相等的實根,X1=X2=”+alltrim(str(x) Case m0 Thisform.label4.caption=”該方程有兩個不相等的虛根.” EndcaseEndcase4循環(huán)結(jié)構(gòu)程序設(shè)計1. 在列表框中輸出1001000之間能被37整除的數(shù)。:For n=100 to 1000 If n%37=0Thisform.list1.additem(alltrim(str(n) E

16、ndifEndfor:Thisform.release2. 設(shè)計程序,求s = 1 + (1 + 2) + (1 + 2 + 3) + + (1 + 2 + 3 + + n)的值。click:n=val(thisform.text1.value)m=0s=0for i=1 to n if i=n m=m+i s=s+m endifendforthisform.label3.caption=alltrim(str(s)thisform.text1.selstart=0thisform.text1.sellength=len(thisform.text1.text):Thisform.releas

17、e3. 輸出“九九”乘法表,格式如圖所示。columncount:10Columnwidth:30,30,30,30,30,30,30,30,30,30(10個):Thisform.list1.additem(“*”)For i=1 to 9Thisform.list1.addlistitem(alltrim(str(i,3),1,i+1)Thisform.list1.addlistitem(alltrim(str(i,3),i+1,1) For n =1 to i Thisform.list1.addlistitem(alltrim(str(n,3),i+1,n+1) EndforEndfo

18、r:T4.組合框中顯示2000-2400年間所有閏年。For n=2000 to 2400 If n%4=0 and n%1000 or n%400=0 Tbo1.additem(alltrim(str(n) Tbo1.displayvalue=1 &使第一行總是顯示 EndifEndfor:thisform.release5.頁框:素數(shù)頁:在列表框中顯示2到1000的所有素數(shù)。含7頁:列表框中顯示1-200之間所有含7的數(shù)據(jù)。素數(shù)頁:For n=2 to 1000S=0 For i=2 to n-1 &除本身以外 if n%i=0 s=1 exit endif endforif s=0thi

19、s.parent.list1.additem(alltrim(str(n)endifendfor含7頁:FOR n=1 to 200If “7”$ str(n)This.parent.list1.additem(alltrim(str(n)EndifEndfor5索引,表單中使用數(shù)據(jù)表4. 設(shè)計一個操作數(shù)據(jù)表的表單,使之具有按記錄瀏覽數(shù)據(jù)表的功能(首記錄、上一個、下一個、尾記錄):Go topTmand1.enabled=.f.Tmand2.enabled=.f.Tmand3.enabled=.t.Tmand4.enabled=.t.Thisform.refresh:Skip -1If rec

20、no=1Tmand1.enabled=.f.Tmand2.enabled=.f.EndifTmand3.enabled=.t.Tmand4.enabled=.t.Thisform.refresh:Skip 1If eof()=0Go bottomTmand3.enabled=.f.Tmand4.enabled=.f.EndifT1.enabled=.t.T2.enabled=.t.Thisform.refresh:Go bottomTmand1.enabled=.t.Tmand2.enabled=.t.Tmand3.enabled=.f.Tmand4.enabled=.f.Thisform.r

21、efresh:Thisform.release6多表操作7數(shù)組1. 有一個86的矩陣,各元素的值由由計算機隨機產(chǎn)生,求全部元素的平均值,并輸出高于平均值的元素以及它們的行、列號。:column count 6Column widths:30,30,30,30,30,30Row source: aRow source type: 5-數(shù)組:Public a(8,6)For i=1 to 48a(i)=alltrim(str(rand()*100)Thisform.list1.numberofelements=48在list中設(shè)隨機數(shù)矩陣Endfor:P=”K=this.valueDo caseC

22、ase k=1 S=0 For i=1 to 48 S=s+val(a(i) EndforAv=s/48Thisform.label2.caption=”平均值為:”+alltrim(str(av) For m=1 to 8 For n=1to 6 If a(i)av P=p+”a(“+str(a(m,1)+”,”+str(a(1,n)+”)=”+alltrim (a(m,n)+”,” & a(m,n)=x中m和n必須加上str endif endfor endfor messagebox(p,0,”大于平均值的元素為:”)Case k=2Thisform.activateThisform.r

23、efreshThisform.label2.caption=”平均值為:” &Endcase2. 求方陣(66)的兩個對角線元素和。屬性:column count :6 Column widths:30,30,30,30,30,30 Rowsource: a RowsourceType:5-數(shù)組:Public a(6,6)For i=1 to 36a(i)=alltrim(str(rand()*100)thisform.list1.numberofelements=36endfor:S=0Z=0For i=1to 6S=s+val(a(i,i)Z=z+val(a(I,7-i)Thisform.

24、text1.value=alltrim(str(s)Thisform.text2.value=allrtrim(str(z)Endfor:Thisform.activateThisform.text1.value=”Thisform.text2.value=” &value”默認值Thisform.refresh3任意10個數(shù)由大到小排列:Public a(10)For i=1 to 10 Yes=1 Do while yes=1 X=int(rand()*100) Yes=0 For j=1to i-1 If x=val(a(j) Yes=1 Exit &exit直接跳到endfor End

25、if Endfor Enddo &避免隨機數(shù)重復的do循環(huán)a(i)=str(x,2) &任何數(shù)字預留兩位字符,避免alltrimp=p+a(i)+”,” &不能寫a(i)=allt(str(x,2) 這樣如果隨機產(chǎn)生了個位數(shù),那么用asort排序(字符排序)時“7”會比“66”大thisform.text1.value=left(p,len(p)-1) &把最后一個逗號去掉:Assort(a) P=”For i=10 to 1 step-1 &默認從小到大排P=p+a(i)+”,”Thisform.text2.value=left(p,len(p)-1):Thisform.activateTh

26、isform.text2.value=”Thisform.refresh自定義屬性和方法1. 求兩個數(shù)n,m的最大公約數(shù)和最小公倍數(shù)。添加自定義方法:Gys:Parameters m n zIf mnT=mm=nN=t &對調(diào)m nEndifR=m%nDo while r0N=rM=nR=m%nEnddoZ=n & z為公約數(shù),公倍數(shù)=m*n/z:X=val(thisform.text1.value)Y= val(thisform.text2.value)A=0B=0If x*y0Thisform.gys(x,y,a)B=x*y/aThisform.label3.caption=alltrim

27、(str(a)Thisform.label5.caption=alltrim(str(b)endif2. 使用“傳址”方式傳遞參數(shù),編寫判斷素數(shù)的自定義方法,驗證哥德巴赫猜想:一個不小于6的偶數(shù)可以表示為兩個素數(shù)之和(參見例8-8)。:Parameters m,fF=.t.If m3 For i=3 to sqrt(m) If m%i=0 F=.f. exit endif endforendifreturn:N=val(thisform.text1.value)A=.f.If n%2!=0 or n6Messagebox(“必須輸入大于等于6的偶數(shù)!”,48,”非法數(shù)據(jù)”)ElseFor x=

28、3 to n/2 step 2Thisform.哥德巴赫(x,a) If a=.t. Y=n-x If.thisform.哥德巴赫(y,a) If a=.t. Thisform.text2.value=alltrim(str(x) Thisform.text3.value=alltr(str(y) Exit endif endif EndifEndforEndifT3計算組合數(shù)的程序:Parameters aP=1For i=1 to a P=p*iEndforReturn p:m=val(thisform.text1.value)n= val(thisform.text2.value)if

29、mnmessagebox(“m必須大于n!”,48,”非法數(shù)據(jù)”)else x=thisform.zhs(m) y=thisform.zhs(n) z=thisform.zhs(m-n) thisform.text3.value=alltr(str(x/(y*z)endif查詢與視圖1、【例13-1】設(shè)計一個數(shù)據(jù)查詢表單,可以瀏覽全體同學、查詢數(shù)據(jù)庫中優(yōu)秀學生的成績、平均成績前5名以及成績不及格的學生名單。(數(shù)據(jù)表在data3.rar中)新建查詢,添加xs和cj,kc表,建立學號關(guān)聯(lián).根據(jù)要求分別制作4個選項相應要求的查詢1,2,3,4命名:查詢1:查詢1 &否則表單釋放時表空白3-查詢QPR

30、:Thisform.grid1.recordsource=”查詢1”Thisform.refresh:Thisform.grid1.recordsource=”查詢2” Thisform.refresh:Thisform.grid1.recordsource=”查詢3”Thisform.refresh:Thisform.grid1.recordsource=”查詢4.qpr”Thisform.refresh2、 完成以下基本操作題:1) 創(chuàng)建一個新的項目“student_p”。2) 在新建立的項目“student_p”中創(chuàng)建數(shù)據(jù)庫“student_db”。3) 在student_db數(shù)據(jù)庫中,

31、使用視圖設(shè)計器創(chuàng)建一個名稱為sview5_8的視圖以std_cj新建一本地視圖,顯示所有記錄、所有字段,其中學號、姓名字段值不能修改,平時、期中、期末及總成績是可以修改的。(略)SQL語言1設(shè)計查詢表單,在兩個文本框內(nèi)分別輸入總成績的下限和上限,可以從std_cj表中查詢出該分數(shù)段的所有學生分數(shù),并顯示在表格中。:4-SQL說明:a=val(thisform.text1.value)b=val(thisform.text2.value)c=”select * from std_cj where 總成績 between a and b order by 總成績 DESC into cursor std_cj2“ &必須帶引號thisform.grid1.recordsource=cthisform.refresh2設(shè)計一個能進行查

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論