⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 本光盘是《Delphi 7应用教程》一书的配套光盘
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var                                 //定义三个变量
  m:Integer;
  t,s:Real;
begin
  t:=StrToFloat(Edit1.Text);       //将字符串转换成实数
  m:=Trunc(t);                     //取整函数
  Case (m div 100) of
    0: s:=t;                       //购物金额少于100元不优惠
    1,2: s:=t*(1-0.05);        //购物金额大于等于100但少于300的优惠5%
    3,4: s:=t*(1-0.1);        //购物金额大于等于300但少于500的优惠10%
    5,6,7,8,9: s:=t*(1-0.15); //购物金额大于等于500但少于1000的优惠15%
  else
    s:=t*(1-0.2);             //购物金额大于等于1000元的优惠20%
  end;
  Edit2.Text:=FloatToStr(s);  //将实型数据转换成字符串赋值给编辑框
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -