anonymous
2012-03-01 14:35:31 UTC
#include
#include
#include
#include "/user/cse232/Projects/project06.triangle.h"
#define PI 3.14159265
/*-----------------------------------------------------------------------------
Name: validate (private function member)
Purpose: Validate the contents of the sides. A triangle is only valid if
if the sum of 2 smallest sides is greater than the largest side alone and if
all the lengths of the sides are greater than zero.
-----------------------------------------------------------------------------*/
void Triangle::validate()
{ // triangle becomes valid if all sides are not = 0 and the sums of 2 sides is never less than the other
Valid = ((SideA!=0 && SideB!=0 &&SideC!=0)&&(SideA+SideB>SideC && SideA+SideC>SideB && SideC+SideB>SideA));
}
/*-----------------------------------------------------------------------------
Name: default constructor for type "Triangle"
Purpose: Initialize the contents of a Triangle
Receive: The lengths of the three sides of a Triangle
-----------------------------------------------------------------------------*/
Triangle::Triangle( double SA, double SB, double SC )
{
SideA = SA; //assigns values to each argument
SideB = SB;
SideC = SC;
validate();
}
/*-----------------------------------------------------------------------------
Name: copy constructor for class "Triangle
Purpose: Initalize the values of each side
Receive: the sides which is to be copied
-----------------------------------------------------------------------------*/
Triangle::Triangle (const Triangle& T)
{
SideA = T.SideA; // assigns each value to each argument that is gong to be copied
SideB = T.SideB;
SideC = T.SideC;
validate();
}
/*-----------------------------------------------------------------------------
Name: assignment operator for class "Triangle
Purpose: Copy the contents of the sides into another
Receive: the sides which is to be copied
Return: The sides on the righthand side for chaining.
-----------------------------------------------------------------------------*/
Triangle& Triangle::operator=(const Triangle& T)
{
SideA = T.SideA; // copy of each side's lengths
SideB = T.SideB;
SideC = T.SideC;
validate();
return *this; // return everything in the function
}
/*-----------------------------------------------------------------------------
Name: is_valid
Purpose: Test a Triangle object to see if it's valid
Receive: The Boolean value "true" is the object is valid
-----------------------------------------------------------------------------*/
bool Triangle::is_valid() const
{
return Valid; // returns true if the triangle is valid
}
/*-----------------------------------------------------------------------------
Name: sides
Purpose: Return the lenghth of each sides
Receive: The length of each side
Return: The value of each side's length
-----------------------------------------------------------------------------*/
void Triangle::sides(double& SA, double& SB, double& SC) const //0,inf,nan
{
SA = SideA;
SB = SideB;
SC = SideC;
cout<<"side"<
/*-----------------------------------------------------------------------------
Name: angles
Purpose: Return the angles of each sides
Receive: The length of each side
Return: The value of the angles between each side
-----------------------------------------------------------------------------*/
void Triangle::angles(double& SA, double& SB, double& SC) const
{
double AA,AB,AC;
AA = acos((pow(SB,2)+pow(SC,2)-pow(SA,2))/(2*SB*SC))*180/PI;
AB = acos((pow(SA,2)+pow(SC,2)-pow(SB,2))/(2*SA*SC))*180/PI;
AC = acos((pow(SA,2)+pow(SB,2)-pow(SC,2))/(2*SA*SB))*180/PI;
cout<
/*-----------------------------------------------------------------------------
Name: perimeter
Purpose: Return the perimeter of a Triangle
Return: The perimeter value
-----------------------------------------------------------------------------*/
double Triangle::perimeter() const
{
double A = SideA,
B = SideB,
C = SideC,
Perimeter;
Perimeter = A + B + C; // equation for perimeter
return Perimeter;
}
Cant show all my code. but how can I get the void functions(angles and sides) to successfully execute a "cout". Im knew with c++, and classes are still a bit confusing. If someone could help me out and explain to me how to do it, id appreciate it.