#include <iostream.h>
#include <conio.h>
class CRectangle
{
int *width, *height;
public:
CRectangle (int,int);
~CRectangle();
int area()
{
return (*width* *height);
}
};
CRectangle::CRectangle (int a, int b)
{
width = new int;
height = new int;
*width = a;
*height = b;
}
CRectangle::~CRectangle()
{
delete width;
delete height;
}
int main()
{
CRectangle rect (3,4),rectb (5,6);
cout << "rect area : " << rect.area() << endl;
cout << "rect area : " << rectb.area() << endl;
getch();
}
berikut adalah hasilnya:

No comments:
Write comments