4-2-三角形クラス
1848 ワード
01./*
02.* :
03.* Copyright (c) 2011,
04.* All rights reserved.
05.* :test.cpp
06.* :
07.* :2014 03 23
08.* :v1.0
09.* :
10.* :
11.* :
12.* :
13.* :
14.* :
15.*/
#include <iostream>
#include<cmath>
using namespace std;
class Triangle
{
private:
double a,b,c;
public:
void setA(double x)
{
a=x;
}void setB(double y)
{
b=y;
}
void setC(double z)
{
c=z;
}
double getA(void)
{
return a;
}
double getB(void)
{
return b;
}
double getC(void)
{
return c;
}
bool isTriangle(double,double,double);
double perimeter(void);
double area(void);
};
int main()
{
Triangle tri1; // ( )
double x,y,z;
cout<<" :";
cin>>x>>y>>z;
tri1.setA(x);
tri1.setB(y);
tri1.setC(z); //
if(tri1.isTriangle(x,y,z))
{
cout<<" :"<<tri1.getA()<<','<<tri1.getB()<<','<<tri1.getC()<<endl;
cout<<" :"<< tri1.perimeter()<<'\t'<<" :"<< tri1.area()<<endl;
}
else
cout<<" "<<endl;
return 0;
}
bool Triangle::isTriangle(double x,double y,double z)
{
if((x+y)>z&&(x+z)>y&&(z+y)>x)//||(x-y)>=z||(z-y)>=x||(x-z)>=x)
return 1;
else
return 0;
}
double Triangle::perimeter(void)
{
return a+b+c;
}
double Triangle::area(void)
{
double m;
m=(a+b+c)/2;
return sqrt(m*(m-a)*(m-b)*(m-c));
}