Program tugas4pascal;
Uses CRT;
Type
dealer = Record
Nama : String[12];
Merk : String[8];
Jenis : String[10];
Harga : LongInt;
Bayar : String[6];
Diskon : LongInt;
Total : LongInt;
End;
data = Array [1..100] Of dealer;
Const
Maks = 100;
Var
motor : data;
Pilih : Char;
jml : Byte;
GTotal : LongInt;
Function UpCaseStr(S : String): String;
Var
I : Byte;
Begin
For I := 1 to Length(S) do
If (S[I] >= 'a') And (S[I] <= 'z') Then
Dec(S[I], 32);
UpCaseStr := S;
End;
Function urutdata(Var Brg : data; B : Byte) : Byte;
Var
I, J : Byte;
BTemp : dealer;
Begin
For I := 1 To B Do Begin
For J := (I + 1) To B Do Begin
If (Brg[J].Merk < Brg[I].Merk) Then Begin
BTemp := Brg[I];
Brg[I] := Brg[J];
Brg[J] := BTemp;
End;
End;
End;
urutdata := B;
End;
Function InputData(I : Byte) : Char;
Var
Lagi : Char;
Begin
WriteLn;
Write('Nama Pembeli : '); ReadLn(motor[I].Nama);
WriteLn('Data Motor');
Write('- Merk Motor : '); ReadLn(motor[I].Merk);
Write('- Jenis Motor : '); ReadLn(motor[I].Jenis);
Write('- Harga Motor : Rp. '); ReadLn(motor[I].Harga);
Repeat
Write('Jenis Bayar [Tunai/Kredit] : ');
ReadLn(motor[I].Bayar);
motor[I].Bayar := UpCaseStr(motor[I].Bayar);
Until (motor[I].Bayar = 'TUNAI') Or (motor[I].Bayar = 'KREDIT');
motor[I].Merk := UpCaseStr(motor[I].Merk);
If (motor[I].Merk = 'HONDA') And (motor[I].Bayar = 'KREDIT') Then
motor[I].Diskon := (motor[I].Harga * 5) div 100;
If (motor[I].Merk = 'YAMAHA') And (motor[I].Bayar = 'KREDIT') Then
motor[I].Diskon := (motor[I].Harga * 7) div 100;
If (motor[I].Merk = 'KAWASAKI') And (motor[I].Bayar = 'KREDIT') Then
motor[I].Diskon := (motor[I].Harga * 6) div 100;
If (motor[I].Bayar = 'TUNAI') Then
motor[I].Diskon := (motor[I].Harga * 20) div 100;
If (motor[I].Merk <> 'HONDA') And (motor[I].Merk <> 'YAMAHA') And
(motor[I].Merk <> 'KAWASAKI') Then Begin
motor[I].Harga := 0;
motor[I].Diskon := 0;
End;
motor[I].Total := motor[I].Harga - motor[I].Diskon;
Repeat
WriteLn;
Write('Masukan data lagi [Y/T] : ');
ReadLn(Lagi);
Lagi := UpCase(Lagi)
Until (UpCase(Lagi) = 'Y') Or (UpCase(Lagi) = 'T');
InputData := Lagi;
End;
Function CetakData(B : Byte) : LongInt;
Var
I : Byte;
GT : LongInt;
Begin
WriteLn;
WriteLn('NO. NAMA PEMBELI MERK HARGA JENIS BAYAR DISKON JML. BAYAR');
WriteLn('-------------------------------------------------------------------------------');
For I := 1 To B Do Begin
GT := GT + motor[I].Total;
Write(I:3,' ');
Write(motor[I].Nama:12, ' ');
Write(motor[I].Merk:8, ' ');
Write(motor[I].Harga:10);
Write(motor[I].Bayar:11);
Write(motor[I].Diskon:15);
WriteLn(motor[I].Total:14);
End;
WriteLn('-------------------------------------------------------------------------------');
CetakData := GT;
End;
(* Program Utama *)
Begin
ClrScr;
WriteLn('DEALER MOTOR "JAYA"');
WriteLn('-------------------');
While (jml <= Maks) And (Pilih <> 'T') Do Begin
Inc(jml);
Pilih := InputData(jml);
End;
jml := urutdata(motor, jml);
GTotal := CetakData(jml);
ReadLn;
End.


