Advertisement
rikokurniawan

Contoh Latihan Delphi pilihan if, else if, dan else

Nov 29th, 2012
1,374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.64 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Label1: TLabel;
  12.     Label2: TLabel;
  13.     Label3: TLabel;
  14.     Label4: TLabel;
  15.     Label5: TLabel;
  16.     Label6: TLabel;
  17.     Label7: TLabel;
  18.     Label8: TLabel;
  19.     Edit1: TEdit;
  20.     Edit2: TEdit;
  21.     Edit3: TEdit;
  22.     Edit4: TEdit;
  23.     Edit5: TEdit;
  24.     Edit6: TEdit;
  25.     Edit7: TEdit;
  26.     Edit8: TEdit;
  27.     Button1: TButton;
  28.     Button2: TButton;
  29.     Button3: TButton;
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure Button1Click(Sender: TObject);
  32.     procedure Button2Click(Sender: TObject);
  33.     procedure Button3Click(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.   public
  37.     { Public declarations }
  38.     procedure bersih;  //inisialisasi pembuatan prosedur bersih
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.  
  44. implementation
  45.  
  46. {$R *.dfm}
  47. procedure TForm1.bersih;  //awal pembuatan prosedur bersih
  48. begin
  49.   Edit1.Clear;
  50.   Edit2.Clear;
  51.   Edit3.Clear;
  52.   Edit4.Clear;
  53.   Edit5.Clear;
  54.   Edit6.Clear;
  55.   Edit7.Clear;
  56.   Edit8.Clear;
  57. end;   //akhir pembuatan prosedur bersih
  58.  
  59. procedure TForm1.Button1Click(Sender: TObject);
  60. var nt,nq,nm,nu,na:Real;
  61. begin
  62. if Edit1.Text='' then begin
  63.   Application.MessageBox('Inputkan Nilainya Terlebih dahulu' +#13+'Good Luck Coy!!'+#13+'Di Halaman http://delphianimelover.blogspot.com','Heng !',MB_ICONWARNING);
  64.   Edit1.SetFocus;
  65.   Exit;
  66. end
  67. else if Edit2.Text='' then Begin
  68.   Application.MessageBox('Inputkan Nilainya Terlebih dahulu' +#13+'Good Luck Coy!!'+#13+'Di Halaman http://delphianimelover.blogspot.com','Heng !',MB_ICONWARNING);
  69.   Edit2.SetFocus;
  70.   Exit;
  71. end
  72. else if Edit3.Text=''  then Begin
  73.   Application.MessageBox('Inputkan Nilainya Terlebih dahulu' +#13+'Good Luck Coy!!'+#13+'Di Halaman http://delphianimelover.blogspot.com','Heng !',MB_ICONWARNING);
  74.   Edit3.SetFocus;
  75.   Exit;
  76. end
  77. else if Edit4.Text='' then begin
  78.   Application.MessageBox('Inputkan Nilainya Terlebih dahulu' +#13+'Good Luck Coy!!'+#13+'Di Halaman http://delphianimelover.blogspot.com','Heng !',MB_ICONWARNING);
  79.   Edit4.SetFocus;
  80.   Exit;
  81. end;
  82.   nt:=StrtoFloat(Edit1.Text);
  83.   nq:=StrtoFloat(Edit2.Text);
  84.   nm:=StrtoFloat(Edit3.Text);
  85.   nu:=StrtoFloat(Edit4.Text);
  86.   na:=(nt*0.1) + (nq*0.1) + (nm*0.4) + (nu*0.4);
  87.   Edit5.Text:=FloatToStr(na);
  88.  
  89.   if (Edit5.Text<='100') and (Edit5.Text>='81') then begin
  90.     Edit6.Text:='A';
  91.     Edit7.Text:='4';
  92.     Edit8.Text:='Excelent';
  93.   end
  94.   else if (Edit5.Text<='80') and (Edit5.Text>='66') then begin
  95.     Edit6.Text:='B';
  96.     Edit7.Text:='3';
  97.     Edit8.Text:='Baik';
  98.   end
  99.   else if (Edit5.Text<='65') and (Edit5.Text>='56') then begin
  100.     Edit6.Text:='C';
  101.     Edit7.Text:='2';
  102.     Edit8.Text:='Cukup';
  103.   end
  104.   else if (Edit5.Text<='55') and (Edit5.Text>='41') then begin
  105.     Edit6.Text:='D';
  106.     Edit7.Text:='1';
  107.     Edit8.Text:='Kurang';
  108.   end
  109.   else if (Edit5.Text<='10') and (Edit5.Text>='0') then begin
  110.     Edit6.Text:='E';
  111.     Edit7.Text:='0';
  112.     Edit8.Text:='Gagal';
  113.   end;
  114. end;
  115. procedure TForm1.Button2Click(Sender: TObject);
  116. begin
  117.   Bersih;  //prosedur bersih dipanggil
  118. end;
  119.  
  120. procedure TForm1.Button3Click(Sender: TObject);
  121. begin
  122. Self.Close;
  123. end;
  124.  
  125. procedure TForm1.FormCreate(Sender: TObject);
  126. begin
  127.   bersih;
  128.   Label1.Caption:='Nilai Tugas';
  129.   Label2.Caption:='Nilai Quiz';
  130.   Label3.Caption:='Nilai MID';
  131.   Label4.Caption:='Nilai UAS';
  132.   Label5.Caption:='Nilai Angka';
  133.   Label6.Caption:='Nilai Huruf';
  134.   Label7.Caption:='Nilai Mutu';
  135.   Label8.Caption:='Nilai Keterangan';
  136.   Button1.Caption:='Hitung';
  137.   Button2.Caption:='Clear';
  138.   Button3.Caption:='Exit';
  139. end;
  140. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement