Code:
#include <iostream>
class Point //holds x, y coordinates
{
//no constructor, use default
public:
void SetX(int x){itsX =x;}
void SetY(int y){itsY =y;}
int GetX() const {return itsX;}
int GetY()const {return itsY;
private:
int itsX;
int itsY;
};//end of point class declaration
class Rectangle
{
public:
Rectangle (int top, int left, int bottom, int right);
~Rectangle(){}
int GetTop()const {return itsTop;{
int GetLeft()const {return itsLeft;}
int GetBottom()const{return itsBottom;}
int getRight() const {return itsRight;}
Point GetUpperLeft() const {return itsUpperLeft;}
Point GetLowerLeft() const {return itsLowerLeft;}
Point GetUpperRight() const {return itsUpperRight;}
Point GetLowerRight() const {return itsLowerRight;}
void SetUpperLeft(Point Location) {itsUpperLeft = Location;}
void SetLowerLeft(Point Location) {itsLowerLeft = Location;}
void SetUpperRight(Point Location) {itsUpperRight = Location;}
void SetLowerRight(Point Location) {itsLowerRight = Location;}
void SetTop(int top) { itsTop =top;}
void SetLeft(int left) {itsLeft =left;}
void SetBottom (int bottom) { itsBottom = bottom;}
void SetRight (int right) {itsRight = right;}
int GetArea() const;
private:
Point itsUpperLeft;
Point itsUpperRight;
Point itsLowerLeft;
Point itsLowerRight;
int itsTop;
int itsLeft;
int itsBottom;
int itsRight;
};
//end rect.hpp
rect.cpp
Code:
#include "Rect.hpp"
Rectangle::Rectangle(int top, int left, int bottom, int right)
{
itsTop =top;
itsLeft = left;
itsBottom = bottom;
itsRight = right;
itsUpperLeft.SetX(left);
itsUpperLeft.SetY(top);
itsUpperRight.SetX(right);
itsUpperRight.SetY(top);
itsLowerLeft.SetX(left);
itsLowerleft.SetY(bottom);
}
//compute area of the rectangle by finding cornersides,
//establish width and height and then multiply
int Rectangle::GetArea() const
{
int Width = itsRight - itsLeft;
int Height = itsTop - itsBottom;
return(Width * Height);
}
int main()
{
//intitialize a local Rectangle variable
Rectangle MyRectangle (100,20,50,80);
int Area = MyRectangle.GetArea();
std::cout <<"Area: "<<Area <<"\n";
std::cout <<"Upper Left X coordinate: ";
std::cout <<MyRectangle.GetUpperLeft().GetX();
return 0;
}