六周任务5

//任务五 main.cpp


#include <iostream>
#include <cmath>
#include "class.h"

using namespace std;


	int main()

	{
		CTriangle ctr1(CPoint(6,6),CPoint(9,7),CPoint(10,5)) ;

		//ctr1.setTriangle() ;//

		cout<<"该三角形的周长为:"<<ctr1.perimeter()<<",面积为:"<<ctr1.area()<<endl<<endl;  

        cout<<"该三角形"<<(ctr1.isRightTriangle()?"是":"不是")<<"直角三角形"<<endl;  

        cout<<"该三角形"<<(ctr1.isIsoscelesTriangle()?"是":"不是")<<"等腰三角形"<<endl;  

		system ("pause") ;

		return  0 ;
	}

 
 

// class.h

//using namespace std;

class CPoint
{
private :
	double x ;
	double y ;

public :
	CPoint( double xx = 0 , double yy = 0 );//构造函数声明

	double Distance ( CPoint p ) const ;//求两点距离函数声明

	void input() ;//按x , y的形式输入点

	void output() ;//按(x,y)输出点的值

};


class CTriangle

{
public:

    CTriangle(CPoint &x , CPoint &y , CPoint &z ):A(x),B(y),C(z){}//

	void setTriangle (CPoint &x , CPoint &y , CPoint &z );//

	double perimeter(void);//

	double area(void);//

	bool isRightTriangle();//

	bool isIsoscelesTriangle();//

private:

	CPoint A , B , C ;//
};


	





// Triangle.cpp


#include "class.h"
#include <cmath>

double  CTriangle::perimeter(void)

{
	return ( A.Distance(B) + A.Distance(C) + B.Distance(C) ) ;//
}

void  CTriangle::setTriangle (CPoint &x , CPoint &y , CPoint &z )

{
	A.input();
    B.input();
	C.input();
}

double  CTriangle::area(void)

{  
	double s , m ;

	m = ( A.Distance(B) + A.Distance(C) + B.Distance(C) )/2 ;

	s = sqrt ( m * ( m - A.Distance(B) ) * ( m - A.Distance(C) ) * ( m - B.Distance(C) ) ) ;//

	return s ;
}

bool  CTriangle::isRightTriangle()

{
	if ( abs(A.Distance(B)*A.Distance(B)+A.Distance(C)*A.Distance(C)-B.Distance(C)*B.Distance(C))<1e-6||abs( A.Distance(B)*A.Distance(B)+B.Distance(C)*B.Distance(C)-A.Distance(C)*A.Distance(C))<1e-6||abs(A.Distance(C)*A.Distance(C)+B.Distance(C)*B.Distance(C)-A.Distance(B)*A.Distance(B))<1e-6)

		 return true ;
	else 

		return false ;
}

bool  CTriangle::isIsoscelesTriangle()

{
	if((abs(A.Distance(C)*A.Distance(C)-B.Distance(C)*B.Distance(C))<1e-6)||((abs(A.Distance(B)*A.Distance(B)-B.Distance(C)*B.Distance(C))<1e-6)||(abs(A.Distance(B)*A.Distance(B)-A.Distance(C)*A.Distance(C))<1e-6) ))

        return true ;
	else 
		return false ;
}


 

 

 

// CPoint.cpp


#include <iostream>

#include "class.h"

#include <cmath>

using namespace std ;

CPoint::CPoint( double xx , double yy )
{
	x = xx ;
	y = yy ;
}

void  CPoint::input()
{
	cout << "按 x , y 的形式输入坐标点" << endl ;
	cin >> x >> y ;
}

void  CPoint::output()
{
	cout<< "点的坐标为:" <<"("<< x <<","<< y <<")"<< endl ;
}

double CPoint::Distance ( CPoint p ) const
{
	double h ;
	h = sqrt ((x - p.x)*(x - p.x) + (y - p.y)*(y - p.y)) ; 
	return h ;
}


 

运行结果:

 

 

加油 继续吧!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值