⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rect.cpp

📁 《24学时精通c++》的光盘内容
💻 CPP
字号:
// Begin rect.cpp
#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);

    itsLowerRight.SetX(right);
    itsLowerRight.SetY(bottom);
}

void Rectangle::SetUpperLeft(Point Location)
{
    itsUpperLeft = Location;
    itsUpperRight.SetY(Location.GetY());
    itsLowerLeft.SetX(Location.GetX());
    itsTop = Location.GetY();
    itsLeft = Location.GetX();
}

void Rectangle::SetLowerLeft(Point Location)
{
    itsLowerLeft = Location;
    itsLowerRight.SetY(Location.GetY());
    itsUpperLeft.SetX(Location.GetX());
    itsBottom = Location.GetY();
    itsLeft = Location.GetX();
}

void Rectangle::SetLowerRight(Point Location)
{
    itsLowerRight = Location;
    itsLowerLeft.SetY(Location.GetY());
    itsUpperRight.SetX(Location.GetX());
    itsBottom = Location.GetY();
    itsRight = Location.GetX();
}

void Rectangle::SetUpperRight(Point Location)
{
    itsUpperRight = Location;
    itsUpperLeft.SetY(Location.GetY());
    itsLowerRight.SetX(Location.GetX());
    itsTop = Location.GetY();
    itsRight = Location.GetX();
}

void Rectangle::SetTop(int top)
{
    itsTop = top;
    itsUpperLeft.SetY(top);
    itsUpperRight.SetY(top);
}

void Rectangle::SetLeft(int left)
{
    itsLeft = left;
    itsUpperLeft.SetX(left);
    itsLowerLeft.SetX(left);
}

void Rectangle::SetBottom(int bottom)
{
    itsBottom = bottom;
    itsLowerLeft.SetY(bottom);
    itsLowerRight.SetY(bottom);
}

void Rectangle::SetRight(int right)
{
    itsRight = right;
    itsUpperRight.SetX(right);
    itsLowerRight.SetX(right);
}

int Rectangle::GetArea() const
{
    int Width = itsRight-itsLeft;
    int Height = itsTop - itsBottom;
    return (Width * Height);
}

// compute area of the rectangle by finding corners,
// establish width and height and then multiply
int main()
{
    //initialize 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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -