#include <iostream> |
using namespace std; |
class Point |
{ |
public : |
int x,y; |
Point ( int a, int b) |
{ |
x=a; |
y=b; |
cout<< "A point (" <<x<< ", " <<y<< ") is created!" <<endl; |
} |
Point ( const Point &p) |
{ |
x=p.x; |
y=p.y; |
cout<< "A point (" <<x<< ", " <<y<< ") is copied!" <<endl; |
} |
~Point () |
{ |
cout<< "A point (" <<x<< ", " <<y<< ") is erased!" <<endl; |
} |
int getX() |
{ |
return x; |
} |
int getY() |
{ |
return y; |
} |
}; |
class Rectangle |
{ |
private : |
Point leftTop,rightBottom; |
public : |
Rectangle( int a, int b, int c, int d):leftTop(a,b),rightBottom(c,d) |
{ |
cout<< "A rectangle (" <<a<< ", " <<b<< ") to (" <<c<< ", " <<d<< ") is created!" <<endl; |
} |
~Rectangle() |
{ |
cout<< "A rectangle (" <<leftTop.getX()<< ", " <<leftTop.getY()<< ") to (" <<rightBottom.getX()<< ", " <<rightBottom.getY()<< ") is erased!" <<endl; |
} |
Point &getLeftTop() |
{ |
return leftTop; |
} |
Point getRightBottome() |
{ |
return rightBottom; |
} |
int getArea() |
{ |
int a,b,c,d; |
a=leftTop.x; |
b=leftTop.y; |
c=rightBottom.x; |
d=rightBottom.y; |
return (c-a)*(b-d); |
} |
}; |
int main() |
{ |
int cases; |
int x1, y1, x2, y2; |
cin>>cases; |
for ( int i = 0; i < cases; i++) |
{ |
cin>>x1>>y1>>x2>>y2; |
Rectangle rect(x1,y1,x2,y2); |
cout<< "Area: " <<rect.getArea()<<endl; |
cout<< "Left top is (" <<rect.getLeftTop().getX()<< ", " <<rect.getLeftTop().getY()<< ")" <<endl; |
cout<< "Right bottom is (" <<rect.getRightBottome().getX()<< ", " <<rect.getRightBottome().getY()<< ")" <<endl; |
} |
return 0; |
} |
by: 发表于:2017-09-01 09:54:04 顶(0) | 踩(0) 回复
??
回复评论