zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
  • 相关阅读:
    Web版RSS阅读器(五)——初步完成阅读功能
    袁氏-人物-袁赋城:百科
    汉语-词语-慧根:百科
    汉语-词语-善根:百科
    汉语-词语-阴德:百科
    汉语-词语-福报:百科
    汉语-词语-回响:百科
    汉语-词语-领悟:百科
    汉语-词语-开悟:百科
    汉语-词语-业障:百科
  • 原文地址:https://www.cnblogs.com/lightice/p/12910847.html
Copyright © 2011-2022 走看看