You are on page 1of 20

LAPORAN PRAKTIKUM

STRUKTUR DATA

MODUL
ADT JAM & ADT POINT

Nama        : Mohamad Aditya Muttaqin Ghozali


NIM        : 3411201006
Kelas        : A

JURUSAN INFORMATIKA
FAKULTAS SAINS DAN INFORMATIKA
UNIVERSITAS JENDERAL AHMAD YANI
2021
DAFTAR ISI

BAB I.......................................................................................................................................3
HASIL PRAKTIKUM.............................................................................................................3
Sourcecode.h........................................................................................................................3
Sourcecode.c........................................................................................................................5
Main.c................................................................................................................................13
Screenshot hasil.................................................................................................................16
Analisa...............................................................................................................................17
BAB II...................................................................................................................................18
TUGAS..................................................................................................................................18
Sourcecode.h......................................................................................................................18
Sourcecode.c......................................................................................................................20
Main.c................................................................................................................................25
Screenshot Hasil.................................................................................................................27
Analisa...............................................................................................................................27
BAB III..................................................................................................................................28
KESIMPULAN......................................................................................................................28
BAB I

HASIL PRAKTIKUM
Sourcecode.h
#ifndef JAM_H
#define JAM_H
#include "boolean.h"
#define true 1
#define false 0
#define boolean unsigned char

typedef struct{
int Hour;
int Minute;
int Second;
}JAM;

void CreateJam (JAM *J, int HH, int MM, int SS);
//JAM CreateJam(int HH, int MM, int SS);

int GetHour(JAM J);


int GetMinute(JAM J);
int GetSecond(JAM J);
void SetHour(JAM *J,int newHour);
void SetMinute(JAM *J,int newMinute);
void SetSecond(JAM *J, int newSecond);
void ReadJam(JAM *J);
void PrintJam(JAM J);
boolean IsValid(int H, int M, int S);
boolean JEQ(JAM J1, JAM J2);
boolean JLT(JAM J1, JAM J2);
boolean JGT(JAM J1, JAM J2);
void Reset(JAM *J);
JAM NextDetik(JAM J);
JAM NextNDetik(JAM J, int N);
int Durasi(JAM Jaw, JAM JAkhr);
int JamToDetik(JAM J);
#endif

Sourcecode.c
#include <stdio.h>
#include <conio.h>
#include "jam.h"
void CreateJam (JAM *J, int HH, int MM, int SS){
SetHour(&(*J), HH);
SetMinute(&(*J), MM);
SetSecond(&(*J), SS);
}

int GetHour(JAM J){


return (J.Hour);
}
int GetMinute(JAM J){
return (J.Minute);
}
int GetSecond(JAM J){
return (J.Second);
}

void SetHour(JAM *J, int newHour){


(*J).Hour = newHour;
}
void SetMinute(JAM *J,int newMinute){
(*J).Minute= newMinute;
}
void SetSecond(JAM *J,int newSecond){
(*J).Second = newSecond;
}

void ReadJam(JAM *J){


//Kamus
int hh, mm,ss;
//Algoritma
do{

printf("Masukkan Jam = ");


scanf("%d",&hh);
printf("Masukkan Menit = ");
scanf("%d",&mm);
printf("Masukkan Detik = ");
scanf("%d",&ss);
}while(hh<0 || hh>24 || mm<0 || mm>60 || ss<0 || ss>60);
CreateJam(&(*J), hh, mm, ss);
}
void PrintJam(JAM J){
printf("%d:%d:%d", GetHour(J), GetMinute(J), GetSecond(J));
}

boolean IsValid(int H, int M, int S){


if(H>=0 && H<=23 && M>=0 && M<59 && S>=0 && S<59){
return (true);
}else{
return (false);
}
}

boolean JEQ(JAM J1, JAM J2){


if(GetHour(J1) == GetHour(J2) && GetMinute(J1) == GetMinute(J2)
&& GetSecond(J1) == GetSecond(J2)){
return(true);
}else{
return(false);
}
}

boolean JLT(JAM J1, JAM J2){


if(GetHour(J1) < GetHour(J2) || GetMinute(J1) < GetMinute(J2)
|| GetSecond(J1) < GetSecond(J2)){
return(true);
}else{
return(false);
}
}

boolean JGT(JAM J1, JAM J2){


if(GetHour(J1) > GetHour(J2) || GetMinute(J1) > GetMinute(J2)
|| GetSecond(J1) > GetSecond(J2)){
return(true);
}else{
return(false);
}
}

void Reset(JAM *J){


SetHour(&(*J),0);
SetMinute(&(*J),0);
SetSecond(&(*J),0);
}

JAM NextDetik(JAM J){


JAM JamBaru;
JamBaru =J;
SetSecond(&(JamBaru), GetSecond(J)+1 );
if (GetSecond(JamBaru)>59){
SetSecond(&JamBaru, 0);
SetMinute(&JamBaru, GetMinute(JamBaru)+1);
if(GetMinute(JamBaru)>59){
SetMinute(&JamBaru, 0);
SetHour(&JamBaru, GetHour(JamBaru)+1);
if(GetHour(JamBaru)>23){
SetHour(&JamBaru, 0);
}
}
}
return (JamBaru);
}

JAM NextNDetik(JAM J, int N){


int i;
JAM jamBaru;

jamBaru = J;
if(N> 0 && N <= 86400){
for(i=1; i<=N; i++){
jamBaru= NextDetik (jamBaru);
}
}
return (jamBaru);
}

int Durasi(JAM JAw, JAM JAkhr){


int detikAwl, detikAkh, result;

detikAwl = JamToDetik(JAw);
detikAkh = JamToDetik(JAkhr);
result= detikAwl - detikAkh;
if(result < 0){
result = result *(-1);
}
return (result);
}

int JamToDetik(JAM J){


int detik;

detik = (GetHour(J) * 3600) + (GetMinute(J) *60) + GetSecond(J);


return(detik);
}
Main.c
#include <stdio.h>
#include <conio.h>
#include "jam.h"

int main(){
//Kamus
JAM J1, J2, J3, J4;
int TambahanDetik;
int Konversi;

//Algoritma
ReadJam(&J1);
printf("Nilai J1 = ");
PrintJam(J1);
printf("\n");

J2= NextDetik(J1);
printf("Nilai J2 = ");PrintJam(J2);printf("\n");

printf("Masukkan nilai N detik (0...59) : ");


scanf("%d", &TambahanDetik);
J3 = NextNDetik(J1, TambahanDetik);
printf("Nilai J3 = ");PrintJam(J3);printf("\n");
J4=J1;
printf("Nilai J4 = ");PrintJam(J4);printf("\n");

printf("\nPengecekan Operator Relasional\n");


if(JEQ(J1,J2)){
printf("nilai J1 sama dengan J2\n");
}if(JLT(J1,J2)){
printf("nilai J1 lebih kecil dari J2\n");
}if(JGT(J1,J2)){
printf("nilai J1 lebih besar dari J2\n");
}

printf("\nPengecekan Operator Relasional\n");


if(JEQ(J3,J1)){
printf("nilai J3 sama dengan J1\n");
}if(JLT(J3,J1)){
printf("nilai J3 lebih kecil dari J1\n");
}if(JGT(J3,J1)){
printf("nilai J3 lebih besar dari J1\n");
}

printf("\nPengecekan Operator Relasional\n");


if(JEQ(J1,J4)){
printf("nilai J1 sama dengan J4\n");
}if(JLT(J1,J4)){
printf("nilai J1 lebih kecil dari J4\n");
}if(JGT(J1,J4)){
printf("nilai J1 lebih besar dari J4\n");
}

Reset(&J4);
printf("Nilai J4 = ");PrintJam(J4);printf("\n");
printf("\nDurasi Jam J1 dengan Jam J3 adalah %d detik\n",Durasi(J1,J3));
getch();
printf("\nKonversi jam J2 ke detik adalah %d detik",JamToDetik(J2));
return 0;
}

Screenshot hasil

Analisa
Project pertama membuat ADT jam dan di dalam project pertama terdapat main.c,
jam.c, jam.h, dan boolean.h yang merupakan bagian-bagian program dari project
ini. Isi dari main.c adalah remote dari program yang akan dijalankan, lalu pada
jam.h berisi header dari procedure dan function, kemudian di jam.c berisi perintah
dari header yang sudah ditulis di jam.h. Pada hasil program J1 akan lebih kecil dari
J2 dan J3, lalu saat memasukan perbandingan detik maka durasi dari J1 dengan J2
berbanding dengan data yang dimasukan. Saat J1 lebih kecil dari J2 dan J3 maka J4
akan memiliki jam yang sama dengan J1, kemudian J2 akan di konversikan
kedalam detik.

BAB II

TUGAS
Sourcecode.h
#ifndef _POINT_H
#define _POINT_H
#include "boolean.h"
#include <stdio.h>
#include <conio.h>
#define Absis(P) (P).X
#define Ordinat(P) (P).Y
#define PI 3.14159265

typedef struct {
int X;
int Y;
}POINT;

POINT CreatePOINT(int x, int y);


int GetAbsis(POINT P);
int GetOrdinat(POINT P);
void SetAbsis(POINT *P,int newX);
void SetOrdinat(POINT *P,int newY);
void BacaPOINT(POINT *P);
void CetakPOINT(POINT P);
boolean EQ(POINT P1, POINT P2);
boolean NEQ(POINT P1, POINT P2);
boolean LT(POINT P1, POINT P2);
boolean MT(POINT P1,POINT P2);
boolean IsOrigin(POINT P);
boolean IsOnSbx(POINT P);
boolean IsOnSby(POINT P);
int Kuadran(POINT P);
POINT MirrorOf(POINT P, boolean SBX, boolean SBY);
void GeserKeSbx(POINT *P);
void GeserKeSby(POINT *P);

#endif
Sourcecode.c
#include "boolean.h"
#include <stdio.h>
#include <conio.h>
#include "poin.h"
#define Absis(P) (P).X
#define Ordinat(P) (P).Y
#define PI 3.14159265

POINT CreatePOINT(int X, int Y){


POINT P;
P.X=X;
P.Y=Y;
return P;
}
int GetAbsis(POINT P){
return P.X;
}
int GetOrdinat(POINT P){
return P.Y;
}
void SetAbsis(POINT *P,int newX){
(*P).X = newX;
}
void SetOrdinat(POINT *P,int newY){
(*P).Y = newY;
}
void BacaPOINT(POINT *P){
int x,y;
scanf("%d %d",&x,&y);
(*P)=CreatePOINT(x,y);
}
void CetakPOINT(POINT P){
printf("(%d, %d)\n", P.X, P.Y);
}
boolean EQ(POINT P1, POINT P2){
if(P1.X==P2.X && P1.Y==P2.Y)
return (true);
else
return (false);
}
boolean NEQ(POINT P1, POINT P2){
if(P1.X!=P2.X || P1.Y!=P2.Y)
return (true);
else
return (false);
}
boolean LT(POINT P1, POINT P2){
if(P1.X < P2.X && P1.Y < P2.Y)
return (true);
else
return (false);
}
boolean MT(POINT P1, POINT P2){
if(P1.X > P2.X && P1.Y > P2.Y)
return (true);
else
return (false);
}
boolean IsOrigin(POINT P){
if(P.X==0 && P.Y==0)
return (true);
else
return (false);
}
boolean IsOnSbx(POINT P){
if(P.Y==0)
return (true);
else
return (false);
}
boolean IsOnSby(POINT P){
if(P.X==0)
return (true);
else
return (false);
}
int Kuadran(POINT P){
int X;
if(P.X > 0 && P.Y > 0)X=1;
else if(P.X >0 && P.Y < 0)X=2;
else if(P.X < 0 && P.Y < 0)X=3;
else if(P.X > 0 && P.Y < 0 )X=4;
return X;
}
POINT MirrorOf(POINT P, boolean SBX, boolean SBY){
POINT mirror;
mirror=P;
if(SBX && ! SBY){
mirror.Y=P.Y*-1;
return mirror;
}else if(! SBX && SBY){
mirror.X=P.X*-1;
return mirror;
}else if(SBX && SBY){
mirror=P;
return mirror;
}else{
mirror=P;
return mirror;
}
}
void GeserKeSbx(POINT *P){
(*P).Y=0;
}
void GeserKeSby(POINT *P){
(*P).X=0;
}

Main.c
#include "boolean.h"
#include <stdio.h>
#include <conio.h>
#include "poin.h"
#define Absis(P) (P).X
#define Ordinat(P) (P).Y
#define PI 3.14159265

int main (){


POINT P1,P2;

printf(">>Masukkan POIN ke 1:\n");BacaPOINT(&P1);


CetakPOINT(P1);
printf(">>Masukan POIN ke 2 :\n");BacaPOINT(&P2);
CetakPOINT(P2);

if(IsOrigin(P1)){
printf("Titik (%d,%d): Origin",GetAbsis(P1),GetOrdinat(P1));
}
else{
printf("Titik (%d,%d): Tidak Origin",GetAbsis(P1),GetOrdinat(P1));
}

if(EQ(P1,P2))
printf("\nP1 dan P2 sama");

if(NEQ(P1,P2))
printf("\nP1 dan P2 tidak sama");

if(LT(P1,P2))
printf("\nP1 lebih kecil dari P2");

if(MT(P1,P2))
printf("\nP1 lebih besar dari P2");

}
Screenshot Hasil

Analisa
Project ke dua ini membuat ADT Point dan sama seperti pada project pertama di
dalam project nya terdapat beberapa bagian seperti main.c, poin.c, poin.h, dan
boolean.h. Pada hasil program ini terdapat 2 buat poin yang dimana masing-masing
nya diisi oleh data yang kitu inputkan, setelah data telah di inputkan maka si
program akan menentukan apakah poin ke satu dan kedua ini origin atau tidak.
Kedua poin akan origin jika poin satu dan dua sama, tetapi jika poin satu dan dua
tidak sama maka akan dinyatakan tidak origin oleh si program tersebut, dan juga
jika poin ke satu memiliki nilai yang lebih kecil dari poin ke dua maka program
akan menginputkan bahwa p1 lebih kecil dari p2. Dan setelah di coba kembali
dengan memasukan angka 0 pada semua poin maka p1 dan p2 akan sama dan
menyatakan origin.
BAB III

KESIMPULAN
Pada modul pertama ini membuat program ADT jam dan ADT poin dengan
menggunakan file project yang dimana project ini memiliki bagian-bagiannya. Di
project ini juga menggunakan procedure dan function yang dimasukan ke dalam
bagian-bagian yang ada di project ini. Isi dari project ini seperti main.c yang berperan
seperti remote dari program yang kita buat, lalu ada jam.h atau poin.h yang
digunakan untuk menuliskan header-header yang akan digunakan dalam membuat
program, kemudian ada jam.c atau poin.c yang digunakan untuk membuat perintah
agar si remote tersebut bisa digunakan atau main.c bisa di jalankan.

You might also like