六周任务5
来源:互联网 发布:windows 数据库客户端 编辑:程序博客网 时间:2024/05/12 21:14
//任务五 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 ;}
运行结果:
加油 继续吧!!!!
- 六周任务5
- 六周任务3
- 六周任务4.1
- 六周任务二
- 六周任务2.2
- 六周任务三
- 六周任务四
- 第九周项目六 委派任务
- 第九周项目六--委派任务
- 第九周项目六—委派任务
- 第九周项目六(任务委派)
- ucore lab1 任务六
- 实验任务六
- 第二周 任务六 输出所有的水仙花数
- 第九周上机项目六(2)委派任务
- 六.gradle的自定义任务
- 第六周任务5
- 第六周任务5
- 求职感想
- HTML5 跨域信息交互技术之 postMessage
- 第六周实验报告3
- 完全卸载最新版mysql
- 第六周实验报告(任务四)【三角形类】
- 六周任务5
- etk arm7 移植版 演示
- 任务三:设计平面坐标点类
- 重新注册一下ASP.NET
- C#.Net的常见面试试题
- 获取系统消息
- 有关C#的 继承、结构、封装 的一些小实现例子
- jquery实现弹框效果
- 1.Win32基本程序概念(深入浅出MFC之读书笔记)