第六周上机任务项目5-一个项目多个文件

01/*      
02.* 程序的版权和版本声明部分      
03.* Copyright (c)2013, 烟台大学计算机学院学生      
04.* All rightsreserved.      
05.* 文件名称:CPoint .cpp                                 
06.* 作    者:赵冠哲                                  
07.* 完成日期:2013年4月5日      
08.* 版本号: v1.0            
09.* 输入描述:      
10.* 问题描述:    
11.*/         
#include<iostream>
#include<cmath> 
#include "class.h" 
using namespace std;
int main()  
{  
    CPoint a(0,0), b(1, 1), c(1, 0);
    CTriangle sj(a, b, c);  
    a.output(), b.output(), c.output();  
    cout << "构成的三角形:" << endl;  
    cout << "周长为:" << sj.perimeter() << endl;  
    cout << "面积为:" << sj.area() << endl;  
    cout << (sj.isRightTriangle() ? "是" : "不是") << "直角三角形。" << endl;  
    cout << (sj.isIsoscelesTriangle() ? "是" : "不是") << "等腰三角形。" << endl;   
    CPoint a2(0, 0), b2(0, ), c2(5, 0);
    CTriangle sj2(a2, b2, c2);   
    a2.output(), b2.output(), c2.output();  
     cout << "构成的三角形:" << endl;  
    cout << "周长为:" << sj2.perimeter() << endl;  
    cout << "面积为:" << sj2.area() << endl;  
    cout << (sj2.isRightTriangle() ? "是" : "不是") << "直角三角形。" << endl;  
    cout << (sj2.isIsoscelesTriangle() ? "是" : "不是") << "等腰三角形。" << endl; 
    system("PAUSE");    
	return 0;  
}  

 
 
//点类
#include <iostream>  
#include <cmath>  
#include "class.h"  

using namespace std; 

class CPoint
{private:
  float x;  // 横坐标
  float y;  // 纵坐标
public:
  CPoint(float xx=0,float yy=0);
  float Distance(CPoint p) const;   // 两点之间的距离(一点是当前点,另一点为参数p)
  void input();  //以x,y 形式输入坐标点
  void output(); //以(x,y) 形式输出坐标点
};
CPoint:: CPoint(float xx,float yy)
{
    x=xx,y=yy;
}
float CPoint::Distance(CPoint p) const
{
    return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
 void CPoint::input()
 {
     char a;
     do{
        cout<<"请输入点的坐标(如(x,y)的形式):";
        cin>>x>>a>>y;
     }while(a!=',');
 }
 void CPoint::output()
 {
     cout<<"("<<x<<","<<y<<")"<<endl;
 }


 
 
//三角形类
#include <iostream>  
#include <cmath>  
#include "class.h"  
class CTriangle
{
public:
  CTriangle(CPoint &X,CPoint &Y,CPoint &Z):A(X),B(Y),C(Z){} //给出三点的构造函数
  void setTriangle(CPoint &X,CPoint &Y,CPoint &Z);//
  float perimeter(void);//计算三角形的周长
  float area(void);//计算并返回三角形的面积
  bool isRightTriangle(); //是否为直角三角形
  bool isIsoscelesTriangle(); //是否为等腰三角形
private:
  CPoint A,B,C; //三顶点
};
void CTriangle::setTriangle(CPoint &X,CPoint &Y,CPoint &Z)
{
	A=X,B=Y,C=Z;
}
float CTriangle::perimeter(void)
{
	return(A.Distance(B)+B.Distance(C)+C.Distance(A));
}
float CTriangle::area(void)
{
	float AB=A.Distance(B), BC=B.Distance(C), AC=A.Distance(C); 	
	float p=(AB+BC+AC)/2;  
	return (sqrt(p*(p-AB)*(p-BC)*(p-AC)));  
} 
bool CTriangle::isRightTriangle()  
{  
    float AB=A.Distance(B), BC=B.Distance(C), AC=A.Distance(C);  
    return((AB*AB+BC*BC==AC*AC)||(AB*AB+AC*AC==BC*BC)||(AC*AC+BC*BC == AB*AB))?true:false;
}  
bool CTriangle::isIsoscelesTriangle()  
{  
    float AB=A.Distance(B), BC=B.Distance(C), AC=A.Distance(C);  
	return (AB==AC||AB==BC||AC==BC)?true:false; 
}  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值