-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkehilangan_handler.pas
More file actions
98 lines (87 loc) · 3 KB
/
Copy pathkehilangan_handler.pas
File metadata and controls
98 lines (87 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
unit kehilangan_handler;
interface
uses
tipe_data;
{ KONSTANTA }
const
nmax = 1000; // Asumsi bahwa size terbesar dari database adalah 1000
{ DEKLARASI TIPE }
type
kehilangan = record
Username, ID_Buku, Tanggal_Laporan: string;
end;
tabel_kehilangan = record
t: array [0..nmax] of kehilangan;
sz: integer; // effective size
end;
{ DEKLARASI FUNGSI DAN PROSEDUR }
function tambah(s: arr_str): tabel_kehilangan;
procedure output(data_tempkehilangan: tabel_kehilangan);
function konversi_csv(data_tempkehilangan: tabel_kehilangan): arr_str;
{ IMPLEMENTASI FUNGSI DAN PROSEDUR }
implementation
function tambah(s: arr_str): tabel_kehilangan;
{ DESKRIPSI : Memasukkan data dari array of string kedalam tabel_kehilangan }
{ PARAMETER : array of string }
{ RETURN : data kehilangan }
var
col, row: integer; // col = data ke-N, row = baris ke-N dari file csv
temp: string; // string temporer, berfungsi
c: char;
data_tempkehilangan : tabel_kehilangan;
begin
data_tempkehilangan.sz := 0;
for row:=0 to s.sz-1 do
begin
col := 0;
temp := '';
for c in s.st[row] do
begin
if(c=',') then
begin
// 0 based indexing
case col of
0: data_tempkehilangan.t[data_tempkehilangan.sz].Username := temp;
1: data_tempkehilangan.t[data_tempkehilangan.sz].ID_Buku := temp;
end;
col := col+1;
temp := '';
end else temp := temp+c;
end;
data_tempkehilangan.t[data_tempkehilangan.sz].Tanggal_Laporan := temp;
data_tempkehilangan.sz := data_tempkehilangan.sz+1;
end;
tambah := data_tempkehilangan;
end;
function konversi_csv(data_tempkehilangan: tabel_kehilangan): arr_str;
{ DESKRIPSI : Fungsi untuk mengubah data kehilangan menjadi array of string }
{ PARAMETER : data kehilangan }
{ RETURN : array of string }
{ KAMUS LOKAL }
var
i : integer;
ret : arr_str;
begin
ret.sz := data_tempkehilangan.sz;
for i:=0 to data_tempkehilangan.sz do
begin
ret.st[i] := data_tempkehilangan.t[i].Username + ',' +
data_tempkehilangan.t[i].ID_Buku + ',' +
data_tempkehilangan.t[i].Tanggal_Laporan;
end;
konversi_csv := ret;
end;
procedure output(data_tempkehilangan: tabel_kehilangan);
{ DESKRIPSI : Prosedur sederhana yang digunakan pada proses pembuatan program untuk debugging, prosedur ini mencetak data ke layar }
{ PARAMETER : Data yang akan dicetak }
{ KAMUS LOKAL }
var
i: integer;
{ ALGORITMA }
begin
for i:=0 to data_tempkehilangan.sz-1 do
begin
writeln(data_tempkehilangan.t[i].Username, ' | ', data_tempkehilangan.t[i].ID_Buku, ' | ', data_tempkehilangan.t[i].Tanggal_Laporan);
end;
end;
end.