*Header
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
typedef struct
{
int x; /* absis */
int y; /* ordinat */
} point;
point makepoint(int x,int y);
void bacapoint(point *p);
int getabsis (point p);
int getordinat(point p);
void tulispoint(point p);
#endif // HEADER_H_INCLUDED
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
typedef struct
{
int x; /* absis */
int y; /* ordinat */
} point;
point makepoint(int x,int y);
void bacapoint(point *p);
int getabsis (point p);
int getordinat(point p);
void tulispoint(point p);
#endif // HEADER_H_INCLUDED
*C++ source
#include <iostream>
#include <stdio.h>
#include "Header.H"
point makepoint( int x, int y)
{
point temp;
temp.x = x;
temp.y = y;
return temp;
}
void bacapoint(point *p)
{
//membaca nilai x dan y dari keyboard
int x,y;
printf("Masukkan nilai X : ");
scanf("%d", &x);
printf("Masukkan nilai Y : ");
scanf("%d", &y);
*p = makepoint(x,y);
}
int getabsis(point p)
{
return p.x;
}
int getordinat(point p)
{
return p.y;
}
void tulispoint(point p)
{
printf("P(%d,%d)",p.x,p.y);
}
* Main
#include <iostream>
#include "Header.h"
using namespace std;
int main()
{
int x,y;
point P;
bacapoint(&P);
tulispoint(P);
cout<<"\n";
cout<<"Nilai absis \t :"<< getabsis(P)<<"\n";
cout<<"Nilai ordinat \t :"<<getordinat(P);
}
No comments