ADT garis

Posted: September 4, 2010 in Kuliah
  • adtline.h

#ifndef ADTLINE_H
#define ADTLINE_H

typedef struct {
int w,x,y,z;
}garis;
typedef struct{
int a,b,c;
}pers;
garis createline(int x1,int y1,int x2,int y2);
/*
I.S : titik-titik yang membentuk garis bertipe integer
F.S : dikembalikan satu buah fungsi garis dengan x1=w, y1=x, x2=y, y2=z.
*/
pers persgaris(int x1,int y1,int x2,int y2);
/*
I.S : titik-titik yang membentuk garis bertipe integer
F.S : dikembalikan nilai x bertipe pers dengan (x.a = x2 – x1), (x.b = y2 – y1), (x.c = (y1*x.a)+(x1*x.b)).
*/

float gradien(pers x);
/*
I.S : nilai x bertipe pers
F.S : dikembalikan nilai bertipe integer dengan nilai x.b/(-x.a)
*/

int printpoint(pers P);
/*
I.S : P adalah variabel point yang sudah terdefinisi nilai
F.S : dikembalikan dicetak nilai w,x,y,z di media output
*/

#endif

____________________________________________________________

  • adtline.cpp

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

garis createline(int x1, int y1,int x2,int y2)
{
garis temp;
temp.w = x1;
temp.x = y1;
temp.y = x2;
temp.z = y2;
return temp;
}
pers persgaris(int x1,int y1,int x2,int y2)
{
pers x;
x.a = x2 – x1;
x.b = y2 – y1;
x.c = (y1*x.a)-(x1*x.b);
return x;

}

float gradien(pers x)
{
float gra;
gra=x.a/x.b;
return gra;
}

int printpoint(pers P)
{
// writeln(P.x, P.y)
printf(“Persamaan garis : %dX+(%dY)+(%d)=0 \n\n”,P.b,-P.a,P.c);
return 0;
}

____________________________________________________________

  • garis.cpp

#include <stdio.h>
#include <ios>
#include “adtline.h”

int main()
{
garis var1;
pers var2;
var1 = createline(1,2,3,4);
printf(“garis melewati titik (%d,%d) dan (%d,%d)\n”,var1.w,var1.x,var1.y,var1.z);
var2 = persgaris(var1.w,var1.x,var1.y,var1.z);
printpoint(var2);
printf(“Gradien(m) = %f \n”,gradien(var2));
system(“pause”);
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