Third practice 2

Posted lightice

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于Third practice 2的主要内容,如果未能解决你的问题,请参考以下文章

Third practice 5

Third practice 4

Third practice 3

Third practice 6

Numpy学习笔记练习代码 ——

The third day