/*write a program class Rectangle . the class will have two data member to coodinates of upper left & lower
reght corner of rectangle. these two data member will be object of point class.
1-The rectangle class should following function.
2-A default destructor to print a messagewheneveran objectis distroyed
3-a get function for each data member.
4-a set function for each data member
5-a function to compute the area of rectangle
6-a function to compute parimeter of rectangle
7-a print function to print all the data with appropriate lables
write a driver program to test the functionality of rectangle class
plz plz help.*/
#include<iostream.h>
#include<stdlib.h>
class point
{
public :
int x,y;
public :
point()
{
x=0;y=0;
}
point(int a ,int b)
{
x=a;y=b;
}
void print()
{
cout<<"("<<x<<","<<y<<")";
}
};
class rectangle
{
private:
point p1,p2;
rectangle()
{
p1.x=0;p2.x=0;
p1.y=0;p2.y=0;
}
rectangle(point a,point b)
{
p1.x=a.x;p2.x=b.x;
p1.y=a.y;p2.y=b.y;
}
int calArea()
{
int i,j;
i=p1.x-p2.x;
j=p1.y-p2.y;
i=abs(i);
j=abs(j);
return (i*j);
}
int calPeri()
{
int i,j,peri;
i=p1.x-p2.x;
j=p1.y-p2.y;
i=abs(i);
j=abs(j);
peri=2(i+j);
return peri;
}
void print()
{
cout<<"("<<p1.x<<","<<p1.y<<")"<<endl;
cout<<"("<<p2.x<<","<<p2.y<<")";
cout<<"Area is "<<calArea()<<"perimeter is <<"<<calPeri();
}
};
void main()
{
rectangle r;
point p1(2,3),p2(4,5);
r.rectangle(p1,p2);
r.print();
}
HASHMI007
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.