232
LATIHAN 1 Objek Properti Nilai Properti Form1 Caption Latihan 1 Label1 Caption DATA MAHASISWA Font Name: Tahoma, Size: 15, Style: fsBold (True) Label2 Caption NAMA Font Name: Tahoma, Size: 12 Label3 Caption ALAMAT Font Name: Tahoma, Size: 12 Edit1 Text (Kosongkan) Edit2 Text (Kosongkan) Button1 Caption Proses Button2 Caption Hapus Button3 Caption Keluar unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type 1

Pemrograman Delphi

  • Upload
    unnes

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

LATIHAN 1

Objek Properti Nilai PropertiForm1 Caption Latihan 1Label1 Caption DATA MAHASISWA

Font Name: Tahoma, Size: 15,Style: fsBold (True)

Label2 Caption NAMAFont Name: Tahoma, Size: 12

Label3 Caption ALAMATFont Name: Tahoma, Size: 12

Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)Button1 Caption ProsesButton2 Caption HapusButton3 Caption Keluar

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type

1

TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit1: TEdit; Edit2: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Label4: TLabel; Label5: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);begin

label4.Caption:=edit1.Text;label5.Caption:=edit2.Text;

end;procedure TForm1.Button2Click(Sender:TObject);begin

2

label4.Caption:='';edit1.Text:='';label5.Caption:='';edit2.Text:='';

end;procedure TForm1.Button3Click(Sender:TObject);begin

application.Terminate;end;end.

3

LATIHAN 2

Objek Properti Nilai PropertiForm1 Caption Latihan 2Label1 Caption DATA MAHASISWA

Font Name: Tahoma, Size: 15,Style: fsBold (True)

Label2 Caption NAMAFont Name: Tahoma, Size: 12

Label3 Caption ALAMATFont Name: Tahoma, Size: 12

Label4 Caption (Kosongkan)Label5 Caption (Kosongkan)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)Button1 Caption ProsesButton2 Caption VerdanaButton3 Caption LucidaButton4 Caption Ukuran 20Button5 Caption MerahButton6 Caption BiruButton7 Caption NormalButton8 Caption Keluar

4

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Label1: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Label2: TLabel; Label3: TLabel; Edit1: TEdit; Edit2: TEdit; Label4: TLabel; Label5: TLabel; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton;

5

procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button5Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);begin

Label4.Caption:=edit1.Text;Label5.Caption:=edit2.Text;

end;procedure TForm1.Button2Click(Sender:TObject);begin

Application.Terminate;end;procedure TForm1.Button3Click(Sender:TObject);begin

label4.Font.Name:='verdana';label5.Font.Name:='verdana';

6

end;procedure TForm1.Button4Click(Sender:TObject);begin

label4.Font.size:=20;label5.Font.Size:=20;

end;procedure TForm1.Button8Click(Sender:TObject);begin

label4.Font.Name:='Ms sans serif';label5.Font.Name:='Ms Sans Serif';label4.Font.size:=8;label5.Font.Size:=8;label4.Font.Color:=cldefault;label5.Font.color:=cldefault;

end;procedure TForm1.Button7Click(Sender:TObject);begin

label4.Font.Color:=clblue;label5.Font.color:=clblue;

end;procedure TForm1.Button6Click(Sender:TObject);begin

label4.Font.Color:=clred;label5.Font.color:=clred;

end;procedure TForm1.Button5Click(Sender:TObject);begin

label4.Font.Name:='Lucida handwriting';7

label5.Font.Name:='Lucida handwriting';end;end.

8

LATIHAN 3

Objek Properti Nilai PropertiForm1 Caption Latihan 3Label1 Caption Tombol Belum Ditekan

Font Name: Tahoma, Size: 14,Style: fsBold (True)

Button1 Caption Belum ditekanButton2 Caption Belum direset

Enabled FalseButton3 Caption Keluar

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label1: TLabel; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject);

9

procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);begin

label1.Caption:='Tombol Sudah di Tekan';button2.Caption:='Tombol Belum di Reset';button1.Caption:='Tombol Sudah di Tekan';button1.Enabled:=false;button2.enabled:=true;

end;procedure TForm1.Button2Click(Sender:TObject);begin

button1.enabled:=true;button2.enabled:=false;button1.Caption:='Tombol Belum di Tekan';button2.Caption:='Tombol Sudah di Reset';Label1.Caption:='Tombol Sudah di Reset';

end;procedure TForm1.Button3Click(Sender:TObject);begin

Application.Terminate;end;

10

end.

11

LATIHAN 4

Objek Properti

Nilai Properti

Form1 Caption Latihan 4Label1 Caption DATA MAHASISWA

Font Name: Tahoma, Size: 14,Style: fsBold (True)

Label2 Caption N I MLabel3 Caption NAMALabel4 Caption JURUSANLabel5 Caption PRODILabel6 Caption (Kosongkan)

Font Name: Tahoma, Size: 12,Style: fsBold (True)

Label7 Caption (Kosongkan)Font Name: Tahoma, Size: 12,

Style: fsBold (True)Label8 Caption (Kosongkan)

Font Name: Tahoma, Size: 12,Style: fsBold (True)

Label9 Caption (Kosongkan)Font Name: Tahoma, Size: 12,

Style: fsBold (True)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)ComboBox1

Text (Kosongkan)

Items Matematika, Fisika, Kimia,Biologi

ListBox1 Items Matematika, Pend. Matematika, Fisika, pend. Fisika, Kimia, Pend.

12

Kimia, Biologi, Pend. Biologi

Button1 Caption HapusButton2 Caption Keluar

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Edit1: TEdit; Edit2: TEdit; ComboBox1: TComboBox; ListBox1: TListBox; Label6: TLabel;

13

Label7: TLabel; Label8: TLabel; Label9: TLabel; Button1: TButton; Button2: TButton; procedure Edit1Change(Sender: TObject); procedure Edit2Change(Sender: TObject); procedure ComboBox1Change(Sender:TObject); procedure ListBox1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1Change(Sender:TObject);begin

label6.Caption:=edit1.Text;end;procedure TForm1.Edit2Change(Sender:TObject);begin

label7.Caption:=edit2.Text;end;procedure TForm1.ComboBox1Change(Sender:TObject);

14

beginlabel8.Caption:=combobox1.Text;

end;procedure TForm1.ListBox1Click(Sender:TObject);begin

label9.Caption:=listbox1.Items[listbox1.itemindex];end;procedure TForm1.Button2Click(Sender:TObject);begin

Application.Terminate;end;procedure TForm1.Button1Click(Sender:TObject);begin

Edit1.text:='';Edit2.text:='';Label6.caption:='';Label7.caption:='';Label8.caption:='';Label9.caption:='';

end;end.

15

LATIHAN 5

Objek Properti

Nilai Properti

Form1 Caption

Latihan 5

GroupBox1 Caption

JURUSAN

Sisipi CheckBox1-4GroupBox2 Captio

nPROGRAM STUDI

Sisipi CheckBox5-12CheckBox1 Captio

nKimia

CheckBox2 Caption

Biologi

CheckBox3 Caption

Matematika

CheckBox4 Caption

Fisika

CheckBox5 Caption

Kimia

CheckBox6 Caption

Biologi

CheckBox7 Caption

Matematika

CheckBox8 Caption

Fisika

CheckBox9 Caption

Pend. Kimia

CheckBox10

Caption

Pend. Biologi

CheckBox1 Captio Pend. Matematika16

1 nCheckBox12

Caption

Pend. Fisika

Memo1 Lines (Kosongkan)Button1 Captio

nProses

Button2 Caption

Hapus

Button3 Caption

Keluar

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Button1: TButton; Button2: TButton; GroupBox1: TGroupBox; GroupBox2: TGroupBox;

17

ck1: TCheckBox; ck2: TCheckBox; ck3: TCheckBox; ck4: TCheckBox; ck5: TCheckBox; ck6: TCheckBox; ck7: TCheckBox; ck8: TCheckBox; ck9: TCheckBox; ck10: TCheckBox; ck11: TCheckBox; ck12: TCheckBox; memo1: TMemo; Button3: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender:TObject);begin

Application.Terminate;end;procedure TForm1.Button1Click(Sender:TObject);

18

beginif ck1.Checked or ck2.Checked or ck3.Checked or ck4.Checked then memo1.Lines.add(groupbox1.Caption);if ck1.Checked then

memo1.Lines.add(ck1.Caption);if ck2.Checked then

memo1.Lines.add(ck2.Caption);if ck3.Checked then

memo1.Lines.add(ck3.Caption);if ck4.Checked then

memo1.Lines.add(ck4.Caption);memo1.lines.add('');if ck5.Checked or ck6.Checked or ck7.Checked or ck8.Checked or ck9.Checked or ck10.Checked or ck11.Checked or ck12.Checked then memo1.Lines.add(groupbox2.Caption);if ck5.Checked then

memo1.Lines.add(ck5.Caption);if ck6.Checked then

memo1.Lines.add(ck6.Caption);if ck7.Checked then

memo1.Lines.add(ck7.Caption);if ck8.Checked then

memo1.Lines.add(ck8.Caption);if ck9.Checked then

memo1.Lines.add(ck9.Caption);if ck10.Checked then

memo1.Lines.add(ck10.Caption);if ck11.Checked then

memo1.Lines.add(ck11.Caption);

19

if ck12.Checked thenmemo1.Lines.add(ck12.Caption);

end;procedure TForm1.Button3Click(Sender:TObject);begin

ck1.Checked:=false;ck2.Checked:=false;ck3.Checked:=false;ck4.Checked:=false;ck5.Checked:=false;ck6.Checked:=false;ck7.Checked:=false;ck8.Checked:=false;ck9.Checked:=false;ck10.Checked:=false;ck11.Checked:=false;ck12.Checked:=false;memo1.lines.Clear;

end;end.

20

LATIHAN 6

Objek Properti Nilai PropertiForm1 Caption Latihan 6Label1 Caption TAMPILAN GAMBARLabel2 Caption (Kosongkan)Image1 Proportio

nalTrue

Button1 Caption Gb 1Button2 Caption Gb 2Button3 Caption Gb 3Button4 Caption Keluar

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, jpeg, ExtCtrls;

type TForm1 = class(TForm) Button2: TButton; Image1: TImage; Label1: TLabel;

21

Button4: TButton; Label2: TLabel; Button1: TButton; Button3: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender:TObject);begin

image1.picture.LoadFromFile('c:/b.jpg');button1.Enabled:=true;button2.Enabled:=false;button3.Enabled:=true;Label2.Caption:='Gambar 2';

end;procedure TForm1.Button1Click(Sender:TObject);begin

image1.picture.LoadFromFile('a.jpg');button1.Enabled:=false;button2.Enabled:=true;button3.Enabled:=true;

22

Label2.Caption:='Pak Dekan dan Pak Sigit';Label1.Caption:=’TAMPILAN GAMBAR';

end;procedure TForm1.Button3Click(Sender:TObject);begin

image1.picture.LoadFromFile('c:/c.jpg');button1.Enabled:=true;button2.Enabled:=true;button3.Enabled:=false;Label2.Caption:='Gambar 3';

end;procedure TForm1.Button4Click(Sender:TObject);begin

Application.Terminate;end;end.

23

LATIHAN 7

Objek Properti Nilai PropertiForm1 Caption Latihan 7RadioGroup1

Caption HITUNG

Items Perkalian, Penjumlahan, Pengurangan, Pembagian

ItemIndex

0

Columns 2Label1 Caption X

Font Name: Tahoma, Size: 12,Style: fsBold (True)

Label2 Caption =Font Name: Tahoma, Size: 12,

Style: fsBold (True)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)Edit3 Text (Kosongkan)Button1 Caption UlangiButton2 Caption Keluar

unit Unit1;interface

24

usesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, ExtCtrls;

type TForm1 = class(TForm) rg1: TRadioGroup; Edit1: TEdit; Label1: TLabel; Edit2: TEdit; Button1: TButton; Edit3: TEdit; Button3: TButton; Button2: TButton; procedure rg1Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; a,b,c:real;implementation{$R *.dfm}procedure TForm1.rg1Click(Sender: TObject);begin

if rg1.ItemIndex=0 thenbegin

Label1.Caption:='X';25

Edit1.Text:='';Edit2.Text:='';Edit3.Text:='';

end else if rg1.ItemIndex=1 thenbegin

Label1.Caption:='+';Edit1.Text:='';Edit2.Text:='';Edit3.Text:='';

end else if rg1.ItemIndex=2 thenbegin

Label1.Caption:='-';Edit1.Text:='';Edit2.Text:='';Edit3.Text:='';

end else if rg1.ItemIndex=3 thenbegin

Label1.Caption:='/';Edit1.Text:='';Edit2.Text:='';Edit3.Text:='';

end;end;procedure TForm1.Button1Click(Sender:TObject);begin

if rg1.ItemIndex=0 thenbegin

a:=strtofloat(edit1.Text);b:=strtofloat(edit2.Text);c:=b*a;edit3.Text:=floattostr(c);

end else if rg1.ItemIndex=1 then26

begina:=strtofloat(edit1.Text);b:=strtofloat(edit2.Text);c:=b+a;edit3.Text:=floattostr(c);

end else if rg1.ItemIndex=2 thenbegin

a:=strtofloat(edit1.Text);b:=strtofloat(edit2.Text);c:=a-b;edit3.Text:=floattostr(c);

end else if rg1.ItemIndex=3 thenbegin

a:=strtofloat(edit1.Text);b:=strtofloat(edit2.Text);

if b=0 thenbegin messagedlg ('Goblok!!? 0 Tidak Bisa Untuk Membagi',mtwarning,[mbOk],0);edit1.Text:='';edit2.Text:='';edit3.Text:='';end elsec:=a/b;edit3.Text:=floattostr(c);

end;end;procedure TForm1.Button3Click(Sender:TObject);begin

Application.Terminate;end;

27

procedure TForm1.Button2Click(Sender:TObject);begin

edit1.Text:='';edit2.Text:='';edit3.Text:='';

end;end.

28

LATIHAN 8

Objek Properti Nilai PropertiForm1 Caption Latihan 8Button1 Caption TextButton2 Caption GambarButton3 Caption KeluarPanel1 Caption Agung Tri Prasetya

Font Name: Tahoma, Size: 12,Style: fsUnderline (True)

StatusBar1 Autohint :True; Parentshowhint:true;Simplepanel:true;

unit Unit12;29

interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,ExtCtrls,jpeg, StdCtrls, ComCtrls;

type TForm1 = class(TForm) StatusBar1: TStatusBar; Button1: TButton; Button2: TButton; Button3: TButton; Panel1: TPanel; RichEdit1: TRichEdit; Image1: TImage; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Panel1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationuses Unit1, Unit3;{$R *.dfm}procedure TForm1.Button2Click(Sender:TObject);begin

richedit1.Visible:=false;image1.Visible:=true;

30

image2.Visible:=false;image1.Picture.loadfromfile('a.jpg');

end;procedure TForm1.Button1Click(Sender:TObject);begin

richedit1.Visible:=true;image1.Visible:=false;image2.Visible:=false;richedit1.lines.loadfromfile('tulisan.rtf'

);end;procedure TForm1.Button3Click(Sender:TObject);begin

if messagedlg ('Anda yakin Akan Keluar ?',mtConfirmation,mbOkCancel,0)=mrOk thenApplication.Terminate;

end;procedure TForm1.Panel1Click(Sender:TObject);begin

Aboutbox.ShowModal;end;end.

unit Unit3;interfaceuses Windows, SysUtils, Classes, Graphics, Forms,Controls, StdCtrls, Buttons, ExtCtrls;

31

type TAboutBox = class(TForm) Panel1: TPanel; ProgramIcon: TImage; ProductName: TLabel; Version: TLabel; Copyright: TLabel; Comments: TLabel; OKButton: TButton; Label1: TLabel; private { Private declarations } public { Public declarations } end;var AboutBox: TAboutBox;implementation{$R *.dfm}end.

32

LATIHAN 9

Objek Properti Nilai PropertiForm1 Caption Latihan 9Label1 Caption PROGRAM HITUNG TEKANAN

Font Name: Tahoma, Size: 16,Style: fsBold (True)

Label2 Caption Volume (L)Label3 Caption Jumlah MolLabel4 Caption Suhu (K)Label5 Caption TekananLabel6 Caption (Kosongkan)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)Edit3 Text (Kosongkan)Button1 Caption ProsesButton2 Caption UlangiButton3 Caption Keluar

unit Unit1;interfaceuses

33

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

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; label5: TLabel; edit1: TEdit; edit2: TEdit; edit3: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Label6: TLabel; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; n,p,t,v: real; const R=0.081;implementation{$R *.dfm}

34

procedure TForm1.Button3Click(Sender:TObject);begin

application.terminate;end;procedure TForm1.Button1Click(Sender:TObject);begin

v:=strtofloat(edit1.text);t:=strtofloat(edit2.text);n:=strtofloat(edit3.text);p:=(n*R*T)/v;label6.Caption:=floattostr(p);

end;procedure TForm1.Button2Click(Sender:TObject);begin

edit1.text:='';edit2.text:='';edit3.text:='';label6.Caption:='';edit1.setfocus;

end;end.

35

LATIHAN 10

Objek Properti

Nilai Properti

Form1 Caption Latihan 10Label1 Caption Bilangan yang akan dihitung

akarnyaLabel2 Caption (Kosongkan)Edit1 Text (Kosongkan)Button1

Caption Hitung

Button2

Caption Keluar

unit Ulat11;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit;

36

Label2: TLabel; Button1: TButton; Button2: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;

x,y:real;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender:TObject);begin

application.Terminate;end;procedure TForm1.Button1Click(Sender:TObject);begin y:=strtofloat(edit1.Text); x:=sqrt(y);

label2.Caption:='Akar dari ' + edit1.Text+ ' adalah ' + floattostr(x);

edit1.SetFocus;end;end.

37

LATIHAN 11

Objek Properti Nilai PropertiForm1 Caption Latihan 11Label1 Caption Bilangan PokokLabel2 Caption PangkatLabel3 Caption (Kosongkan)Label4 Caption (Kosongkan)Label5 Caption (Kosongkan)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)Button1 Caption HitungButton2 Caption UlangiButton3 Caption Keluar

unit Ulat12;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type38

TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; a,b,c:real;implementation{$R *.dfm}procedure TForm1.Button3Click(Sender:TObject);begin

application.Terminate;end;procedure TForm1.Button1Click(Sender:TObject);begin

b:=strtofloat(edit1.Text);39

c:=strtofloat(edit2.Text);a:=exp(c*ln(b));label3.Caption:=edit1.Text;label4.Caption:=edit2.Text;label5.Caption:=' = '+floattostr(a);

end;procedure TForm1.Button2Click(Sender:TObject);begin

edit1.Text:='';edit2.Text:='';label3.Caption:='';label4.Caption:='';label5.Caption:='';edit1.SetFocus;

end;end.

40

LATIHAN 12

Objek Properti

Nilai Properti

Form1 Caption Latihan 12Label1 Caption HITUNG ENERGI LINTASAN

ELEKTRONFont Name: Tahoma, Size: 14,

Style: fsBold (True)Label2 Caption Berapa LintasannyaLabel3 Caption Berapa MassanyaLabel4 Caption Berapa LintasannyaLabel5 Caption HASILMemo1 Lines (Kosongkan)

ScrollBars

ssVertical

Button1

Caption Hitung

Button2

Caption Ulangi

Button3

Caption Keluar

41

unit Ulat13;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject);

42

procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; n,i:byte; m,a:real; e:double;const h=6.62e-34; ev=1.6e+19;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);begin n:=strtoint(edit1.Text); m:=strtofloat(edit2.Text); a:=strtofloat(edit3.Text); for i:=1 to n do begin e:=(sqr(h)*sqr(i))/(8*m*sqr(a)); e:=e*ev;

memo1.Lines.Add('Lintasan = ' + inttostr(i) + ' maka E = '+floattostr(e)+ ' eV');

memo1.Lines.Add(''); end;end;

43

procedure TForm1.Button2Click(Sender:TObject);begin edit1.Text:=''; edit2.Text:=''; edit3.Text:=''; memo1.Lines.Clear; edit1.setfocus;end;

procedure TForm1.Button3Click(Sender:TObject);begin application.Terminate;end;end.

44

LATIHAN 13

Objek Properti Nilai PropertiForm1 Caption Latihan 13Label1 Caption SOAL

Font Name: Tahoma, Size: 14,Style: fsBold (True)

Label2 Caption Larutan A liter yang mengandung B mol NaCl dicampur dengan

Label3 Caption C liter larutan yang mengandung D mol Perak Nitrat

Label4 Caption KSP Perak Nitrat = 18 x 10Label5 Caption -18Label6 Caption Apakah Akan Terjadi

Endapan ?Label7 Caption DiketahuiLabel8 Caption A =Label9 Caption B =Label10 Caption C =Label11 Caption D =Label12 Caption Jawab:Label13 Caption (Kosongkan)Label14 Caption (Kosongkan)Label15 Caption (Kosongkan)Label16 Caption (Kosongkan)Label17 Caption (Kosongkan)Label18 Caption (Kosongkan)Label19 Caption (Kosongkan)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)

45

Edit3 Text (Kosongkan)Edit4 Text (Kosongkan)Button1 Caption HitungButton2 Caption UlangiButton3 Caption Keluar

unit Ulat14;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel;

46

Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; Label14: TLabel; Label15: TLabel; Label16: TLabel; Label17: TLabel; Label18: TLabel; Label19: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;Var Form1: TForm1; a,b,c,d,e,f,g,h:real;Const ksp=1.8e-10;implementation{$R *.dfm}

47

procedure TForm1.Button1Click(Sender:TObject);begin

a:=strtofloat(edit1.Text);b:=strtofloat(edit2.Text);c:=strtofloat(edit3.Text);d:=strtofloat(edit4.Text);e:=a+c;f:=b/e;g:=d/e;h:=f*g;label13.Caption:=floattostr(a) + ‘ liter larutan mengandung ‘ + floattostr(b) + ‘ mol Cl-‘;label14.Caption:=floattostr(c) + ‘ liter larutan mengandung ‘ + floattostr(d) + ‘ mol Ag+’;label15.Caption:=’Volume campuran = ‘ + floattostr(e) + ‘ liter’;label16.Caption:=’[Cl-] = ‘ + floattostr(b) + ‘/’ + floattostr(e) + ‘ mol/liter = ‘ + floattostr(f) + ‘ mol/liter’;label17.Caption:=’[Ag+] = ‘ + floattostr(d) + ‘/’ + floattostr(e) + ‘ mol/liter = ‘ + floattostr(g) + ‘ mol/liter’;label18.Caption:=’[Ag+][Cl-] = ‘ + floattostr(f) + ‘ x ‘ + floattostr(g) + ‘ = ‘ + floattostr(h);if h < ksp thenbegin

48

label19.Caption:=’Karena [Ag+][Cl-] < Ksp maka AgCl tidak mengendap’;

end elselabel19.Caption:=’Karena [Ag+][Cl-] > Ksp maka AgCl mengendap’;

end;procedure TForm1.Button3Click(Sender:TObject);begin

application.Terminate;end;procedure TForm1.Button2Click(Sender:TObject);begin

edit1.Text:=’’;edit2.Text:=’’;edit3.Text:=’’;edit4.Text:=’’;label13.Caption:=’’;label14.Caption:=’’;label15.Caption:=’’;label16.Caption:=’’;label17.Caption:=’’;label18.Caption:=’’;label19.Caption:=’’;edit1.setfocus;

end;end.

49

LATIHAN 14

Objek Properti Nilai PropertiForm1 Caption Latihan 14

BorderStyle

bsNone

Panel1 Caption (Kosongkan)BevelInner

byRaised

BevelOuter

byLowered

RadioGroup1

Caption (Kosongkan)

Items SetujuTidak Setuju

Button1 Caption KeluarButton2 Caption Lanjut >>

Objek Properti Nilai PropertiForm2 Caption Latihan 14Label1 Caption TEORI

Font Name: Tahoma, Size: 16,Style: fsBold (True)

RichEdit1

Lines (Kosongkan)

ScrollBars

ssNone

50

ReadOnly TrueButton1 Caption TeoriButton2 Caption Latihan 1Button3 Caption Latihan 2Button4 Caption Latihan 3Button5 Caption Latihan 4Button6 Caption SoalButton7 Caption KembaliButton8 Caption Keluar

unit Ugab3;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,ExtCtrls, shellapi, StdCtrls;

type TForm1 = class(TForm) Panel1: TPanel; Label1: TLabel; Label2: TLabel; Label3: TLabel;

51

RadioGroup1: TRadioGroup; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure RadioGroup1Click(Sender:TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;Var Form1: TForm1;implementationuses Unit2, Ugab2;{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);begin

application.Terminate;end;procedure TForm1.FormCreate(Sender: TObject);begin

button1.Enabled:=false;button2.Enabled:=false;

end;procedure TForm1.RadioGroup1Click(Sender:TObject);begin

if radiogroup1.ItemIndex=0 then begin

52

button1.Enabled:=true; button2.Enabled:=true; end else if radiogroup1.ItemIndex=1then begin button1.Enabled:=true; button2.Enabled:=false; end;end;procedure TForm1.Button2Click(Sender:TObject);begin

form1.Visible:=false;form2.visible:=true;

end;end.unit Ugab2;interfaceusesWindows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,shellapi, StdCtrls, ComCtrls;

type TForm2 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Label1: TLabel; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; RichEdit1: TRichEdit;

53

Button8: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;Var Form2: TForm2;implementationuses Ugab1, Ugab3;{$R *.dfm}

procedure TForm2.Button1Click(Sender:TObject);begin

application.Terminate;end;procedure TForm2.Button2Click(Sender:TObject);begin

form2.Visible:=false;form1.Visible:=true;

end;

54

procedure TForm2.Button3Click(Sender:TObject);begin

form2.Visible:=false;form3.Visible:=true;

end;procedure TForm2.Button4Click(Sender:TObject);begin

shellexecute(handle,'open','latihan1.exe',nil,nil,sw_show);end;procedure TForm2.Button5Click(Sender:TObject);begin

shellexecute(handle,'open','latihan2.exe',nil,nil,sw_show);end;procedure TForm2.Button6Click(Sender:TObject);begin

shellexecute(handle,'open','latihan3.exe',nil,nil,sw_show);end;procedure TForm2.Button7Click(Sender:TObject);begin

shellexecute(handle,'open','latihan4.exe',nil,nil,sw_show);end;procedure TForm2.Button8Click(Sender:TObject);begin

55

richedit1.Visible:=true;richedit1.Lines.LoadFromFile('tulisan.rtf'

);end;procedure TForm2.FormCreate(Sender: TObject);begin

richedit1.Visible:=false;end;end.

56

LATIHAN 15

Objek Properti Nilai PropertiForm1 Caption Latihan 15Label1 Caption MEDIA TEKS, GAMBAR DAN

VIDEOFont Name: Tahoma, Size: 16,

Style: fsBold (True)RichEdit1 Lines (Kosongkan)*

ScrollBars

ssNone

ReadOnly TrueImage1 Proportio

nalTrue *

Image2 Picture Isi dengan File logo UNNES

Panel1 Caption (Kosongkan)*MediaPlayer1

Visible False

StatusBar1 AutoHint TrueButton1 Caption TulisanButton2 Caption GambarButton3 Caption VideoButton4 Caption StopButton5 Caption Keluar* = Ukuran sama besar

57

unit Ulatfilm;interfaceusesWindows, jpeg, shellapi, mplayer,Messages,SysUtils, Variants, Classes, Graphics,Controls, Forms, Dialogs, ExtCtrls,ComCtrls, StdCtrls;

type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; RichEdit1: TRichEdit; Label1: TLabel; StatusBar1: TStatusBar; Image1: TImage; Panel1: TPanel; MediaPlayer1: TMediaPlayer; Button4: TButton; Button5: TButton; Image2: TImage; procedure Button1Click(Sender: TObject);

58

procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);begin

button4.Visible:=false;panel1.Visible:=false;image1.Visible:=false;image2.Visible:=false;richedit1.Visible:=true;richedit1.Lines.LoadFromFile('tulisan.rtf'

);end;procedure TForm1.Button2Click(Sender:TObject);begin

button4.Visible:=false;panel1.Visible:=false;image1.Visible:=true;image2.Visible:=false;richedit1.Visible:=false;

59

image1.picture.LoadFromFile('A.jpg');end;procedure TForm1.Button3Click(Sender:TObject);begin

button1.Enabled:=false;button2.Enabled:=false;button3.Enabled:=false;button4.Visible:=true;panel1.Visible:=false;image1.Visible:=false;image2.Visible:=false;richedit1.Visible:=false;mediaplayer1.FileName:='video.avi';mediaplayer1.open;panel1.show;mediaplayer1.display:=panel1;mediaplayer1.displayrect:=rect(2,2,width,h

eight);mediaplayer1.play;

end;procedure TForm1.Button4Click(Sender:TObject);begin

mediaplayer1.Stop;button1.Enabled:=true;button2.Enabled:=true;button3.Enabled:=true;button4.Visible:=false;panel1.Visible:=false;image2.Visible:=true;

end;procedure TForm1.FormCreate(Sender: TObject);

60

beginimage2.Visible:=true;image1.Visible:=false;richedit1.Visible:=false;panel1.Visible:=false;button4.Visible:=false;

end;procedure TForm1.Button5Click(Sender:TObject);begin

if messagedlg ('Anda yakin akan keluar ?',mtconfirmation, mbokcancel,0) = mrok thenapplication.Terminate;

end;end.

61

LATIHAN 16Objek Properti Nilai Properti

Form1 Caption Latihan 2Label1 Caption DATA MAHASISWA

Font Name: Tahoma, Size: 15,Style: fsBold (True)

Label2 Caption NAMAFont Name: Tahoma, Size: 12

Label3 Caption ALAMATFont Name: Tahoma, Size: 12

Label4 Caption (Kosongkan)Label5 Caption (Kosongkan)Edit1 Text (Kosongkan)Edit2 Text (Kosongkan)Button1 Caption ProsesButton2 Caption VerdanaButton3 Caption LucidaButton4 Caption Ukuran 20Button5 Caption MerahButton6 Caption BiruButton7 Caption NormalButton8 Caption Keluar

62

unit ulatsoal;interfaceusesWindows, shellapi, Messages, SysUtils,Variants, Classes, Graphics, Controls,Forms, Dialogs, ExtCtrls, StdCtrls,ComCtrls;

type TForm1 = class(TForm) re1: TRichEdit; Kalkulator: TButton; SPU: TButton; Label1: TLabel; Waktu: TLabel; Label3: TLabel; A: TButton; B: TButton; C: TButton; D: TButton; Edit1: TEdit;

63

Ket1: TLabel; Ket2: TLabel; Mulai: TButton; next: TButton; keluar: TButton; Timer: TTimer; StatusBar1: TStatusBar; procedure KalkulatorClick(Sender:TObject); procedure SPUClick(Sender: TObject); procedure keluarClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure MulaiClick(Sender: TObject); procedure nextClick(Sender: TObject); procedure AClick(Sender: TObject); procedure BClick(Sender: TObject); procedure CClick(Sender: TObject); procedure TimerTimer(Sender: TObject); procedure DClick(Sender: TObject); private { Private declarations } public { Public declarations } end;Var Form1: TForm1; xb,fni,js,jb,x:integer; xs,fns,jss,jbs,filename:string;implementation{$R *.dfm}procedure TForm1.KalkulatorClick(Sender:TObject);begin

64

shellexecute(handle,'open','soal/calc.exe',nil,nil,sw_show);end;procedure TForm1.SPUClick(Sender: TObject);begin

shellexecute(handle,'open','soal/spu.exe',nil,nil,sw_show);end;procedure TForm1.keluarClick(Sender:TObject);begin IF messagedlg ('Anda yakin Akan Keluar ?', mtConfirmation,mbOkCancel,0) =mrOk then Application.Terminate;end;procedure TForm1.FormCreate(Sender: TObject);begin label1.Visible:=false; label3.Visible:=false; waktu.Visible:=false; a.Visible:=false; b.Visible:=false; c.Visible:=false; d.Visible:=false; edit1.Visible:=false; ket1.Visible:=false; ket2.Visible:=false; next.Visible:=false; re1.Visible:=false;

mulai.visible:=true; kembali.visible:=true;

65

keluar.visible:=true;end;procedure TForm1.MulaiClick(Sender: TObject);begin label1.Visible:=true; label3.Visible:=true; waktu.Visible:=true; a.Visible:=true; b.Visible:=true; c.Visible:=true; d.Visible:=true; edit1.Visible:=true; ket1.Visible:=true; ket2.Visible:=true; next.Visible:=true; re1.Visible:=true; mulai.Visible:=false; filename:='11'; re1.Lines.LoadFromFile('soal/'+filename+'.rtf'); js:=1; jss:=inttostr(js); ket1.Caption:='Jumlah Soal : '+jss; jb:=0; jbs:=inttostr(jb); ket2.Caption:='Jumlah Benar : '+jbs; timer.Enabled:=true; x:=0;end;procedure TForm1.nextClick(Sender: TObject);begin edit1.text:=''; a.Enabled:=true;

66

b.Enabled:=true; c.Enabled:=true; d.Enabled:=true; re1.visible:=true; js:=js+1; fni:=strtoint(filename); fni:=fni+1; if fni>15 THEN fni:=11; fns:=inttostr(fni); filename:=fns; re1.Lines.LoadFromFile('soal/'+filename+'.rtf'); jss:=inttostr(js); ket1.Caption:='Jumlah Soal: '+jss;

if ket1.Caption='Jumlah Soal: 5' then next.Enabled:=false;end;procedure TForm1.AClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='11' then

begin edit1.Text:='Benar'; jb:=jb+1; jbs:=inttostr(jb); ket2.Caption:='Jumlah Benar:'+jbs; end else if filename='12' then

67

begin edit1.Text:='Salah'; jb:=jb; jbs:=inttostr(jb); ket2.Caption:='Jumlah Benar:'+jbs; end else if filename='13' then begin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;next.Visible:=false;

end;end;procedure TForm1.BClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;

68

if filename='11' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='13' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;next.Visible:=false;

end;end;

69

procedure TForm1.CClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='11' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='13' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Salah';70

jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;next.Visible:=false;

end;end;

procedure TForm1.TimerTimer(Sender: TObject);begin

x:=x+2;xs:=inttostr(600-x);waktu.Caption:=xs+' detik';xb:=strtoint(xs);if xb=0 thenbegin

mulai.Enabled:=true;next.Enabled:=false;a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;x:=-1;re1.clear;timer.Enabled:=false;waktu.caption:='600';jb:=0;js:=0;

end;end;procedure TForm1.DClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;

71

c.Enabled:=false;d.Enabled:=false;if filename='11' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='13' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;next.Visible:=false;

72

end;end;end.

LATIHAN 17

unit Upers_gas;

interface

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

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Edit1: TEdit;

73

Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Edit9: TEdit; Edit10: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; Const R = 0.0821;var Form1: TForm1; Pid,Pre,Ptis,T,V,Pc,Vc,Tc,b,a,b2,a2 : extended;implementation

74

{$R *.dfm}

procedure TForm1.Button3Click(Sender: TObject);begin

Application.Terminate;end;

procedure TForm1.Button2Click(Sender: TObject);begin

edit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';edit5.Text:='';edit6.Text:='';edit7.text:='';edit8.Text:='';edit9.Text:='';edit10.Text:='';

end;

procedure TForm1.Button1Click(Sender: TObject);begin V:=strtofloat(edit1.Text); t:=strtofloat(edit2.Text); a:=strtofloat(edit3.Text);

b:=strtofloat(edit4.Text); Pid := (R*T)/V; b2 := (R*T)/(V-b); a2 := a/sqr(V);

75

Pre := b2-a2; Vc := 3*b; Tc := a/(27*sqr(b)); Pc := (8*a)/(27*b*R); Ptis := ((8*Pc*Vc*T)/(3*Tc*(V-(Vc/3))))-((3*Pc*sqr(Vc))/sqr(V));

edit5.Text:=floattostr(vc);edit6.Text:=floattostr(pc);edit7.Text:=floattostr(tc);edit8.Text:=floattostr(pid);edit9.Text:=floattostr(pre);edit10.Text:=floattostr(ptis);

end;

end.

76

LATIHAN 18

unit Ulat20;

interface

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

type TForm1 = class(TForm) rg: TRadioGroup; Label1: TLabel; Label2: TLabel; Edit1: TEdit; Edit2: TEdit;

77

Label3: TLabel; Label4: TLabel; Button1: TButton; Button2: TButton; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; procedure rgClick(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;

h1,h2,h3,oh1,oh2,oh3,ph1,ph2,ph3,ph4,ph5,ph6,poh1,poh2,poh3,ca,cb,ka,kb,d,d1,d2,d3 :double;

constkw=10e-14;

implementation{$R *.dfm}

procedure TForm1.rgClick(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

label1.Caption:='Konsentrasi Asam';78

label2.Caption:='Konstanta Asam (Ka)';label3.Caption:='';label4.Caption:='';label5.Caption:='';edit1.Text:='';edit2.Text:='';

end else if rg.ItemIndex=1thenbegin

label1.Caption:='Konsentrasi Basa';label2.Caption:='Konstanta Basa (Kb)';label3.Caption:='';label4.Caption:='';label5.Caption:='';edit1.Text:='';edit2.Text:='';

end;end;

procedure TForm1.Button2Click(Sender: TObject);begin

application.Terminate;end;

procedure TForm1.Button1Click(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

ca:=strtofloat(edit1.Text);ka:=strtofloat(edit2.Text);d:=sqr(ka)+4*ka*ca;d1:= sqrt(d);

79

h1:=(-ka+d1)/2;h2:=sqrt(ka*ca);h3:=sqrt(ka*ca+kw);ph1:=-ln(h1)/ln(10);ph2:=-ln(h2)/ln(10);ph3:=-ln(h3)/ln(10);label3.Caption:='pH =

'+floattostr(ph1);label4.Caption:='pH =

'+floattostr(ph2);label5.Caption:='pH =

'+floattostr(ph3);end else if rg.ItemIndex=1thenbegin

cb:=strtofloat(edit1.Text);kb:=strtofloat(edit2.Text);d2:=sqr(kb)+4*kb*cb;d3:= sqrt(d2);oh1:=(-kb+d3)/2;oh2:=sqrt(kb*cb);oh3:=sqrt(kb*cb+kw);poh1:=-ln(oh1)/ln(10);poh2:=-ln(oh2)/ln(10);poh3:=-ln(oh3)/ln(10);ph4:=14-poh1;ph5:=14-poh2;ph6:=14-poh3;label3.Caption:='pH =

'+floattostr(ph4);label4.Caption:='pH =

'+floattostr(ph5);label5.Caption:='pH =

'+floattostr(ph6);80

end;end;

end.

81

LATIHAN 19

unit Ulat21;

interface

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

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel;

82

Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label6: TLabel; Edit5: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Label7: TLabel; Label8: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;

ca,mla,ka,cb,mlb,h,ph,oh,poh,kb,mva,mvb,ml,cg,cas,cbs,cgs:real;const kw=10e-14;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender:TObject);begin

ca:=strtofloat(edit1.Text);83

mla:=strtofloat(edit2.Text);ka:=strtofloat(edit3.Text);cb:=strtofloat(edit4.Text);mlb:=strtofloat(edit5.Text);mva:=ca*mla;mvb:=cb*mlb;ml:=mla+mlb;if (mva > mvb) thenbegin

label7.Caption:='Larutan yang terjadiadalah buffer asam';

cas:=(mva-mvb)/ml;cg:=mvb/ml;ph:=

(-(ln(ka))/(ln(10)))+(ln(cg)/ln(cas));label8.Caption:='pH = '+floattostr(ph);

end else if (mva<mvb) thenbegin

label7.Caption:='Larutan yang terjadiadalah sisa basa kuat';

cbs:=(mvb-mva)/ml;poh:= -(ln(cbs))/(ln(10));ph:= 14-poh;label8.Caption:='pH = '+floattostr(ph);

end else if (mva=mvb) thenbegin

label7.Caption:='Larutan yang terjadiadalah garam terhidrolisis';

cgs:=(mvb)/ml;oh:= sqrt(kw/ka*cgs +kw);poh:=-((ln(oh))/(ln(10)));ph:= 14-poh;label8.Caption:='pH = '+floattostr(ph);

84

end; end;

procedure TForm1.Button2Click(Sender:TObject);begin

edit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';edit5.Text:='';label7.Caption:='';label8.Caption:='';edit1.SetFocus;

end;

procedure TForm1.Button3Click(Sender:TObject);begin

application.Terminate;end;

end.

85

LATIHAN 20

unit Ulat22;

interface

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

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel;

86

Label6: TLabel; Label7: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button4Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;implementation{$R *.dfm}

procedure TForm1.Button4Click(Sender:TObject);begin

Application.Terminate;end;

87

procedure TForm1.Button1Click(Sender:TObject);begin

label2.Visible:=true;label3.Visible:=true;label4.Visible:=true;label5.Visible:=true;label6.Visible:=true;label7.Visible:=true;edit1.Visible:=true;edit2.Visible:=true;edit3.Visible:=true;edit4.Visible:=true;edit5.Visible:=true;edit6.Visible:=true;edit1.Text:='Hidrogen';edit2.Text:='1.00794';edit3.Text:='1s1';edit4.Text:='13.598 V';edit5.Text:='1';edit6.Text:='20.28 K ';

end;

procedure TForm1.Button2Click(Sender:TObject);begin

label2.Visible:=true;label3.Visible:=true;label4.Visible:=true;label5.Visible:=true;label6.Visible:=true;label7.Visible:=true;edit1.Visible:=true;

88

edit2.Visible:=true;edit3.Visible:=true;edit4.Visible:=true;edit5.Visible:=true;edit6.Visible:=true;edit1.Text:='Litium';edit2.Text:='6.941';edit3.Text:='[He] 2s1';edit4.Text:='5.392 V';edit5.Text:='1';edit6.Text:='1615 K ';

end;

procedure TForm1.Button3Click(Sender:TObject);begin

label2.Visible:=true;label3.Visible:=true;label4.Visible:=true;label5.Visible:=true;label6.Visible:=true;label7.Visible:=true;edit1.Visible:=true;edit2.Visible:=true;edit3.Visible:=true;edit4.Visible:=true;edit5.Visible:=true;edit6.Visible:=true;edit1.Text:='Natrium';edit2.Text:='22.98977';edit3.Text:='[He] 3s1';edit4.Text:='5.139 V';edit5.Text:='1';

89

edit6.Text:='1156 K ';end;

end.

90

LATIHAN 21

unit Ulat23;

interface

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

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Edit1: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Label3: TLabel;

91

Label4: TLabel; procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject);

private { Private declarations } public { Public declarations } end;

var Form1: TForm1;

i,n,sum:integer;implementation{$R *.dfm}

procedure TForm1.Button3Click(Sender:TObject);begin

Application.Terminate;end;

procedure TForm1.Button2Click(Sender:TObject);begin

label3.Caption:='';label4.Caption:='';edit1.Text:='';edit1.setfocus;

end;

92

procedure TForm1.Button1Click(Sender:TObject);begin

n:=strtoint(edit1.Text);sum:=0;for i:=1 to n dobegin

sum:=sum+sqr(i);end;label3.Caption:='Jumlah Kuadrat dari 1

sampai ' +edit1.Text+ ' Adalah';label4.Caption:=inttostr(sum);

end;

end.

93

LATIHAN 22

unit Ulat24;

interface

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

type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Button1: TButton;

94

Memo: TMemo; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; data:array of real; jml,rata:real;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender:TObject);begin

if edit2.Text='' thenmessagedlg('Data belum diisi',mterror,

[mbok],0)elsebegin

setlength (data,strtoint(edit1.text)+1);

data[strtoint(edit1.text)]:=strtofloat(edit2.text);

95

edit1.text:=inttostr(strtoint(edit1.text)+1);

jml:=jml+strtofloat(edit2.Text);memo.lines.add('Data ke

'+inttostr(strtoint(edit1.text)-1)+ 'adalah ' +edit2.text+ ' Jumlah Data = '+floattostr(jml));

edit2.text:='';edit2.setfocus;

end;end;

procedure TForm1.Button2Click(Sender:TObject);begin

Rata:=jml/(strtoint(edit1.Text)-1);memo.Lines.Add('' );memo.Lines.Add('Rata-rata =

'+floattostr(rata));end;

procedure TForm1.Button3Click(Sender:TObject);begin

edit1.Text:=inttostr(1);edit2.text:='';edit2.setfocus;jml:=0;memo.Lines.Clear;

end;

procedure TForm1.Button4Click(Sender:TObject);

96

beginapplication.Terminate;

end;

end.

97

LATIHAN 23

unit Umid2;

interface

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

type TForm1 = class(TForm) rg: TRadioGroup; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel;

98

Label5: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label6: TLabel; Label7: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Label8: TLabel; procedure Button1Click(Sender: TObject); procedure rgClick(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;

oh,ca,va,ka,cb,vb,v,cg,x,alfa,salah,h:real;const kw=1e-14;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender:TObject);begin

if rg.ItemIndex=0 then99

beginca:=strtofloat(edit1.Text);va:=strtofloat(edit2.Text);ka:=strtofloat(edit3.Text);cb:=strtofloat(edit4.Text);vb:=(ca*va)/cb;v:=va+vb;cg:=(ca*va)/v;h:=(1e-8);oh:=kw/h;x:=(oh-h)/cg;alfa:=h/(h+ka);salah:=(x-alfa)*100;label6.caption:='Titrasi berhenti pada

pH 8';label7.caption:='Volume Basa yang

dibutuhkan = '+floattostr(vb)+' mL';label8.caption:='Kesalahan Titrasi =

'+floattostr(salah)+' %';edit1.SetFocus;

end else if rg.ItemIndex=1 thenbegin

ca:=strtofloat(edit1.Text);va:=strtofloat(edit2.Text);ka:=strtofloat(edit3.Text);cb:=strtofloat(edit4.Text);vb:=(ca*va)/cb;v:=va+vb;cg:=(ca*va)/v;h:=(1e-7);oh:=kw/h;x:=(oh-h)/cg;alfa:=h/(h+ka);

100

salah:=(x-alfa)*100;label6.caption:='Titrasi berhenti pada

pH 7';label7.caption:='Volume Basa yang

dibutuhkan = '+floattostr(vb)+' mL';;label8.caption:='Kesalahan Titrasi =

'+floattostr(salah)+' %';;edit1.SetFocus;

end else if rg.ItemIndex=2 thenbegin

ca:=strtofloat(edit1.Text);va:=strtofloat(edit2.Text);ka:=strtofloat(edit3.Text);cb:=strtofloat(edit4.Text);vb:=(ca*va)/cb;v:=va+vb;cg:=(ca*va)/v;h:=(1e-6);oh:=kw/h;x:=(oh-h)/cg;alfa:=h/(h+ka);salah:=(x-alfa)*100;label6.caption:='Titrasi berhenti pada

pH 6';label7.caption:='Volume Basa yang

dibutuhkan = '+floattostr(vb)+' mL';;label8.caption:='Kesalahan Titrasi =

'+floattostr(salah)+' %';;edit1.SetFocus;

end;end;

procedure TForm1.rgClick(Sender: TObject);101

beginif rg.ItemIndex=0 thenbegin

edit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';label7.caption:='';label8.caption:='';label6.caption:='Titrasi berhenti pada

pH 8';edit1.SetFocus;

end else if rg.ItemIndex=1 thenbegin

edit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';label6.caption:='Titrasi berhenti pada

pH 7';label7.caption:='';label8.caption:='';edit1.SetFocus;

end else if rg.ItemIndex=2 thenbegin

edit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';label6.caption:='Titrasi berhenti pada

pH 6';label7.caption:='';label8.caption:='';

102

edit1.SetFocus;end;

end;

procedure TForm1.Button3Click(Sender:TObject);begin

Application.Terminate;end;

end.

103

LATIHAN 24

unit Unit1;

interface

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

type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; BEVEL: TBevel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Image1: TImage; rg2: TRadioGroup; Bevel1: TBevel;

104

Label1: TLabel; Label2: TLabel; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure rg2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;implementationuses Unit2;{$R *.dfm}

procedure TForm1.Button1Click(Sender:TObject);begin

form1.visible:=false;form2.visible:=true;

end;

procedure TForm1.Button2Click(Sender:TObject);begin

Application.Terminate;end;

procedure TForm1.rg2Click(Sender: TObject);begin

105

if rg2.ItemIndex=0 thenbegin

button1.Enabled:=true;button2.Enabled:=true;

end else if rg2.ItemIndex=1 thenbegin

button2.enabled:=true;button1.Enabled:=false;

end;end;

end.

unit Unit2;

interface

106

uses Windows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, shellapi,jpeg,ExtCtrls,ComCtrls, MPlayer;

type TForm2 = class(TForm) Button1: TButton; Button2: TButton; RG: TRadioGroup; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton; Label1: TLabel; Image: TImage; RE: TRichEdit; StatusBar1: TStatusBar; Panel1: TPanel; Button3: TButton; a1: TButton; a2: TButton; a3: TButton; a4: TButton; a5: TButton; g1: TButton; g2: TButton; g3: TButton; g4: TButton; g5: TButton;

107

Label2: TLabel; logo: TImage; procedure Button1Click(Sender: TObject); procedure RGClick(Sender: TObject); procedure Panel1Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure a1Click(Sender: TObject); procedure a2Click(Sender: TObject); procedure a3Click(Sender: TObject); procedure a4Click(Sender: TObject); procedure a5Click(Sender: TObject); procedure g1Click(Sender: TObject); procedure g2Click(Sender: TObject); procedure g3Click(Sender: TObject); procedure g4Click(Sender: TObject); procedure g5Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form2: TForm2;implementationuses Unit3, Unit4, Unit5, Unit6;{$R *.dfm}

108

procedure TForm2.Button1Click(Sender:TObject);begin

IF messagedlg ('Anda yakin Akan Keluar ?',mtConfirmation,mbOkCancel,0)=mrOk thenApplication.Terminate;

end;

procedure TForm2.RGClick(Sender: TObject);begin

IF RG.ItemIndex=0 THENbegin

label1.Caption:='Titrasi Asam-Basa';logo.Visible:=true;a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;re.Visible:=false;image.Visible:=false;g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;a1.Caption:='Animasi Asam 1';a2.Caption:='Animasi Asam 2';a3.Caption:='Animasi Asam 3';a4.Caption:='Animasi Asam 4';a5.Caption:='Animasi Asam 5';

109

g1.Caption:='Gambar Asam 1';g2.Caption:='Gambar Asam 2';g3.Caption:='Gambar Asam 3';g4.Caption:='Gambar Asam 4';g5.Caption:='Gambar Asam 5';

END else IF RG.ItemIndex=1 THENbegin

logo.Visible:=true;label1.Caption:='Titrasi Redoks';a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;a1.Caption:='Animasi Redoks 1';a2.Caption:='Animasi Redoks 2';a3.Caption:='Animasi Redoks 3';a4.Caption:='Animasi Redoks 4';a5.Caption:='Animasi Redoks 5';g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;g1.Caption:='Gambar Redoks 1';g2.Caption:='Gambar Redoks 2';g3.Caption:='Gambar Redoks 3';g4.Caption:='Gambar Redoks 4';g5.Caption:='Gambar Redoks 5';re.Visible:=false;image.Visible:=false;

END;end;

110

procedure TForm2.Panel1Click(Sender:TObject);begin

aboutbox.showmodal;end;

procedure TForm2.Button7Click(Sender:TObject);begin

shellexecute(handle,'open','data/spu.exe',nil,nil,sw_show);end;

procedure TForm2.Button8Click(Sender:TObject);begin

shellexecute(handle,'open','data/calc.exe',nil,nil,sw_show);end;

procedure TForm2.Button2Click(Sender:TObject);begin

IF RG.ItemIndex=0 THENbegin

logo.Visible:=false;image.Visible:=false;a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;

111

re.Visible:=false;g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;re.Visible:=true;re.Lines.LoadFromFile('teori/asam-

basa.rtf');END else IF RG.ItemIndex=1 THENbegin

logo.Visible:=false;a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;re.Visible:=false;g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;image.Visible:=false;re.Visible:=true;re.Lines.LoadFromFile('teori/

redoks.rtf');END;

end;

procedure TForm2.Button5Click(Sender:TObject);

112

beginIF RG.ItemIndex=0 THENbegin

logo.Visible:=true;re.Visible:=false;image.Visible:=false;g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;a1.Visible:=true;a2.Visible:=true;a3.Visible:=true;a4.Visible:=true;a5.Visible:=true;a1.Caption:='Animasi Asam 1';a2.Caption:='Animasi Asam 2';a3.Caption:='Animasi Asam 3';a4.Caption:='Animasi Asam 4';a5.Caption:='Animasi Asam 5';

END else IF RG.ItemIndex=1 THENbegin

logo.Visible:=true;image.Visible:=false;re.Visible:=false;a1.Visible:=true;a2.Visible:=true;a3.Visible:=true;a4.Visible:=true;a5.Visible:=true;a1.Caption:='Animasi Redoks 1';a2.Caption:='Animasi Redoks 2';

113

a3.Caption:='Animasi Redoks 3';a4.Caption:='Animasi Redoks 4';a5.Caption:='Animasi Redoks 5';g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;

END;end;

procedure TForm2.Button4Click(Sender:TObject);begin

IF RG.ItemIndex=0 THENbegin

logo.Visible:=true;image.Visible:=false;re.Visible:=false;a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;re.Visible:=false;g1.Visible:=true;g2.Visible:=true;g3.Visible:=true;g4.Visible:=true;g5.Visible:=true;g1.Caption:='Gambar Asam 1';g2.Caption:='Gambar Asam 2';g3.Caption:='Gambar Asam 3';

114

g4.Caption:='Gambar Asam 4';g5.Caption:='Gambar Asam 5';

END else IF RG.ItemIndex=1 THENbegin

logo.Visible:=true;image.Visible:=false;re.Visible:=false;g1.Visible:=true;g2.Visible:=true;g3.Visible:=true;g4.Visible:=true;g5.Visible:=true;g1.Caption:='Gambar Redoks 1';g2.Caption:='Gambar Redoks 2';g3.Caption:='Gambar Redoks 3';g4.Caption:='Gambar Redoks 4';g5.Caption:='Gambar Redoks 5';

END;end;

procedure TForm2.Button6Click(Sender:TObject);begin

logo.Visible:=true;image.Visible:=false;re.Visible:=false;a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;g1.Visible:=false;g2.Visible:=false;

115

g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;IF RG.ItemIndex=0 THENbegin

form4.visible:=true;form2.Visible:=false;

END else IF RG.ItemIndex=1 THENbegin

form5.visible:=true;form2.Visible:=false;

END;end;

procedure TForm2.a1Click(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

if a1.Caption='Animasi Asam 1' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketas1.rtf');a1.Caption:='Jalankan';a2.Caption:='Animasi Asam 2';a3.Caption:='Animasi Asam 3';a4.Caption:='Animasi Asam 4';a5.Caption:='Animasi Asam 5';

end else if a1.Caption='Jalankan' thenbegin

a1.Caption:='Animasi Asam 1';image.Visible:=false;

116

re.Visible:=false;shellexecute(handle,'open','aktif/

Asam1.exe',nil,nil,sw_show);end;

end else if rg.ItemIndex=1 thenbegin

if a1.Caption='Animasi Redoks 1' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketre1.rtf');a1.Caption:='Jalankan';a2.Caption:='Animasi Redoks 2';a3.Caption:='Animasi Redoks 3';a4.Caption:='Animasi Redoks 4';a5.Caption:='Animasi Redoks 5';

end else if a1.Caption='Jalankan' thenbegin

a1.Caption:='Animasi Redoks 1';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Redoks1.exe',nil,nil,sw_show);end;

end;end;

procedure TForm2.a2Click(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

if a2.Caption='Animasi Asam 2' then117

beginimage.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketas2.rtf');a2.Caption:='Jalankan';a1.Caption:='Animasi Asam 1';a3.Caption:='Animasi Asam 3';a4.Caption:='Animasi Asam 4';a5.Caption:='Animasi Asam 5';

end else if a2.Caption='Jalankan' thenbegin

a2.Caption:='Animasi Asam 2';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Asam2.exe',nil,nil,sw_show);end;

end else if rg.ItemIndex=1 thenbegin

if a2.Caption='Animasi Redoks 2' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketre2.rtf');a2.Caption:='Jalankan';a1.Caption:='Animasi Redoks 1';a3.Caption:='Animasi Redoks 3';a4.Caption:='Animasi Redoks 4';a5.Caption:='Animasi Redoks 5';

end else if a2.Caption='Jalankan' thenbegin

118

a2.Caption:='Animasi Redoks 2';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Redoks2.exe',nil,nil,sw_show);end;

end;end;

procedure TForm2.a3Click(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

if a3.Caption='Animasi Asam 3' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketas3.rtf');a3.Caption:='Jalankan';a2.Caption:='Animasi Asam 2';a1.Caption:='Animasi Asam 1';a4.Caption:='Animasi Asam 4';a5.Caption:='Animasi Asam 5';

end else if a3.Caption='Jalankan' thenbegin

a3.Caption:='Animasi Asam 3';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Asam3.exe',nil,nil,sw_show);end;

end else if rg.ItemIndex=1 then119

beginif a3.Caption='Animasi Redoks 3' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketre3.rtf');a3.Caption:='Jalankan';a2.Caption:='Animasi Redoks 2';a1.Caption:='Animasi Redoks 1';a4.Caption:='Animasi Redoks 4';a5.Caption:='Animasi Redoks 5';

end else if a3.Caption='Jalankan' thenbegin

a3.Caption:='Animasi Redoks 3';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Redoks3.exe',nil,nil,sw_show);end;

end;end;procedure TForm2.a4Click(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

if a4.Caption='Animasi Asam 4' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketas4.rtf');a4.Caption:='Jalankan';

120

a2.Caption:='Animasi Asam 2';a3.Caption:='Animasi Asam 3';a1.Caption:='Animasi Asam 1';a5.Caption:='Animasi Asam 5';

end else if a4.Caption='Jalankan' thenbegin

a4.Caption:='Animasi Asam 4';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Asam4.exe',nil,nil,sw_show);end;

end else if rg.ItemIndex=1 thenbegin

if a4.Caption='Animasi Redoks 4' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketre4.rtf');a4.Caption:='Jalankan';a2.Caption:='Animasi Redoks 2';a3.Caption:='Animasi Redoks 3';a1.Caption:='Animasi Redoks 1';a5.Caption:='Animasi Redoks 5';

end else if a4.Caption='Jalankan' thenbegin

a4.Caption:='Animasi Redoks 4';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Redoks4.exe',nil,nil,sw_show);end;

121

end;end;

procedure TForm2.a5Click(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

if a5.Caption='Animasi Asam 5' thenbegin

image.Visible:=false;re.Visible:=true;re.lines.LoadFromFile('ket/

ketas5.rtf');a5.Caption:='Jalankan';a2.Caption:='Animasi Asam 2';a3.Caption:='Animasi Asam 3';a4.Caption:='Animasi Asam 4';a1.Caption:='Animasi Asam 1';

end else if a5.Caption='Jalankan' thenbegin

a5.Caption:='Animasi Asam 5';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Asam5.exe',nil,nil,sw_show);end;

end else if rg.ItemIndex=1 thenbegin

if a5.Caption='Animasi Redoks 5' thenbegin

image.Visible:=false;re.Visible:=true;

122

re.lines.LoadFromFile('ket/ketre5.rtf');

a5.Caption:='Jalankan';a2.Caption:='Animasi Redoks 2';a3.Caption:='Animasi Redoks 3';a4.Caption:='Animasi Redoks 4';a1.Caption:='Animasi Redoks 1';

end else if a5.Caption='Jalankan' thenbegin

a5.Caption:='Animasi Redoks 5';image.Visible:=false;re.Visible:=false;shellexecute(handle,'open','aktif/

Redoks5.exe',nil,nil,sw_show);end;

end;end;

procedure TForm2.g1Click(Sender: TObject);begin

logo.Visible:=false;if rg.ItemIndex=0 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Asam1.jpg');end else if rg.ItemIndex=1 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Redoks1.jpg');123

end;end;

procedure TForm2.g2Click(Sender: TObject);begin

logo.Visible:=false;if rg.ItemIndex=0 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Asam2.jpg');end else if rg.ItemIndex=1 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Redoks2.jpg');end;

end;

procedure TForm2.g3Click(Sender: TObject);begin

logo.Visible:=false;if rg.ItemIndex=0 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Asam3.jpg');end else if rg.ItemIndex=1 then

124

beginimage.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Redoks3.jpg');end;

end;

procedure TForm2.g4Click(Sender: TObject);begin

logo.Visible:=false;if rg.ItemIndex=0 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Asam4.jpg');end else if rg.ItemIndex=1 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Redoks4.jpg');end;

end;

procedure TForm2.g5Click(Sender: TObject);begin

logo.Visible:=false;if rg.ItemIndex=0 thenbegin

image.Visible:=true;re.Visible:=false;

125

image.picture.LoadFromFile('gambar/Asam5.jpg');end else if rg.ItemIndex=1 thenbegin

image.Visible:=true;re.Visible:=false;image.picture.LoadFromFile('gambar/

Redoks5.jpg');end;

end;

procedure TForm2.Button3Click(Sender:TObject);begin

logo.Visible:=true;image.Visible:=false;a1.Visible:=false;a2.Visible:=false;a3.Visible:=false;a4.Visible:=false;a5.Visible:=false;re.Visible:=false;g1.Visible:=false;g2.Visible:=false;g3.Visible:=false;g4.Visible:=false;g5.Visible:=false;re.Visible:=false;form2.Visible:=false;form6.visible:=true;

end;

end.126

unit Unit4;

interface

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

type TForm4 = class(TForm) kembali: TButton; Keluar: TButton; re1: TRichEdit;

127

timer: TTimer; ket1: TLabel; ket2: TLabel; waktu: TLabel; A: TButton; B: TButton; C: TButton; Edit1: TEdit; pilih: TLabel; mulai: TButton; maju: TButton; kal: TButton; Label1: TLabel; spu: TButton; D: TButton; Label2: TLabel; procedure kembaliClick(Sender: TObject); procedure KeluarClick(Sender: TObject); procedure mulaiClick(Sender: TObject); procedure majuClick(Sender: TObject); procedure AClick(Sender: TObject); procedure BClick(Sender: TObject); procedure CClick(Sender: TObject); procedure timerTimer(Sender: TObject); procedure kalClick(Sender: TObject); procedure spuClick(Sender: TObject); procedure DClick(Sender: TObject); private { Private declarations } public { Public declarations } end;

128

var Form4: TForm4;

xb,fni,js,jb,x:integer;xs,fns,jss,jbs,filename:string;

implementationuses Unit2;{$R *.dfm}

procedure TForm4.kembaliClick(Sender:TObject);begin

form2.visible:=true;form4.Visible:=false;js:=1;jb:=0;x:=0;mulai.Visible:=true;maju.Visible:=false;ket1.Visible:=false;ket2.Visible:=false;re1.visible:=false;waktu.Visible:=false;pilih.Visible:=false;a.Visible:=false;b.Visible:=false;c.Visible:=false;d.Visible:=false;edit1.Visible:=false;

end;

procedure TForm4.KeluarClick(Sender:TObject);

129

beginIF messagedlg ('Anda yakin Akan Keluar ?',mtConfirmation,mbOkCancel,0)=mrOk thenApplication.Terminate;

end;

procedure TForm4.mulaiClick(Sender: TObject);begin

spu.Visible:=true;label1.Visible:=true;re1.visible:=true;waktu.visible:=true;pilih.visible:=true;a.visible:=true;b.visible:=true;c.visible:=true;d.Visible:=true;a.Enabled:=true;b.Enabled:=true;c.Enabled:=true;d.Enabled:=true;ket1.visible:=true;ket2.visible:=true;edit1.visible:=true;maju.visible:=true;maju.enabled:=true;kal.visible:=true;mulai.visible:=false;filename:='11';re1.Lines.LoadFromFile('soal/'+filename+'.

rtf');js:=1;

130

jss:=inttostr(js);ket1.Caption:='Jumlah Soal:'+jss;jb:=0;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar:'+jbs;timer.Enabled:=true;x:=0;

end;

procedure TForm4.majuClick(Sender: TObject);begin

edit1.text:='';a.Enabled:=true;b.Enabled:=true;c.Enabled:=true;d.Enabled:=true;re1.visible:=true;js:=js+1;fni:=strtoint(filename);fni:=fni+1;if fni>20 THEN

fni:=11;fns:=inttostr(fni);filename:=fns;re1.Lines.LoadFromFile('soal/'+filename

+'.rtf');jss:=inttostr(js);ket1.Caption:='Jumlah Soal: ' +jss;if ket1.Caption='Jumlah Soal: 10' then

maju.Enabled:=false;end;

131

procedure TForm4.AClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='11' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='13' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Salah';132

jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='16' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='17' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='18' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='19' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='20' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

133

maju.Visible:=false;end;

end;

procedure TForm4.BClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='11' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='13' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);

134

ket2.Caption:='Jumlah Benar: '+jbs;end else if filename='15' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='16' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='17' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='18' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='19' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='20' thenbegin

135

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end;end;

procedure TForm4.CClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='11' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='13' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' then136

beginedit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='16' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='17' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='18' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='19' thenbegin

edit1.Text:='Benar';jb:=jb+1;

137

jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='20' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end;end;

procedure TForm4.timerTimer(Sender: TObject);begin

x:=x+2;xs:=inttostr(600-x);waktu.Caption:=xs;xb:=strtoint(xs);if xb=0 thenbegin

mulai.Enabled:=true;maju.Enabled:=false;a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;x:=-1;re1.clear;timer.Enabled:=false;waktu.caption:='600';jb:=0;js:=0;

end;138

end;

procedure TForm4.kalClick(Sender: TObject);begin

shellexecute(handle,'open','data/calc.exe',nil,nil,sw_show);end;

procedure TForm4.spuClick(Sender: TObject);begin

shellexecute(handle,'open','data/spu.exe',nil,nil,sw_show);end;

procedure TForm4.DClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='11' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='12' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);

139

ket2.Caption:='Jumlah Benar: '+jbs;end else if filename='13' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='14' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='15' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='16' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='17' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='18' thenbegin

140

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='19' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='20' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end;end;

end.

141

unit Unit5;

interface

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

type TForm5 = class(TForm) timer: TTimer; Label1: TLabel; waktu: TLabel; re1: TRichEdit; pilih: TLabel;

142

A: TButton; B: TButton; C: TButton; Edit1: TEdit; ket1: TLabel; ket2: TLabel; maju: TButton; mulai: TButton; kembali: TButton; Keluar: TButton; kal: TButton; spu: TButton; D: TButton; Label2: TLabel; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure KeluarClick(Sender: TObject); procedure kalClick(Sender: TObject); procedure spuClick(Sender: TObject); procedure timerTimer(Sender: TObject); procedure kembaliClick(Sender: TObject); procedure mulaiClick(Sender: TObject); procedure AClick(Sender: TObject); procedure BClick(Sender: TObject); procedure CClick(Sender: TObject); procedure majuClick(Sender: TObject); procedure DClick(Sender: TObject); private { Private declarations } public { Public declarations } end;

143

var Form5: TForm5;

xb,fni,js,jb,x:integer;xs,fns,jss,jbs,filename:string;

implementationuses Unit2;{$R *.dfm}

procedure TForm5.Button2Click(Sender:TObject);begin

Application.Terminate;end;

procedure TForm5.Button1Click(Sender:TObject);begin

form2.visible:=true;form5.Visible:=false;

end;

procedure TForm5.KeluarClick(Sender:TObject);begin

IF messagedlg ('Anda yakin Akan Keluar ?',mtConfirmation,mbOkCancel,0)=mrOk thenApplication.Terminate;

end;procedure TForm5.kalClick(Sender: TObject);begin

shellexecute(handle,'open','data/calc.exe',nil,nil,sw_show);

144

end;

procedure TForm5.spuClick(Sender: TObject);begin

shellexecute(handle,'open','data/spu.exe',nil,nil,sw_show);end;

procedure TForm5.timerTimer(Sender: TObject);begin

x:=x+2;xs:=inttostr(600-x);waktu.Caption:=xs;xb:=strtoint(xs);if xb=0 thenbegin

mulai.Enabled:=true;maju.Enabled:=false;a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;x:=-1;re1.clear;timer.Enabled:=false;waktu.caption:='600';jb:=0;js:=0;

end;end;

procedure TForm5.kembaliClick(Sender:TObject);

145

beginform2.visible:=true;form5.Visible:=false;js:=1;jb:=0;x:=0;mulai.Visible:=true;maju.Visible:=false;ket1.Visible:=false;ket2.Visible:=false;re1.visible:=false;waktu.Visible:=false;pilih.Visible:=false;a.Visible:=false;b.Visible:=false;c.Visible:=false;d.Visible:=false;edit1.Visible:=false;

end;

procedure TForm5.mulaiClick(Sender: TObject);begin

spu.Visible:=true;label1.Visible:=true;re1.visible:=true;waktu.visible:=true;pilih.visible:=true;a.visible:=true;b.visible:=true;c.visible:=true;d.Visible:=true;a.Enabled:=true;b.Enabled:=true;

146

c.Enabled:=true;d.Enabled:=true;ket1.visible:=true;ket2.visible:=true;edit1.visible:=true;maju.visible:=true;maju.enabled:=true;kal.visible:=true;mulai.visible:=false;filename:='21';re1.Lines.LoadFromFile('soal/'+filename+'.

rtf');js:=1;jss:=inttostr(js);ket1.Caption:='Jumlah Soal:'+jss;jb:=0;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar:'+jbs;timer.Enabled:=true;x:=0;

end;

procedure TForm5.AClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='21' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);

147

ket2.Caption:='Jumlah Benar: '+jbs;end else if filename='22' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='23' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='24' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='25' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='26' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='27' thenbegin

148

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='28' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='29' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='30' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end;end;

procedure TForm5.BClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='21' then

149

beginedit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='22' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='23' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='24' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='25' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='26' thenbegin

edit1.Text:='Salah';jb:=jb;

150

jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='27' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='28' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='29' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='30' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end ;end;

procedure TForm5.CClick(Sender: TObject);begin

a.Enabled:=false;151

b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='21' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='22' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='23' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='24' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='25' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

152

end else if filename='26' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='27' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='28' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='29' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='30' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end ;end;

153

procedure TForm5.majuClick(Sender: TObject);begin

edit1.text:='';a.Enabled:=true;b.Enabled:=true;c.Enabled:=true;d.Enabled:=true;re1.visible:=true;js:=js+1;fni:=strtoint(filename);fni:=fni+1;if fni>30 THENfni:=21;fns:=inttostr(fni);filename:=fns;re1.Lines.LoadFromFile('soal/'+filename+'.

rtf');jss:=inttostr(js);ket1.Caption:='Jumlah Soal: ' +jss;if ket1.Caption='Jumlah Soal: 10' then

maju.Enabled:=false;end;

procedure TForm5.DClick(Sender: TObject);begin

a.Enabled:=false;b.Enabled:=false;c.Enabled:=false;d.Enabled:=false;if filename='21' then

154

beginedit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='22' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='23' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='24' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='25' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='26' thenbegin

edit1.Text:='Salah';jb:=jb;

155

jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='27' thenbegin

edit1.Text:='Benar';jb:=jb+1;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='28' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='29' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;

end else if filename='30' thenbegin

edit1.Text:='Salah';jb:=jb;jbs:=inttostr(jb);ket2.Caption:='Jumlah Benar: '+jbs;maju.Visible:=false;

end ;end;

end.

156

unit Unit6;

interface

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

type TForm6 = class(TForm) Button1: TButton; Button2: TButton; RG: TRadioGroup; Bevel1: TBevel; Button3: TButton; Button4: TButton; Button5: TButton;

157

Memo: TMemo; StatusBar1: TStatusBar; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Panel2: TPanel; Label5: TLabel; Edit5: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure RGClick(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;constkw=1e-14;var Form6: TForm6;

m,ka,h,ph,oh,kb,ca,cb,mla,mlb,mva,mvb,ml,cas,cg,poh,cbs,cgs:real;implementationuses Unit2;{$R *.dfm}

158

procedure TForm6.Button1Click(Sender:TObject);begin

IF messagedlg ('Anda yakin Akan Keluar ?',mtConfirmation,mbOkCancel,0)=mrOk thenApplication.Terminate;

end;

procedure TForm6.Button2Click(Sender:TObject);begin

form6.Visible:=false;form2.visible:=true;memo.Lines.Clear;label1.Visible:=false;label2.Visible:=false;label3.Visible:=false;label4.Visible:=false;edit1.Visible:=false;edit2.Visible:=false;edit3.Visible:=false;edit4.Visible:=false;label5.Visible:=false;edit5.Visible:=false;memo.Visible:=false;

end;

procedure TForm6.Button4Click(Sender:TObject);

159

beginshellexecute(handle,'open','data/

calc.exe',nil,nil,sw_show);end;

procedure TForm6.Button5Click(Sender:TObject);begin

shellexecute(handle,'open','data/spu.exe',nil,nil,sw_show);end;

procedure TForm6.RGClick(Sender: TObject);begin

if rg.ItemIndex=0 thenbegin

memo.Visible:=true;memo.Lines.Clear;memo.Lines.Add('HITUNG pH ASAM LEMAH');memo.Lines.Add('');label1.Visible:=true;label1.Caption:='Konsentrasi Asam (M)

=';label2.Visible:=true;label2.Caption:='Konstanta Asam (Ka)

=';label3.Visible:=false;label4.Visible:=false;edit1.Visible:=true;edit2.Visible:=true;edit1.Text:='';edit2.Text:='';edit3.Visible:=false;

160

edit4.Visible:=false;label5.Visible:=false;edit5.Visible:=false;

end else if rg.ItemIndex=1 thenbegin

memo.Visible:=true;memo.Lines.Clear;memo.Lines.Add('HITUNG pH ASAM KUAT');memo.Lines.Add('');label1.Visible:=true;label1.Caption:='Konsentrasi Asam (M)

=';label2.Visible:=false;label3.Visible:=false;label4.Visible:=false;edit1.Visible:=true;edit2.Visible:=false;edit1.Text:='';edit3.Visible:=false;edit4.Visible:=false;label5.Visible:=false;edit5.Visible:=false;

end else if rg.ItemIndex=2 thenbegin

memo.Visible:=true;memo.Lines.Clear;memo.Lines.Add('HITUNG pH BASA LEMAH');memo.Lines.Add('');label1.Visible:=true;label1.Caption:='Konsentrasi Basa (M)

=';label2.Visible:=true;

161

label2.Caption:='Konstanta Basa (Kb)=';

label3.Visible:=false;label4.Visible:=false;edit1.Visible:=true;edit2.Visible:=true;edit1.Text:='';edit2.Text:='';edit3.Visible:=false;edit4.Visible:=false;label5.Visible:=false;edit5.Visible:=false;

end else if rg.ItemIndex=3 thenbegin

memo.Visible:=true;memo.Lines.Clear;memo.Lines.Add('HITUNG pH BASA KUAT');memo.Lines.Add('');label1.Visible:=true;label1.Caption:='Konsentrasi Basa(M)

=';label2.Visible:=false;label3.Visible:=false;label4.Visible:=false;edit1.Visible:=true;edit2.Visible:=false;edit1.Text:='';edit3.Visible:=false;edit4.Visible:=false;label5.Visible:=false;edit5.Visible:=false;

end else if rg.ItemIndex=4 thenbegin

162

memo.Visible:=true;memo.Lines.Clear;memo.Lines.Add('HITUNG pH TITRASI ASAM

KUAT DENGAN BASA KUAT');memo.Lines.Add('');label1.Visible:=true;label1.Caption:='Konsentrasi Asam (M)

=';label2.Visible:=true;label2.Caption:='Volume Asam (mL) =';label3.Visible:=true;label3.Caption:='Konsentrasi Basa (M)

=';label4.Visible:=true;label4.Caption:='Volume Basa yang

ditambahkan (mL) =';edit1.Visible:=true;edit2.Visible:=true;edit1.Text:='';edit2.Text:='';edit3.Visible:=true;edit4.Visible:=true;edit3.Text:='';edit4.Text:='';label5.Visible:=false;edit5.Visible:=false;

end else if rg.ItemIndex=5 thenbegin

memo.Visible:=true;memo.Lines.Clear;memo.Lines.Add('HITUNG pH TITRASI ASAM

LEMAH DENGAN BASA KUAT');memo.Lines.Add('');

163

label1.Visible:=true;label1.Caption:='Konsentrasi Asam (M)

=';label2.Visible:=true;label2.Caption:='Volume Asam (mL) =';label3.Visible:=true;label3.Caption:='Konstanta Asam (Ka)

=';label4.Visible:=true;label4.Caption:='Konsentrasi Basa (M)

=';label5.Visible:=true;label5.Caption:='Volume Basa yang

ditambahkan (mL) =';edit5.Visible:=true;edit5.Text:='';edit1.Visible:=true;edit2.Visible:=true;edit1.Text:='';edit2.Text:='';edit3.Visible:=true;edit4.Visible:=true;edit3.Text:='';edit4.Text:='';

end;END;

procedure TForm6.Button3Click(Sender:TObject);begin

if rg.ItemIndex=0 thenIF (edit1.Text='') or (edit2.Text='') then

164

messagedlg('Data belum diisi',mterror,[mbok],0) elsebegin

m:=strtofloat(edit1.Text);ka:=strtofloat(edit2.Text);h:=sqrt(m*ka);ph:=-((ln(h))/(ln(10))) ;memo.Lines.add('pH larutan =

'+floattostr(ph));end else if rg.ItemIndex=1 thenIF (edit1.Text='') then

messagedlg('Data belum diisi',mterror,[mbok],0) elsebegin

m:=strtofloat(edit1.Text);ph:=-((ln(m))/(ln(10))) ;memo.Lines.add('pH larutan =

'+floattostr(ph));end else if rg.ItemIndex=2 thenIF (edit1.Text='') or (edit2.Text='') then

messagedlg('Data belum diisi',mterror,[mbok],0) elsebegin

m:=strtofloat(edit1.Text);kb:=strtofloat(edit2.Text);oh:=sqrt(m*kb);h:=kw/oh;ph:=-((ln(h))/(ln(10))) ;memo.Lines.add('pH larutan =

'+floattostr(ph));end else if rg.ItemIndex=3 thenIF (edit1.Text='') then

165

messagedlg('Data belum diisi',mterror,[mbok],0) elsebegin

m:=strtofloat(edit1.Text);h:=kw/m;ph:=-((ln(h))/(ln(10))) ;memo.Lines.add('pH larutan =

'+floattostr(ph));end else if rg.ItemIndex=4 thenIF (edit1.Text='') or (edit2.Text='')or

(edit3.text='') or (edit4.text='') thenmessagedlg('Data belum diisi',mterror,

[mbok],0) elsebegin

ca:=strtofloat(edit1.Text);mla:=strtofloat(edit2.Text);cb:=strtofloat(edit3.Text);mlb:=strtofloat(edit4.Text);mva:=ca*mla;mvb:=cb*mlb;ml:=mla+mlb;if (mva > mvb) thenbegin

memo.lines.add('Larutan yangterjadi adalah sisa asam kuat');

cas:=(mva-mvb)/ml;ph:= -ln(cas)/ln(10);memo.lines.add('pH =

'+floattostr(ph));end else if (mva < mvb) thenbegin

memo.lines.add('Larutan yangterjadi adalah sisa basa kuat');

166

cbs:=(mvb-mva)/ml;poh:= -(ln(cbs))/(ln(10));ph:= 14-poh;memo.lines.add('pH =

'+floattostr(ph));end else if (mva=mvb) thenbegin

memo.lines.add('Larutan yangterjadi adalah garam netral');

memo.lines.add('pH = 7.0');end;

end else if rg.ItemIndex=5 thenIF (edit1.Text='') or (edit2.Text='')or

(edit3.text='') or (edit4.text='') or(edit5.text='') then

messagedlg('Data belum diisi',mterror,[mbok],0) elsebegin

ca:=strtofloat(edit1.Text);mla:=strtofloat(edit2.Text);ka:=strtofloat(edit3.Text);cb:=strtofloat(edit4.Text);mlb:=strtofloat(edit5.Text);mva:=ca*mla;mvb:=cb*mlb;ml:=mla+mlb;if (mva > mvb) thenbegin

memo.lines.add('Larutan yangterjadi adalah buffer asam');

cas:=(mva-mvb)/ml;cg:=mvb/ml;

167

ph:=(-(ln(ka))/(ln(10)))+(ln(cg)/ln(cas));

memo.lines.add('pH ='+floattostr(ph));end else if (mva<mvb) thenbegin

memo.lines.add('Larutan yangterjadi adalah sisa basa kuat');

cbs:=(mvb-mva)/ml;poh:= -(ln(cbs))/(ln(10));ph:= 14-poh;memo.lines.add('pH =

'+floattostr(ph));end else if (mva=mvb) thenbegin

memo.lines.add('Larutan yangterjadi adalah garam terhidrolisis');

cgs:=(mvb)/ml;oh:= sqrt(kw/ka*cgs +kw);poh:=-((ln(oh))/(ln(10)));ph:= 14-poh;memo.lines.add('pH =

'+floattostr(ph));end;

end;end;

end.

168

unit Unit3;

interface

uses Windows, SysUtils, Classes, Graphics,Forms, Controls, StdCtrls, Buttons, ExtCtrls, jpeg;

type TAboutBox = class(TForm) Panel1: TPanel; image: TImage; label5: TLabel; a: TLabel; b: TLabel; c: TLabel; OKButton: TButton; d: TLabel; e: TLabel; Button1: TButton; Image1: TImage; procedure OKButtonClick(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations }

169

public { Public declarations } end;

var AboutBox: TAboutBox;implementation{$R *.dfm}

procedure TAboutBox.OKButtonClick(Sender:TObject);begin

a.Caption:='Version: 1.0';b.Caption:='Copyright: 2007';c.Caption:='Comments :Informasi lebih

lanjut';d.Visible:=true;e.Visible:=true;close;

end;

procedure TAboutBox.Button1Click(Sender:TObject);begin

a.Caption:='Kimia Analitik I, UM Press,2005';

b.Caption:='Buku Teks Analisis KualitatfMakro dan Semimikro, 1985';

c.Caption:='http://www.iowa.chemistry';d.Visible:=false;e.Visible:=false;

end;

170

end.

171

LATIHAN 25

unit Ugrafikarray;

interface

uses Windows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs, Series, TeEngine, StdCtrls,ExtCtrls, TeeProcs, Chart;

type TForm1 = class(TForm)

172

Chart1: TChart; Chart2: TChart; Label1: TLabel; Label2: TLabel; Edit1: TEdit; Edit2: TEdit; Button1: TButton; Button2: TButton; Memo1: TMemo; Series1: TLineSeries; Series2: TAreaSeries; procedure Button1Click(Sender: TObject); procedure Memo1Change(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; Data : array of real ;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender:TObject);begin

if edit2.Text='' then messagedlg('Data belumdiisi',mtError,[mbok],0) else

173

begin

setlength(data,strtoint(edit1.text)+1); data[strtoint(edit1.text)] :=strtofloat(edit2.text);

series1.Add(strtofloat(edit2.text),'',clred);

series2.Add(strtofloat(edit2.text),'',clblue); memo1.lines.add(edit1.text+' -->'+edit2.text);

edit1.text :=inttostr(strtoint(edit1.text)+1); edit2.Text :=floattostr(strtofloat(edit2.text)); edit2.text :=' '; edit2.SetFocus; end;end;

procedure TForm1.Memo1Change(Sender:TObject);begin

if edit1.text='11' thenmemo1.ScrollBars:=ssVertical;

end;

procedure TForm1.Button2Click(Sender:TObject);begin

174

application.terminate;end;

end.

LATIHAN 26 GRAFIK ARAAY

unit Ugrafikarray;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Series, TeEngine, StdCtrls, ExtCtrls, TeeProcs, Chart;

type TForm1 = class(TForm)

175

Chart1: TChart; Chart2: TChart; Label1: TLabel; Label2: TLabel; Edit1: TEdit; Edit2: TEdit; Button1: TButton; Button2: TButton; Memo1: TMemo; Series1: TLineSeries; Series2: TAreaSeries; procedure Button1Click(Sender: TObject); procedure Memo1Change(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; Data : array of real ;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);begin

if edit2.Text='' then messagedlg('Data belum diisi',mtError,[mbok],0) else

176

begin

setlength(data,strtoint(edit1.text)+1); data[strtoint(edit1.text)] := strtofloat(edit2.text);

series1.Add(strtofloat(edit2.text),'',clred);

series2.Add(strtofloat(edit2.text),'',clblue); memo1.lines.add(edit1.text+' -->'+edit2.text);

edit1.text :=inttostr(strtoint(edit1.text)+1); edit2.Text := floattostr(strtofloat(edit2.text)); edit2.text :=' '; edit2.SetFocus; end;end;

procedure TForm1.Memo1Change(Sender: TObject);begin

if edit1.text='11' thenmemo1.ScrollBars:=ssVertical;end;

procedure TForm1.Button2Click(Sender: TObject);begin

177

application.terminate;end;

end.

LATIHAN 27 GRAFIK FUNGSI

unit Ugrafikfungsi;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls, Series;

type TForm1 = class(TForm) Label1: TLabel;

178

RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; Chart1: TChart; Label2: TLabel; Button1: TButton; Button2: TButton; Series1: TLineSeries; Edit1: TEdit; Label3: TLabel; procedure RadioButton1Click(Sender: TObject); procedure RadioButton2Click(Sender: TObject); procedure RadioButton3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;implementation{$R *.dfm}

procedure TForm1.RadioButton1Click(Sender: TObject);begin radiobutton1.checked:=true;

179

radiobutton2.checked:=false; radiobutton3.checked:=false;end;

procedure TForm1.RadioButton2Click(Sender: TObject);begin radiobutton2.checked:=true; radiobutton1.checked:=false; radiobutton3.checked:=false;end;

procedure TForm1.RadioButton3Click(Sender: TObject);begin radiobutton3.checked:=true; radiobutton2.checked:=false; radiobutton1.checked:=false;end;

procedure TForm1.Button1Click(Sender: TObject);var i : integer; Function FX(x : integer):real; begin FX:=2*x*x+3*x+5; end;

Function fs(s:integer):real;begin

fs:=sin(pi/180*s);end;

180

Function fc(c:integer):real;begin

fc:= cos(pi/180*c)-2*sin(pi/180*c);end;

begin series1.Clear; for i := 1 to strtoint(edit1.text) do if radiobutton1.Checked then series1.add(FX(i)) else if radiobutton2.checked then series1.add(sin(pi/180*i))

else if radiobutton3.checked then series1.add(fc(i))end;

procedure TForm1.Button2Click(Sender: TObject);begin

application.terminate;end;

end.

181

LATIHAN 28 DIFERENSIAL NUMERIK (CARABACKWARD)

unit Udiferensial1;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Series, TeEngine, ExtCtrls, TeeProcs, Chart, jpeg;

type TForm1 = class(TForm) Label1: TLabel; Label5: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Button1: TButton;

182

Button2: TButton; Button3: TButton; Label2: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Edit9: TEdit; Label3: TLabel; Label4: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;

i: integer; x : real;Const dx = 0.0001; implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);

Function y(x:real):real;183

begin y := 2*X*X*X + 5*X*X – 4*X + 10; end;

Function dy(x:real):real;begin

dy := (y(x)-y(x-dx))/dx; end;

Function d2y(x:real):real;begin

d2y := (dy(x)-dy(x-dx))/dx;end;

Function d3y(x:real):real;begin d3y := (d2y(x)-d2y(x-dx))/dx;end;

begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin x := strtofloat(edit1.Text); edit2.Text := floattostr(dy(x)); edit3.Text := floattostr(d2y(x)); edit4.Text := floattostr(d3y(x)); edit1.SetFocus; end;end;

procedure TForm1.Button3Click(Sender: TObject);

184

begin if messageDlg ('Yakin akan keluar?', mtConfirmation, mbOkCancel,0) = mrOk then Application.Terminate;end;

procedure TForm1.Button2Click(Sender: TObject);begin

edit1.Text := ' '; edit2.Text := ' '; edit3.Text := ' '; edit4.Text := ' '; edit1.SetFocus;end;end.

185

LATIHAN 29 DIFERENSIAL NUMERIK (CARA FORWARD)

unit Udiferensial1;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Series, TeEngine, ExtCtrls, TeeProcs, Chart, jpeg;

type TForm1 = class(TForm) Label1: TLabel; Label5: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Button1: TButton; Button2: TButton; Button3: TButton;

186

Label2: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Edit9: TEdit; Label3: TLabel; Label4: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; i: integer; x : real;Const dx = 0.01; implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

Function y(x:real):real; begin

187

y := 2*X*X*X + 5*X*X – 4*X + 10; end;

Function dy(x:real):real;begin dy := (y(x+dx)-y(x))/dx;end;Function d2y(x:real):real;begin d2y := (dy(x+dx)-dy(x))/dx;end;Function d3y(x:real):real;begin d3y := (d2y(x+dx)-d2y(x))/dx;end;

begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin x := strtofloat(edit1.Text); edit2.Text := floattostr(dy(x)); edit3.Text := floattostr(d2y(x)); edit4.Text := floattostr(d3y(x)); edit1.SetFocus; end;end;

procedure TForm1.Button3Click(Sender: TObject);begin

188

if messageDlg ('Yakin akan keluar?',mtConfirmation,mbOkCancel,0) = mrOk then Application.Terminate;end;

procedure TForm1.Button2Click(Sender: TObject);begin

edit1.Text := ' '; edit2.Text := ' '; edit3.Text := ' '; edit4.Text := ' '; edit1.SetFocus;end;

end.

189

190

LATIHAN 30 DIFERENSIAL NUMERIK (CARA CENTRAL)

unit Udiferensial1;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Series, TeEngine, ExtCtrls, TeeProcs, Chart, jpeg;

type TForm1 = class(TForm) Label1: TLabel; Label5: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Button1: TButton; Button2: TButton;

191

Button3: TButton; Label2: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Edit9: TEdit; Label3: TLabel; Label4: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; i: integer; x : real;Const dx = 0.01; implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

Function y(x:real):real;192

begin y := 2*X*X*X + 5*X*X – 4*X + 10; end;

Function dy(x:real):real;begin dy := (y(x+dx)-y(x-dx))/(2*dx);end;

Function d2y(y:real):real;begin d2y :=

(dy(x+dx)-dy(x-dx))/(2*dx);end;

Function d3y(x:real):real;begin d3y :=

(d2y(x+dx)-d2y(x-dx))/(2*dx);end;

begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin x := strtofloat(edit1.Text); edit2.Text := floattostr(dy(x)); edit3.Text := floattostr(d2y(x)); edit4.Text := floattostr(d3y(x)); edit1.SetFocus; end;end;

193

procedure TForm1.Button3Click(Sender: TObject);begin if messageDlg ('Yakin akan keluar?',mtConfirmation,mbOkCancel,0) = mrOk then Application.Terminate;end;procedure TForm1.Button2Click(Sender: TObject);begin

edit1.Text := ' '; edit2.Text := ' '; edit3.Text := ' '; edit4.Text := ' '; edit1.SetFocus;end;end.

194

LATIHAN 31 DIFERENSIAL NUMERIK DAN GRAFIKFUNGSI

unit Udiferensial1;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Series, TeEngine, ExtCtrls, TeeProcs, Chart, jpeg;

type TForm1 = class(TForm) Label1: TLabel; Label5: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit;

195

Edit4: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Image1: TImage; Label2: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Edit9: TEdit; Label3: TLabel; Label4: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; Edit10: TEdit; RadioButton1: TRadioButton; RadioButton2: TRadioButton; Button4: TButton; Chart1: TChart; Series1: TLineSeries; Series2: TBarSeries; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button4Click(Sender: TObject);

196

procedure RadioButton1Click(Sender: TObject); procedure RadioButton2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; i: integer; tc,Tk,dS,dCp : real;Const n = 1; F = 96485; dt = 0.1; implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

Function E(tc:real):real; begin E := 0.23659-4.8564e-4*tc-3.4205e-6*tc*tc+5.869e-9*tc*tc*tc; end;

Function dEf(tc:real):real;begin

dEf := (E(tc+dt)-E(tc))/dt;end;

197

Function d2Ef(tc:real):real;begin d2Ef := (dEf(tc+dt)-dEf(tc))/dt;end;

Function dEb(tc:real):real;begin dEb := (E(tc)-E(tc-dt))/dt;end;

Function d2Eb(tc:real):real;begin d2Eb := (dEb(tc)-dEb(tc-dt))/dt;end;

Function dEc(tc:real):real;begin dEc := (E(tc+dt)-E(tc-dt))/(2*dt);end;

Function d2Ec(tc:real):real;begin d2Ec :=

(dEc(tc+dt)-dEc(tc-dt))/(2*dt);end;

begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin tc := strtofloat(edit1.Text);

198

dS := n*F*dEc(tc); Tk := tc + 273; dCp := n*F*Tk*d2Ec(tc); edit2.Text := floattostr(E(tc)); edit3.Text := floattostr(dEf(tc)); edit4.Text := floattostr(d2Ef(tc)); edit5.Text := floattostr(dEb(tc)); edit6.Text := floattostr(d2Eb(tc)); edit7.Text := floattostr(dEc(tc)); edit8.Text := floattostr(d2Ec(tc)); edit9.Text := floattostr(dS); edit10.Text := floattostr(dCp); edit1.SetFocus; end;end;

procedure TForm1.Button3Click(Sender: TObject);begin if messageDlg ('Yakin akan keluar?',mtConfirmation,mbOkCancel,0) = mrOk then Application.Terminate;end;

procedure TForm1.Button2Click(Sender: TObject);begin

edit1.Text := ' '; edit2.Text := ' '; edit3.Text := ' '; edit4.Text := ' '; edit5.Text := ' ';

199

edit6.Text := ' '; edit7.Text := ' '; edit8.Text := ' '; edit9.Text := ' '; edit10.Text := ' '; edit1.SetFocus;end;

procedure TForm1.Button4Click(Sender: TObject);var i : integer;

Function Ei(i:integer):real; begin Ei := 0.23659-4.8564e-4*i-3.4205e-6*i*i+5.869e-9*i*i*i; end;begin series1.Clear; series2.Clear; if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin for i := 1 to 2*strtoint(edit1.text) do if radiobutton1.Checked then begin series1.add(Ei(i)) end else if radiobutton2.Checked then begin series2.add(Ei(i));

200

end; end;end;procedure TForm1.RadioButton1Click(Sender: TObject);begin radiobutton1.checked:=true; radiobutton2.checked:=false;end;

procedure TForm1.RadioButton2Click(Sender: TObject);begin radiobutton2.checked:=true; radiobutton1.checked:=false;end;

end.

201

LATIHAN 32 AKAR PERSAMAAN (METODE NEWTON)

unit Unewton;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Edit1: TEdit; Button1: TButton; Button2: TButton; Button3: TButton;

202

Memo1: TMemo; Memo2: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; awal, akhir,Xa,Xb : real; n : integer;Const

dx = 0.001; presisi = 1e-5;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

Function y(x:real) : real; begin y :=x*x+ 3*x -10;

end;Function dy(x:real) : real;

begin dy :=(y(x)-y(x-dx))/dx;

end; Procedure Cari_akar(var Xa,Xb : real); begin

203

Xb := Xa - (y(Xa)/dy(Xa)); awal := Xa; akhir := Xb; Xa := Xb; end;begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin Xa := strtofloat(edit1.Text); n := 1; repeat Cari_akar(Xa,Xb);

Memo1.Lines.Add(floattostr(awal));

Memo2.Lines.Add(floattostr(akhir));

inc(n,1); until abs(akhir-awal) <= presisi; end; edit1.SetFocus;end;

procedure TForm1.Button2Click(Sender: TObject);begin edit1.Text := ' '; memo1.Clear; memo2.Clear; edit1.SetFocus;

204

end;

procedure TForm1.Button3Click(Sender: TObject);begin

application.Terminate;end;

end.

205

LATIHAN 33 AKAR PERSAMAAN (METODE SECANT)

unit Uakar1;

interface

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

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Button1: TButton; Button2: TButton; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Edit1: TEdit;

206

Button3: TButton; Memo1: TMemo; Memo2: TMemo; Label7: TLabel; Label8: TLabel; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; awal1,awal2, akhir,Xa,Xb, Xc : real; n : integer;Const presisi = 1e-5; implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); Function y(x:real) : real; begin y :=x*x+ 3*x -10;

end; Procedure Cari_akar(var Xa, Xb, Xc : real); begin

207

Xc := Xb - ((Xb - Xa)/(y(Xb) - y(Xa)))*y(Xb); awal1 := Xa; awal2 := Xb; akhir := Xc; Xa := Xb; Xb := Xc; end;begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0) else begin Xa := strtofloat(edit1.Text); Xb := strtofloat(edit2.Text); n := 1; repeat Cari_akar(Xa,Xb, Xc);

Memo1.Lines.Add(floattostr(awal2));

Memo2.Lines.Add(floattostr(akhir));

inc(n,1); until abs(akhir-awal2) <= presisi; edit1.SetFocus; end;end;procedure TForm1.Button2Click(Sender: TObject);begin edit1.Text := ' ';

208

edit2.Text := ' '; memo1.Clear; memo2.Clear; edit1.SetFocus;end;

procedure TForm1.Button3Click(Sender: TObject);begin

application.Terminate;end;

end.

209

LATIHAN 34 AKAR PERSAMAAN (VAN DER WALLS)

unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, TeEngine, Series, StdCtrls, jpeg, ExtCtrls, TeeProcs, Chart;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Button1: TButton;

210

Button2: TButton; Button3: TButton; Button4: TButton; Memo1: TMemo; Memo2: TMemo; Chart1: TChart; Image1: TImage; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Label9: TLabel; Label10: TLabel; Series1: TAreaSeries; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; p, T, pc, Tc, a, b, awal, akhir,Va,Vb :extended; n : integer;Const

dx = 0.001; presisi = 1e-5; {epsilon} R = 8.314;

211

implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); Function f(x : extended) : extended; begin f :=(p*x*x*x)-((b*p+R*T)*x*x)+(a*x)-(a*b);

end;Function df(x : extended) : extended;begin df := (f(x+dx) -

f(x-dx))/(2*dx);end;

Procedure Hitung_abVa; begin a := (27*sqr(R)*sqr(Tc))/(64*pc); b := (R*Tc)/(8*pc); Va := (R*T)/p; end; Procedure Newton(var Va,Vb : extended); begin Vb := Va - (f(Va)/df(Va)); awal := Va; akhir := Vb; Va := Vb; end;begin if edit1.Text =' ' then messagedlg('Data belum diisi',mtError,[mbok],0)

212

else begin Tc := strtofloat(edit1.Text); pc := strtofloat(edit2.Text); p := strtofloat(edit3.Text); T := strtofloat(edit4.Text); Hitung_abVa; edit5.Text := floattostr(Va); n := 1; repeat Newton(Va,Vb);

Memo1.Lines.Add(floattostr(awal));

Memo2.Lines.Add(floattostr(akhir)); inc(n,1); until abs(akhir-awal) <= presisi; edit1.SetFocus; end; edit1.SetFocus;end;procedure TForm1.Button2Click(Sender: TObject);

var n : integer; Function fn(n : integer) : extended; begin fn :=(p*n*n*n)-((b*p+R*T)*n*n)+(a*n)-(a*b);

end;begin series1.Clear; if edit1.Text ='' then messagedlg('Data belum diisi',mtError,[mbok],0)

213

else begin for n := -100 to 100 do begin series1.add(fn(n)); end; end; edit1.SetFocus;end;procedure TForm1.Button3Click(Sender: TObject);begin

edit1.Text := ' '; edit2.Text := ' '; edit3.Text := ' '; edit4.Text := ' '; edit5.Text := ' '; memo1.Clear; memo2.Clear; edit1.SetFocus;end;procedure TForm1.Button4Click(Sender: TObject);begin

APPLICATION.Terminate;end;end.

214

LATIHAN 35 INTEGRASI NUMERIK (Metode Euler)

unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,TeEngine, Series, StdCtrls, ExtCtrls,TeeProcs, Chart;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Memo1: TMemo; Memo2: TMemo;

215

Chart1: TChart; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Series1: TLineSeries; Label7: TLabel; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; t0, tf, h, sum : real; N : integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject); Function y(x : real):real;

begin y := x;end;Procedure Integrasi_Euler;

var h, x : real; i : integer;

begin sum := 0; h := (tf-t0)/N;

216

x := t0; sum := sum + y(x)/2; for i := 1 to N-1 do

beginx := t0 + i*h;

sum := sum + y(x); end;

x := tf; sum := sum + y(x)/2; sum := sum*h;

Memo1.Lines.Add(Inttostr(N)); Memo2.Lines.Add(floattostr(sum)); end;begin Memo1.Clear; Memo2.Clear; Series1.Clear; Edit1.SetFocus; t0:= strtofloat(edit1.Text); tf:= strtofloat(edit2.Text); N:= strtoint(edit3.Text); Integrasi_Euler; Edit1.SetFocus;end;

procedure TForm1.Button3Click(Sender:TObject);begin Memo1.Clear; Memo2.Clear; Series1.Clear; Edit1.Clear;

217

Edit2.Clear; Edit3.Clear; Edit1.SetFocus;end;

procedure TForm1.Button4Click(Sender:TObject);begin Application.Terminate;end;

procedure TForm1.Button2Click(Sender:TObject); var i : integer; function yi(i : integer) : extended; begin yi := i;

end;begin series1.Clear; If edit1.Text ='' then messagedlg('Data belumdiisi',mtError,[mbok],0) else begin for i := 0 to N do begin series1.add(yi(i)); end; end;

edit1.SetFocus;end;end.

218

219

LATIHAN 36 INTEGRASI NUMERIK (Metode Simpson)

unit USimpson;

interface

uses Windows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,TeEngine, Series, StdCtrls, ExtCtrls,TeeProcs, Chart;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Button1: TButton; Button2: TButton;

220

Button3: TButton; Button4: TButton; Memo1: TMemo; Memo2: TMemo; Chart1: TChart; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Series1: TLineSeries; Label7: TLabel; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1; t0, tf, h, sum, sun, luas : real; N : integer;implementation{$R *.dfm}

procedure TForm1.Button1Click(Sender:TObject); Function y(x : real):real;

begin y := x;end;

221

Procedure Integrasi_Euler; var h, x : real; i : integer;

begin sum := 0; h := (tf-t0)/N; x := t0;

sum := sum + y(x); i:=1; repeat

x := t0 + i*h; sum := sum + 4*y(x);

inc(i,2); until i > n-1; x := tf;

sum := sum + y(x); sum := sum*h/3;

sun := 0; i:=2;

repeatx := t0 + i*h;

sun := sun + 2*y(x); inc(i,2); until i > n-1; sun:=sun*h/3;

luas:= sun+sum;

Memo1.Lines.Add(Inttostr(N));

Memo2.Lines.Add(floattostr(luas)); end;begin Memo1.Clear; Memo2.Clear;

222

Series1.Clear; Edit1.SetFocus; t0:= strtofloat(edit1.Text); tf:= strtofloat(edit2.Text); N:= strtoint(edit3.Text); Integrasi_Euler; Edit1.SetFocus;end;

procedure TForm1.Button3Click(Sender:TObject);begin Memo1.Clear; Memo2.Clear; Series1.Clear; Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit1.SetFocus;end;

procedure TForm1.Button4Click(Sender:TObject);begin Application.Terminate;end;

procedure TForm1.Button2Click(Sender:TObject); var i : integer; function yi(i : integer) :extended; begin

223

yi := i;end;

begin series1.Clear; if edit1.Text ='' then messagedlg('Data belumdiisi',mtError,[mbok],0) else begin for i := 0 to N do begin series1.add(yi(i)); end; end;

edit1.SetFocus;end;

end.

224

LATIHAN 37 DIFFERENSIAL ORDINER

unit URUNGEKUTTA;

interface

uses Windows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms, Dialogs,Buttons, StdCtrls, ExtCtrls, TeEngine,Series, TeeProcs, Chart;

type225

TForm1 = class(TForm) SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton5: TSpeedButton; SpeedButton6: TSpeedButton; SpeedButton7: TSpeedButton; Bevel1: TBevel; Bevel2: TBevel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Label4: TLabel; Label5: TLabel; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; GroupBox1: TGroupBox; RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; RadioButton4: TRadioButton; Memo1: TMemo; Memo2: TMemo; Chart1: TChart; Series1: TLineSeries; procedure SpeedButton6Click(Sender:TObject);

226

procedure SpeedButton7Click(Sender:TObject); private { Private declarations } public { Public declarations } end;Const

dim=3; plot=0;

Type mat = array[1..dim] of real;Var Form1: TForm1;

i,j,N,zat : integer; t,h,t0,tf,k1,k2,k3,k4,k5 : real; y,y0,yt,yEuler,m1,m2,m3,m4 : mat;implementation{$R *.dfm}

procedure TForm1.SpeedButton6Click(Sender:TObject);

Function fx(i:integer; t: real; y: mat):real; Begin Case i of 1: fx := -k1*y[1]; 2: fx := +k1*y[1]-k2*y[2]; 3: fx := +k2*y[2]; end; end; Procedure Euler; var i: integer; Begin

227

for i:= 1 to dim do m1[i]:=fx(i,t,y); for i:= 1 to dim do yEuler[i]:=y[i]+ (h*m1[i]); for i:= 1 to dim do m2[i]:=fx(i,t+h,yEuler); for i:= 1 to dim do y[i]:= y[i]+0.5*h* (m1[i]+

m2[i]); for i:= 1 to dim do yt[i]:= y[i]+j*plot; if radiobutton1.Checked = true then begin Memo1.Visible := false; Memo2.Visible := false; Chart1.Visible := true; series1.Add(yt[zat]); end; if radiobutton2.Checked = truethen begin Chart1.Visible := false; Series1.Clear; Memo1.Visible := true; Memo2.Visible := true; if j <= N/2 then Memo1.Lines.Add(''+inttostr(j)+' --> '+

floattostr(yt[zat])) else Memo2.Lines.Add(''+inttostr(j)+' --> '+

floattostr(yt[zat]))228

end; t:= t0 + j*h; end; Procedure RungeKutta4; var i: integer; Begin for i:= 1 to dim do m1[i]:=fx(i,t,y); for i:= 1 to dim do yEuler[i]:=y[i]+ (h*m1[i]/2); for i:= 1 to dim do m2[i]:=fx(i,t+h/2,yEuler); for i:= 1 to dim do yEuler[i]:=y[i]+ (h*m2[i]/2); for i:= 1 to dim do m3[i]:=fx(i,t+h/2,yEuler); for i:= 1 to dim do yEuler[i]:=y[i]+ (h*m3[i]); for i:= 1 to dim do m4[i]:=fx(i,t+h,yEuler); for i:= 1 to dim do y[i]:= y[i]+(h/6)*(m1[i]+

2*m2[i]+2*m3[i]+m4[i]); for i:= 1 to dim do yt[i]:= y[i]+j*plot; if radiobutton1.Checked = true then begin Memo1.Visible := false; Memo2.Visible := false; Chart1.Visible := true; series1.Add(yt[zat]); end;

229

if radiobutton2.Checked =true then begin Series1.Clear; Chart1.Visible := false; Memo1.Visible := true; Memo2.Visible := true; if j <= N/2 then Memo1.Lines.Add(''+inttostr(j)+'-->'+

floattostr(yt[zat])) else Memo2.Lines.Add(''+inttostr(j)+'-->'+

floattostr(yt[zat])) end; t:= t0 + j*h; end;begin

series1.Clear; Memo1.Clear; memo2.Clear; Edit7.SetFocus; zat:= strtoint(edit7.Text); N:= strtoint(edit6.Text); t0:= 1; tf:= N; t := t0; y0[1]:= strtofloat(Edit1.Text); y0[2]:= strtofloat(Edit2.Text); y0[3]:= strtofloat(Edit3.Text); k1 := StrToFloat(Edit4.Text); k2 := StrToFloat(Edit5.Text);

230

y:= y0; h:= (tf-t0)/N; for j := 1 to N do Begin if radiobutton3.Checked = true thenEuler; if radiobutton4.Checked = true thenRungeKutta4; end; Edit7.SetFocus;end;procedure TForm1.SpeedButton7Click(Sender:TObject);begin

APPLICATION.Terminate;end;end.

procedure TForm1.Button1Click(Sender: TObject);begina:=strtoint(edit1.Text);b:=strtofloat(edit2.Text);ksp:=strtofloat(edit3.Text);x:=strtofloat(edit3.Text);ksp:=a*sqr(2*b);x:=exp(1/3*ln(ksp/4));edit3.Text:=floattostr(ksp);edit4.Text:=floattostr(x);end;

231

procedure TForm1.Button2Click(Sender: TObject);beginedit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';edit1.SetFocus; end;

procedure TForm1.Button3Click(Sender: TObject);beginapplication.terminateend;

232