Third practice 2

Third practice 2

任务描述

设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。

测试输入:100205080

预期输出: Area: 3000

测试输入:7503090625

预期输出: Area: 392700

源代码

#include <iostream>
using namespace std;
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; }
    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:
    int itsTop;
    int itsLeft;
    int itsBottom;
    int itsRight;
};
Rectangle::Rectangle(int top, int left, int bottom, int right)
{
    itsTop = top;
    itsLeft = left;
    itsBottom = bottom;
    itsRight = right;
}
int Rectangle::GetArea() const
{
    return (this->GetTop() - this->GetBottom()) * (this->GetRight() - this->GetLeft());
}
int main()
{
    int top,left,bottom,right;
    cin>>top>>left>>bottom>>right;
    Rectangle RT(top,left,bottom,right);
    cout<<"Area: "<<RT.GetArea();
    return 0;
}

原文链接: https://www.cnblogs.com/lightice/p/12910847.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    Third practice 2

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/349433

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 上午5:41
下一篇 2023年3月2日 上午5:41

相关推荐