Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
методичка по Визуальному програмированию.doc
Скачиваний:
57
Добавлен:
01.05.2015
Размер:
545.79 Кб
Скачать

Приложение а

 

Листинги программ к лабораторной работе 1

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

 

type

  TForm1 = class(TForm)

    Edit1: TEdit;

    Edit2: TEdit;

    Label1: TLabel;

    Label2: TLabel;

    Label3: TLabel;

    Button1: TButton;

    Label4: TLabel;

    Button2: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure edit1keypress(Sender: TObject; var Key: Char);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

 

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var r,h,v,s: real;

begin

  r:=strtofloat(edit1.Text);

  h:=strtofloat(edit2.Text);

  s:=pi*sqr(r);

  v:=s*h;

  label3.Caption:='площадь основания равна'+floattostrf(s,ffgeneral,7,2);

  label4.Caption:='объем цилиндра равен'+floattostrf(v,ffgeneral,7,2);

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

close;

end;

procedure TForm1.edit1keypress(Sender: TObject; var Key: Char);

begin

If key=#13 then  Edit2.SetFocus;

end;

end.

 

 

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

type

  TForm1 = class(TForm)

    Edit1: TEdit;

    Edit2: TEdit;

    Memo1: TMemo;

    Button1: TButton;

    Button3: TButton;

    Label1: TLabel;

    Label2: TLabel;

    procedure Button1Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

implementation

{$R *.dfm}

 

procedure TForm1.Button1Click(Sender: TObject);

var r,h,s,vkon,vcil:real;

begin

r:=strtofloat(edit1.Text);

h:=strtofloat(edit2.Text);

s:=r*r*pi;

vkon:=s*h/3;

vcil:=s*h;

memo1.Lines.Add('объем конуса равен:  '+floattostr(vkon));

memo1.Lines.Add('объем цилиндра равен:  '+floattostr(vcil));

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

close;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

edit1.Clear;

edit2.Clear;

memo1.Clear;

end;

end.

Приложение б

 

Листинги программ к лабораторной работе 2

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, Buttons;

type

  TForm1 = class(TForm)

    ListBox1: TListBox;

    Label1: TLabel;

    Label2: TLabel;

    Label3: TLabel;

    BitBtn1: TBitBtn;

    Button1: TButton;

    procedure BitBtn1Click(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure ListBox1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

close;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

 case   listBox1.ItemIndex of

0: Label3.Caption:= 'черный  ОООООО';

1: Label3.Caption:=' белый  FFFFFF' ;

2: Label3.Caption:=' красный  FFOOOO' ;

3: Label3.Caption:=' зеленый  OOFFOO' ;

4: Label3.Caption:= 'бирюзовый OOFFFF';

5: Label3.Caption:=' синий OOOOFF';

6: Label3.Caption:=' фиолетовый  FFOOFF';

7: Label3.Caption:= ' желтый  FFFFOO';

8: Label3.Caption:= 'коричневый  996633';

9 : Label3.Caption:= ' оранжевый  FF8000';

10: Label3.Caption:= ' липовый  8000FF';

11: Label3.Caption:=' серый  АОАОАО';

end;

end;

end.

 

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

type

  TForm1 = class(TForm)

    ComboBox1: TComboBox;

    ComboBox2: TComboBox;

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    procedure FormCreate(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;

      Shift: TShiftState);

    procedure Button3Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;   i, max, min, maxi,mini:integer;

  a:array[1..10] of integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

i:=0;

comboBox1.Clear;

combobox2.Clear;

combobox1.TabOrder:=0;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

combobox1.items.add(combobox1.Text);

i:=i+1;

a[i]:=strtoint(combobox1.Text);

combobox1.SetFocus;

end;

procedure TForm1.Button2Click(Sender: TObject);

var k:integer;

begin

  max:=a[1];   maxi:=1;  min:=a[1];  mini:=1;

  for k:=2 to 10 do

     begin

       if max<a[k] then

          begin

            max:=a[k];

            maxi:=i;

          end;

       if min>a[k] then

          begin

            min:=a[k];

            mini:=i;

          end;

      end;

       a[maxi]:=min;

       a[mini]:=max;

       for k:=1 to 10 do

       combobox2.Items.Add(inttostr(a[k]));

       combobox2.DroppedDown:=true;

end;

 

procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;

  Shift: TShiftState);

begin

if key=13 then button1.SetFocus;

end;

 

procedure TForm1.Button3Click(Sender: TObject);

begin

close;

end;

end.