main.cpp

来自「数据结构及C++相关的一些小程序」· C++ 代码 · 共 20 行

CPP
20
字号
#include<iostream.h>
#include<math.h>
#include"CPoint.h"
#include"CRectangle.h"
double getLength(CPoint p1,CPoint p2){return sqrt((p1.X-p2.X)*(p1.X-p2.X)+(p1.Y-p2.Y)*(p1.Y-p2.Y));}
void CRectangle::display()
{
	cout<<"The length of the rectangle is:"<<endl<<len<<endl;
    cout<<"The width of the rectangle is:"<<endl<<wid<<endl;
	cout<<"The basepoint of the rectangle is:"<<endl<<"("<<basepoint.X<<","<<basepoint.Y<<")"<<endl;
	cout<<"The other three points of the rectangle are:"<<endl<<"("<<pA.X<<","<<pA.Y<<")"<<endl<<"("<<pB.X<<","<<pB.Y<<")"<<endl<<"("<<pC.X<<","<<pC.Y<<")"<<endl;
}
void main()
{
   CPoint P1(-1,4.5),P2(-3,-5.5);//P1在第二象限,P2在第三象限
   double length=getLength(P1,P2);//求两点间的距离
   cout<<"P1和P2之间的距离为"<<length<<endl;
   CRectangle rec(P2,4,3);//初始化一个矩形,P2为基点,长为4,宽为3.这里长和宽的定义不是按照长短来定义的,X轴方向为长,Y轴方向为宽。
   rec.display();
}

⌨️ 快捷键说明

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