📄 triangle.cpp
字号:
// Exercise 17.12: Triangle.cpp
// Triangle class member-function definitions.
#include <iostream> // required to perform C++-style stream I/O
#include <cmath> // required for the sqrt function
#include "Triangle.h" // Triangle class definition
using namespace std; // for accessing C++ Standard Library members
// Triangle constructor
Triangle::Triangle( double side1, double side2, double side3 )
: TwoDimensionalShape( string( "triangle" ) )
{
setSide1( side1 );
setSide2( side2 );
setSide3( side3 );
} // end Triangle constructor
// set the length of side 1
void Triangle::setSide1( double side1 )
{
if ( side1 >= 0.0 )
{
sides[ 0 ] = side1;
} // end if
else
{
sides[ 0 ] = 0.0;
} // end else
} // end function setSide1
// return length of side 1
double Triangle::getSide1()
{
return sides[ 0 ];
} // end function getSide1
// set the length of side 2
void Triangle::setSide2( double side2 )
{
if ( side2 >= 0.0 )
{
sides[ 1 ] = side2;
} // end if
else
{
sides[ 1 ] = 0.0;
} // end else
} // end function setSide2
// return length of side 2
double Triangle::getSide2()
{
return sides[ 1 ];
} // end function getSide2
// set the length of side 3
void Triangle::setSide3( double side3 )
{
if ( side3 >= 0.0 )
{
sides[ 2 ] = side3;
} // end if
else
{
sides[ 2 ] = 0.0;
} // end else
} // end function setSide3
// return length of side 3
double Triangle::getSide3()
{
return sides[ 2 ];
} // end function getSide3
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -