Senin, 07 Mei 2012

Tugas Struktur Data "Delphi7"

unit tugas1;

interface

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

type
  TForm1 = class(TForm)
    ForToDo: TButton;
    ForDowntoDo: TButton;
    WhileDo: TButton;
    RepeatUntil: TButton;
    bt_pangkat: TButton;
    btKeluar: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    bil: TLabel;
    Pangkat: TLabel;
    hasil: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Binput: TButton;
    procedure btKeluarClick(Sender: TObject);
    procedure ForToDoClick(Sender: TObject);
    procedure ForDowntoDoClick(Sender: TObject);
    procedure WhileDoClick(Sender: TObject);
    procedure RepeatUntilClick(Sender: TObject);
    procedure bt_pangkatClick(Sender: TObject);
    procedure BinputClick(Sender: TObject);
     private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btKeluarClick(Sender: TObject);
begin
close;
end;

procedure TForm1.ForToDoClick(Sender: TObject);
var
i,j:integer;b:string;
begin
b:='';j:=2;
for i:=1 to 10 do
begin
b:=b+inttostr(i)+'';
j:=j+2;
end;
label1.Caption:=b;
end;

procedure TForm1.ForDowntoDoClick(Sender: TObject);
var
i,j:integer;b:string;
begin
b:='';j:=2;
for i:=10 downto 1 do
begin
b:=b+inttostr(i)+'';
j:=j+2;
end;
label2.caption:=b;
end;

procedure TForm1.WhileDoClick(Sender: TObject);
var
i,j:integer;b:string;
begin
i:=1;
b:='';
while i<=10 do
begin
b:=b+inttostr(i)+'';
i:=i+1;
end;
label3.Caption:=b;
end;

procedure TForm1.RepeatUntilClick(Sender: TObject);
var
i,j:integer;b:string;
begin
i:=1;
b:='';
repeat
b:=b+inttostr(i)+'';
i:=i+1;
 until i>10;


   label4.caption:=b;
   end;
procedure TForm1.bt_pangkatClick(Sender: TObject);
var
bil,hasil,pangkat,a:integer;
begin
bil:=strtoint(edit1.Text);
hasil:=bil;
pangkat:=strtoint(edit2.Text);
if edit2.text='0'then edit3.Text:='1'else
if edit2.text='1'then edit3.Text:=edit1.text else
begin
for a:=2 to pangkat do
hasil:=hasil*bil;
edit3.Text:=inttostr(hasil);
end;
  end;


procedure TForm1.BinputClick(Sender: TObject);
begin
  edit1.Clear;
  edit2.Clear;
  edit3.clear;
  label1.Caption:='';
  label2.Caption:='';
  label3.Caption:='';
  label4.Caption:='';
end;
end.

IMAGE




Minggu, 25 Maret 2012

 Tugas Struktur Data 3

procedure faktorial(var f,jumlah:real);
var j:integer;
begin
jumlah:=1; j:=1;
while j<=f do
 begin jumlah:=jumlah*j;
       j:=j+1;
 end;
end;

begin
writeln('=======================');
writeln('    masukkan angka     ');
writeln('=======================');
writeln;
write('x=');readln(n);
write('y=');readln(r);
nr:=n-r;
faktorial(n,f1);
faktorial(nr,f2);
faktorial(r,f3);
f4:=f2*f3;
c:=f1/f4;
writeln;
writeln('hasil kombinasi =',c:4:0);
writeln('=======================');
end.

inilah hasil program di atas
 



Minggu, 11 Maret 2012

TUGAS STRUKTUR DATA 2

program pengembalian_uang_belanja;
uses wincrt;

var
   kode,nama,brg:string[50];
   hrg,jumlahbrg,uang,tot,byr: longint;
   barang:array[1..50]of integer;

begin
clrscr;
write('Nama Pembeli : ');readln(nama);
writeln;
writeln(' PEMBELIAN ');
writeln('  ----------------------------------');
write('  Kode Barang : ');readln(kode);
write('  Nama Barang : ');readln(brg);
write('  Harga Satuan Barang : ');readln(hrg);
write('  Jumlah : ');readln(jumlahbrg);
writeln;
tot:=hrg*jumlahbrg;

clrscr;
writeln('Balis dwi wahyudi');
writeln('111221098');
writeln;
writeln('Nama Pembeli : ',nama);
writeln('========================================================================');
write('| Kode barang | ');
write('Nama Barang | ');
write('satuan(Rp) | ' );
write('jumlah | ' );
write('harga n jumlah(Rp) |');
writeln;
writeln('========================================================================');
begin
writeln;
write('    ',kode,'      ');
write('   ',brg:10,'    ');
write(' ',hrg:10,'    ');
write('   ',jumlahbrg,'    ');
write(tot:10);
end;
writeln;
writeln('========================================================================');
  write('Uang Pembayaran : ');readln(byr);
  uang:=byr-tot;
  writeln;
  writeln('Uang Kembalian');
writeln('------------------------------------------------------------------------');

  if uang div 100000 > 0 then begin
    writeln(uang div 100000, ' lembar seratus ribuan');
    uang := uang mod 100000;
  end;

  if uang div 50000 > 0 then begin
    writeln(uang div 50000, ' lembar lima puluh ribuan');
    uang := uang mod 50000;
  end;

  if uang div 20000 > 0 then begin
    writeln(uang div 20000, ' lembar dua puluh ribuan');
    uang := uang mod 20000;
  end;

  if uang div 10000 > 0 then begin
    writeln(uang div 10000, ' lembar sepuluh ribuan');
    uang := uang mod 10000;
  end;

  if uang div 5000 > 0 then begin
    writeln(uang div 5000, ' lembar lima ribuan');
    uang := uang mod 5000;
  end;

  if uang div 1000 > 0 then begin
    writeln(uang div 1000, ' lembar ribuan');
    uang := uang mod 1000;
  end;

  if uang div 500 > 0 then begin
    writeln(uang div 500, ' lembar lima ratusan');
    uang := uang mod 500;
  end;

  if uang div 100 > 0 then begin
    writeln(uang div 100, ' ratusan');
    uang := uang mod 100;
  end;

  if uang div 50 > 0 then begin
    writeln(uang div 50, ' limapuluhan');
    uang := uang mod 50;
  end;

  if uang > 0 then begin
    writeln(uang, ' satuan');
  end;

  writeln('=======================================================================');

end.



inilah hasil program di atas

Minggu, 04 Maret 2012

TUGAS PERTAMA STRUKTUR DATA

Jawaban tugas struktur data no.1
 
program matriks_identitas;
uses WinCrt;
var
mat:array[1..5,1..5]of integer;
a,b:integer;
begin
writeln('matriks identitas : ');
writeln;
  for a:=1 to 5 do
  begin
    for b:=1 to 5 do
    begin
      mat[a,b]:=0;
      if a+b=6 then mat[a,b]:=1;
      write (mat[a,b]:3);
    end;
   writeln;
  end;
  writeln;
  writeln('sekian dan terima kasih');
end.

Inilah tampilan setelah program dijalankan.



Jawaban tugas struktur data no. 2

program perkalian_matriks;
uses wincrt;
var
   a,b,c : array [1..5,1..5] of integer;
   d,e,f,n,m,p : integer;
begin
     clrscr;
     writeln('NAMA : BALIS DWI WAHYUDI');
     writeln('NIM  : 111221098');
     writeln('=======================');
     writeln('matriks A');
     write('jumlah Baris : '); readln(n);
     write('jumlah Kolom : '); readln(m);
     writeln;
     writeln('matriks B');
     writeln('jumlah Baris : ',m);
     write('jumlah Kolom : '); readln(p);
     writeln('=======================');
     for d:=1 to n do
     for e:=1 to m do
     begin
          write('Elemen A[',d,',',e,'] : ');
          readln(a[d,e]);
     end;
     writeln;
     for d:=1 to m do
     for e:=1 to p do
     begin
          write('Elemen B[',d,',',e,'] : ');
          readln(b[d,e]);
     end;
     for d:=1 to n do
     for e:=1 to p do
     for f:=1 to m do
     c[d,e] := c[d,e] + a[d,f]*b[f,e];
     writeln('=======================');
     writeln('Hasil perkalian Matriks A dengan Matriks B : ');
     Writeln;
     for d:=1 to n do
     begin
          for e:=1 to p do
          write(c[d,e]:4);
     writeln;
     end;
     writeln('sekian dan terima kasih');
     readln;
end.

 Inilah tampilan setelah program dijalankan.