954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Rect class

/*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
Junior Poster in Training
60 posts since Feb 2011
Reputation Points: -14
Solved Threads: 1
 

What do you need help with? We can't help you if you can't tell us.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You