Selasa, 31 Maret 2015

PROGRAM SORTING DENGAN MENGGUNAKAN BAHASA PASCAL (Descending)


Source Code
uses crt;

type data= record
nama, nim: string;
ipk : real;
end;

var
mhs : array [1..10] of data;
i, j, n, temp : integer;
pilih : char;

procedure input;
begin
clrscr;
write('Masukkan Jumlah Mahasiswa : '); readln(n);
for i := 1 to n do

begin
clrscr;
writeln('Masukkan Data ke- ', i);
writeln('=====================');
write ('Nama  : '); readln(mhs[i].nama);
write ('NIM   : '); readln(mhs[i].nim);
write ('IPK   : '); readln(mhs[i].ipk);
end;
end;

procedure hasil;
begin
clrscr;
writeln('=========');
writeln('= HASIL =');
writeln('=========');
for i:=1 to n do

begin
writeln;
writeln('Hasil Data Ke-',i);
writeln('NIM  : ',mhs[i].nim);
writeln('NAMA : ',mhs[i].nama);
writeln('IPK  : ',mhs[i].ipk:2:2);
end;

readkey;
end;

procedure seleksi;
var max: integer;
temp: data;

begin
for i:=1 to n-1 do

begin
max:=i;
for j:= i+1 to n do
if mhs[j].ipk> mhs[max].ipk then

max:=j;

temp:= mhs[max];
mhs[max]:= mhs[i];
mhs[i]:= temp;
end;
hasil;
end;

begin
input;
seleksi;
end.

 


Minggu, 22 Maret 2015

PROGRAM MENGHITUNG LUAS DAN VOLUME KUBUS DENGAN MENGGUNAKAN BAHASA PASCAL


Source Code


uses crt;

function kali(a,b:integer):longint;
begin
if b>1 then
begin

kali:= kali(a,b-1)+a;

end else
kali:=a;
end;

procedure  LP_kubus;
var r,b:integer;
    l:longint;
    v:longint;
begin clrscr;
      write('Sisi : '); readln(r);

      l:=6*r*r ;
      v:=r*r*r ;

      writeln;
      writeln('Luas      : ',l); readln;
      writeln('Volume    : ',v); readln;
end;

var pilih : char;
begin
repeat
clrscr;
writeln('============================');
writeln('= PROGRAM MENGHITUNG KUBUS =');
writeln('============================');
writeln(' [1] Luas dan Volume Kubus');
writeln(' [2] Keluar');
writeln;
write(' Pilih  : '); pilih:=readkey;

case pilih of
'1' : LP_kubus;
'2' : exit;

end;
until pilih = '3';
end.

Sabtu, 14 Maret 2015

MEMBUAT PROGRAM DENGAN MENGGUNAKAN BAHASA PASCAL (Matrik Dua Dimensi dan Record)


Source Code
 

Program Biodata_Mahasiswa;
 uses crt;
 Type Rec  = Record
      Nama : String;
      NIM  : String;
      Tl   : string;
      Umur : Longint;
 end;
 var Data  : array[1..50] of Rec;
     n,i   : integer;
     pilih  : string;

 Procedure Input;
 Begin
  clrscr;
  n:=0;
  repeat
  clrscr;
  inc(n);
  writeln('|===================================|');
  writeln('|         BIODATA MAHASISWA         |');
  writeln('|===================================|');
  writeln('| Data ke-',n,'                         |');
  writeln('|===================================|');
  with Data[n] do
  begin
  writeln('|===================================|');
  writeln('| Nama          :                   |');
  writeln('| NIM           :                   |');
  writeln('| Tanggal Lahir :                   |');
  writeln('| Umur          :           Tahun   |');
  writeln('|===================================|');
  gotoxy(19,7);readln(Nama);
  gotoxy(19,8);readln(NIM);
  gotoxy(19,9);readln(Tl);
  gotoxy(19,10);readln(Umur);
  end;
  writeln;
  write('Input Data Lagi? [Y/N] : ');readln(Pilih);
  Until ((Pilih='n') or (Pilih='N'));
 end;



 Procedure Output;
 Begin
 clrscr;
 writeln('|==================================================================|');
 writeln('|                           BIODATA MAHASISWA                      |');
 writeln('|================================================|=================|');
 writeln('|          Nama         |    NIM    |    Umur    |  Tanggal Lahir  |');
 writeln('|=======================|===========|============|=================|');

 for i:=1 to n do
  begin
  writeln('|                       |           |            |                 |');
   with Data[i] do
    begin
     gotoxy(3,5+i);writeln(Nama);
     gotoxy(27,5+i);writeln(NIM);
     gotoxy(43,5+i);writeln(Umur);
     gotoxy(52,5+i);writeln(tl);
    end;
  end;
  writeln('|==================================================================|');
 readkey;
end;

Begin
repeat
clrscr;
  writeln('|======================|');
  writeln('|      Menu Utama      |');
  writeln('|  1. Masukkan Data    |');
  writeln('|  2. Lihat Data       |');
  writeln('|  3. Keluar           |');
  writeln('|======================|');
  writeln('|                      |');
  writeln('| Masukkan Pilihan :   |');
  writeln('|======================|');
  gotoxy(22,8);readln(Pilih);
  case Pilih of
  '1' : Input;
  '2' : Output;
  '3' : Exit;
  else write('Input salah, input ulang!');
  end;
Until (Pilih)='3';
end.




Tampilan ketika program dijalankan: