Implementasi OOP dalam Bahasa C++ untuk Titik
File titik.cpp:
#include <stdio.h>
class titik
{
private:
int x;
int y;
public:
titik()
{
x = 0;
y = 0;
}
titik(int xp,int yp)
{
x = xp;
y = yp;
}
void setx(int xp)
{
x = xp;
}
int getx()
{
return x;
}
void sety(int yp)
{
y = yp;
}
int gety()
{
return y;
}
~titik()
{
}
};
File Main:
#include <iostream>
#include "titik.cpp"
int main()
{
titik t1;
titik t2(11,9);
t1.setx(18);
t1.sety(28);
std::cout<<"t1 : nilai x:"<<t1.getx()<<"\n";
std::cout<<"t1 : nilai y:"<<t1.gety()<<"\n";
std::cout<<"t2 : nilai x:"<<t2.getx()<<"\n";
std::cout<<"t2 : nilai y:"<<t2.gety()<<"\n";
return 0;
}
Komentar
Posting Komentar