两点间距离得矩形.txt

来自「以两点为对角线的矩形面积的计算」· 文本 代码 · 共 69 行

TXT
69
字号
#include<iostream>
#include<cmath>
using namespace std;


class Point
{

public:
	Point (int xx=0, int yy=0)  {X=xx;Y=yy;}
	Point (Point &p);
	int GetX() {return X;}
    int GetY() {return Y;}
	
private:
	int X,Y;
};

Point::Point(Point&p)
{
	X=p.X;
	Y=p.Y;
}

 

class Rectangle
{

public:
	Rectangle (Point xp1, Point xp2);  
    Rectangle (Rectangle &L);
    double Getx0() {return len1;}
	double Getarea() {return fabs(len2*len1);}
	
private:
	Point p1,p2;
    double len1,len2;
};

Rectangle::Rectangle(Point xp1, Point xp2)
:p1(xp1),p2(xp2)
{
	len1=double(p1.GetX()-p2.GetX());
    
    len2=double(p2.GetY()-p1.GetY());
	
}

Rectangle::Rectangle( Rectangle &L):p1(L.p1),p2(L.p2)
{ 
	len1=L.len1;
	len2=L.len2;	
}




int main()
{
	Point myp1(4,5),myp2(1,3);
    Rectangle R(myp1,myp2);

    cout<<"面积="<<R.Getarea()<<endl;
	cout<<"x="<<R.Getx0()<<endl;
	return 0;
}

⌨️ 快捷键说明

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