項目1-三角形の雛形

1742 ワード

問題およびコード:
/*
  *copyright (c) 2014,         
  *All rights reserved.
  *    :test.cpp
  *      :   
  *    :2016 3 28 
  *     :v1.0
  *
  *    :          ,         
  *    :
  *    :
 */
#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
    void Setabc(double x, double y, double z);//     ,        
    void Getabc(double *x, double *y, double *z);//     
    double Perimeter(void);//        
    double Area(void);//           
private:
    double a,b,c; //         
};
void Triangle::Setabc(double x, double y, double z)
 {
     if(x+y>z&&x+z>y&&y+z>x)
     {
         a=x;
         b=y;
         c=z;
     }
     else
        cout<<"       "<<endl;
 }
void Triangle::Getabc(double *x, double *y, double *z)
 {
     *x=a;
     *y=b;
     *z=c;
 }
 double Triangle::Perimeter(void)
 {
     return a+b+c;
 }
 double Triangle::Area(void)
 {
     double p=(a+b+c)/2;
     return sqrt(p*(p-a)*(p-b)*(p-c));

 }
int main(void)
{   Triangle  Tri1; //           (  )
    Tri1.Setabc(4,5,6); //      
    double x,y,z;
    Tri1.Getabc (&x,&y,&z);   //      x,y,z  
    cout<<"    :"<<x<<'\t'<<y<<'\t'<<z<<endl;
    cout<<"       :"<< Tri1.Perimeter()<<'\t'<<"   :"<< Tri1.Area()<<endl;
    return 0;
}
<img src="http://img.blog.csdn.net/20160328210346363?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />