ADT point

Posted: September 4, 2010 in Kuliah

ADTPoint.h

#ifndef ADTPOINT_H
#define ADTPOINT_H

typedef struct {
int x, y;
} point;

/* konstruktor */
point createPoint(int inX, int inY);
/*
I.S: inX dan inY bernilai integer
F.S: dikembalikan satu buah nilai point x = inX, y = inY.
*/

/* selektor */
point replacePoint(int newX,int newY);
/*
I.S: P terdefinisi, newX dan newY bernilai integer
F.S: absis dan ordinat dari P berganti nilai dari newX dan newY
*/

/* operasi translasi */
point translasiPoint(int deltaX, int deltaY);
/*
I.S: P terdefinisi
F.S: absis telah bergeser sebesar deltaX, ordinat telah bergeser sebesar deltaY
*/

/* interface */
int printPoint(point P);
/*
I.S: P adalah variabel point yang sudah terdefinisi nilai
F.S: dikembalikan akan dicetak di media output nilai P.
*/

#endif

—————————————————————————–

ADTPoint.cpp

#include <stdio.h>
#include “ADTPoint.h”

point createPoint(int inX, int inY)
{
point temp;
temp.x =inX;
temp.y =inY;

return temp;
}

point replacePoint(int newX, int newY)
{
point P;
P.x = newX;
P.y = newY;
return P;
}

point translasiPoint(int deltaX,int deltaY)
{
point temp;
temp.x = temp.x+deltaX;
temp.y = temp.y+deltaY;

return temp;
}

int printPoint(point P)
{
//writeln(p.x,p.y)
printf(“Nilai  x : %d, nilai y : %d”, P.x, P.y);
return 0;
}

———————————————————

main.cpp

#include <stdio.h>
#include <iostream>
#include “ADTPoint.h”

using namespace std;

int main()
{
point varP;

varP = createPoint(145,100);
cout << “Nilai Point awal..\n”;
printPoint(varP);

varP = replacePoint(175, 200);
cout << “\n”;
cout << “Nilai Point diganti menjadi..\n”;
printPoint(varP);

varP = translasiPoint(15,65);
cout << “\n”;
cout << “Nilai Point setelah ditranslasikan..\n”;
printPoint(varP);

return 0;
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s