当前位置:文档之家› 浙大远程16年秋数据库应用程序设计离线作业(兼容)

浙大远程16年秋数据库应用程序设计离线作业(兼容)

浙江大学远程教育学院《数据库应用程序设计》课程作业姓名:学号:年级:15年春学习中心:—————————————————————————————作业第一章1.5 如何保存Delphi的项目?尝试自己动手创建一个项目,并保存。

答:练习课本例1.1,创建“我的第一个Delphi小程序”运行程序:保存项目,选择全部保存,保存为dpr格式:1.7 尝试设计如图1-10所示的窗体。

(图见教材P15页图1-10)图1-10答:向窗体中添加一个标签组件label,三个radionbutton按钮和两个按钮组件button,并根据原图设置对应的的Caption值,并使得radionbutton1的checked属性变为True,如图所示:运行后:第二章2.8设计如图2-5所示的界面。

单击“按钮1”或“按钮2”时在标签上显示用户所执行的操作。

单击“开启/停用按钮”可控制“按钮1”和“按钮2”是否可用,单击“退出系统”按钮时,结束程序的运行。

答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject);beginlabel1.Caption:='您点击了按钮1!';end;procedure TForm1.Button2Click(Sender: TObject);beginlabel1.Caption:='您点击了按钮2!';end;procedure TForm1.Button3Click(Sender: TObject); beginlabel1.Caption:=' ';end;procedure TForm1.Button4Click(Sender: TObject); beginForm1.Close;end;2.9 设计如图2-6所示的界面。

当单击按钮时,可控制文本框中字体的颜色。

图2-5 图2-6 答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject); beginEdit1.Font.Color:= clred;end;procedure TForm1.Button2Click(Sender: TObject); beginEdit1.Font.Color:= clgreen;end;procedure TForm1.Button3Click(Sender: TObject); beginEdit1.Font.Color:= clblue;end;第三章3.8 下列实数中哪些是合法的,哪些是不合法的?不合法的请说明理由。

(A)0.25E+02 (B).25+2 (C)25E+2(D)34.5 (E).123 (F)-3E-4答:(A)0.25E+02 合法(B).25+2 不合法,指数记数法不能省略E,小数点前后一定要有数字。

(C)25E+2 合法(D)34.5合法(E).123 不合法,因为小数点前后一定要有数字(F)-3E-4 合法3.12 数学式子sin30。

写成Delphi表达式是下列哪个?(A)Sin30 (B)Sin(30) (C)SIN(30。

)(D)Sin(30*Pi/180)答:要把角度30度转化为弧度表示,所以应该是(D)Sin(30*Pi/180)第四章4.7 利用3个数字编辑框分别输入小时、分、秒,换算共有多少秒,然后使用标签输出。

答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject);beginlabel5.Caption:=inttostr(spinedit1.value*3600+spinedit2.value*60+spinedit3.value)+'秒'; end;4.8 在编辑框中输入一个实数,利用备注框输出该实数及其平方和平方根。

答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject);beginmemo1.Lines.Clear;memo1.Lines.Strings[0]:=edit1.Text+'的平方是'+floattostr(sqr(strtofloat(edit1.Text) ) )+chr(13) +chr(10);memo1.Lines.Strings[1]:=edit1.Text+'的平方根是'+floattostr(sqrt(strtofloat(edit1.Text) ) ); end;procedure TForm1.FormCreate(Sender: TObject);beginmemo1.Lines.Clear; edit1.Clearend;第五章5.11 任意给定3个实数,按照从大到小的顺序依次输出这3个数。

答:程序主要代码清单如下:uses Math ;procedure TForm1.Button1Click(Sender: TObject);var a,b,c,d,e,f:real;begina:=strtofloat(edit1.Text);b:=strtofloat(edit2.Text);c:=strtofloat(edit3.Text);d:=max(max(a,b),c);f:=min(min(a,b),c);if (a<d) and (a>f) then e:=aelse if (b<d) and (b>f) then e:=belse if (c<d) and (c>f) then e:=c;label3.Caption:=floattostr(d)+' '+ floattostr(e)+' '+floattostr(f); end;procedure TForm1.FormCreate(Sender: TObject);beginedit1.clear;edit2.clear;edit3.clear;label3.Caption:=' ' ; end;5.13 假设工资的增幅标准为:若基本工资大于等于1000元,增加工资20%;若小于1000元大于等于800元,则增加工资15%;若小于800元,则增加工资10%。

请根据用户在文本框中输入的基本工资,计算出增加后的工资。

答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject);vara,b:real;begina:=strtofloat(edit1.Text) ;if (a >= 1000) then b := a*1.2else if (a >= 800) then b := 1.15*aelse b := 1.1*a ;edit2.Text:=floattostr(b) ;end;procedure TForm1.FormCreate(Sender: TObject);beginedit1.clear;edit2.clear;end;第六章6.5 设s=1X2X3X…Xn,求s不大于20000时最大的n。

答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject); varx,s:integer;beginx:=1;s:=1;while s <= 20000 dobegin x:=x+1; s:=x*s; end;label2.Caption :='n='+inttostr(x-1)end;procedure TForm1.FormCreate(Sender: TObject); beginlabel2.caption:=' ';end;6.10 在标签上输出100~200之间的所有的奇数,其中3的倍数除外。

答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject);vara,i:integer ;ar : array[1..50] of integer;begini:=1;For a := 100 To 200 Dobeginif ((a mod 2 = 1) and ((a mod 3) <> 0 ) )thenbeginar[i] := a;label2.Caption := label2.Caption + inttostr(ar[i])+' ';if (i mod 10 =0 ) then label2.Caption := label2.Caption + chr(13)+chr(10);i:= i+1;end;end;end;procedure TForm1.FormCreate(Sender: TObject); beginlabel2.Caption:=' ' ;end;第七章7.4 求1~200这200个数的和,当和大于10000时结束计算。

(要求使用转向语句)答:程序主要代码清单如下:procedure TForm1.Button1Click(Sender: TObject);vari,sum,x:integer;beginsum:=0;i:=0;repeati:=i+1;sum:=sum+i;if (sum >10000) thenbegin x:=i-1;break; end;until i>=200;label3.Caption:='相加的数字是从1到'+inttostr(x)+',和为'+ inttostr(sum-x-1) ; end;procedure TForm1.FormCreate(Sender: TObject);beginlabel3.Caption:=' ';end;第八章8.8 编写函数,输出100~500之间所有能同时被3和13整除的数。

答:建立工程,设计界面如图:在代码编辑窗口的private 中定义函数ch的原型部分:private{ Private declarations }function ch(a,b:integer): string;将光标放在该函数原型的代码定义行,按下ctrl+shift+C组合键,在函数体定义中加入代码。

程序主要代码清单如下:function TForm1.ch(a, b: integer): string;var s:string;i:integer;beginfor i:=a to b doif (i mod 3 = 0) and (i mod 13 =0)then s := s+inttostr(i)+' ';result:=s;end;procedure TForm1.FormCreate(Sender: TObject);beginedit1.Clear;edit2.Clear;label4.Caption:=' ';end;procedure TForm1.Button1Click(Sender: TObject);beginlabel4.Caption:=ch(strtoint(edit2.Text) ,strtoint(edit1.Text)) ;end;第九章9.2 打开对话框组件和打开图片对话框组件有什么异同点?答:打开对话框组件和打开图片对话框组外观相似,只是打开图片对话框组件增加了一个预览区域,可以用来显示用户所选择的图象。

相关主题