[Cpp]
/*
* Copyright and version Declaration of the program
* Copyright (c) 2012, a student from the computer College of Yantai University
* All rightsreserved.
* File name: x. cpp
* Author: Xu Benxi
* Completion date: January 1, March 29, 2013
* Version: v1.0
* Input description:
* Problem description: default constructor and constructor with Parameters
* Program output:
*/
// My code:
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Triangle
{
Public:
Triangle (double x, double y, double z );
Triangle ();
Double perimeter (void); // calculates the perimeter of a triangle.
Double area (void); // calculates and returns the area of the triangle.
Void showMessage ();
Private:
Bool isTriangle (); // determines whether a triangle is used.
Double a, B, c; // the three sides are private member data.
};
Bool Triangle: isTriangle () // determines whether a Triangle is used.
{
Double num; int I = 0; bool t = true;
Do
{
If (a + B> c & a-B <c)
{
Num = a; a = B; B = c; c = num;
I ++;
}
Else
{
Cout <"three sides cannot form a triangle! ";
T = false;
Break;
}
If (I = 3)
Break;
} While (I <= 3 );
Return t;
}
Double Triangle: perimeter ()
{
Return (a + B + c );
}
Double Triangle: area ()
{
Double z;
Z = (a + B + c)/2;
Return (sqrt (z * (z-a) * (z-B) * (z-c )));
}
Triangle: Triangle ()
{
A = 1; B = 1; c = 1;
}
Triangle: Triangle (double x, double y, double z)
{
A = x; B = y; c = z;
}
Void Triangle: showMessage ()
{
If (isTriangle ())
{
Cout <"the three sides of the triangle are respectively" <a <'\ t' <B <' \ t' <c <endl;
Cout <"the circumference of the triangle is:" <perimeter () <'\ t' <"area:" <area () <endl;
}
Else
Cout <"cannot be a triangle! "<Endl;
}
Void main (void)
{
Triangle Tri1; // defines an instance (object) of the Triangle class. A default constructor is required. The initial values of the three sides are 1.
Tri1.showMessage ();
Triangle Tri2 (, 9); // defines an instance of the Triangle class (object)
Tri2.showMessage ();
}
/*
* Copyright and version Declaration of the program
* Copyright (c) 2012, a student from the computer College of Yantai University
* All rightsreserved.
* File name: x. cpp
* Author: Xu Benxi
* Completion date: January 1, March 29, 2013
* Version: v1.0
* Input description:
* Problem description: default constructor and constructor with Parameters
* Program output:
*/
// My code:
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Triangle
{
Public:
Triangle (double x, double y, double z );
Triangle ();
Double perimeter (void); // calculates the perimeter of a triangle.
Double area (void); // calculates and returns the area of the triangle.
Void showMessage ();
Private:
Bool isTriangle (); // determines whether a triangle is used.
Double a, B, c; // the three sides are private member data.
};
Bool Triangle: isTriangle () // determines whether a Triangle is used.
{
Double num; int I = 0; bool t = true;
Do
{
If (a + B> c & a-B <c)
{
Num = a; a = B; B = c; c = num;
I ++;
}
Else
{
Cout <"three sides cannot form a triangle! ";
T = false;
Break;
}
If (I = 3)
Break;
} While (I <= 3 );
Return t;
}
Double Triangle: perimeter ()
{
Return (a + B + c );
}
Double Triangle: area ()
{
Double z;
Z = (a + B + c)/2;
Return (sqrt (z * (z-a) * (z-B) * (z-c )));
}
Triangle: Triangle ()
{
A = 1; B = 1; c = 1;
}
Triangle: Triangle (double x, double y, double z)
{
A = x; B = y; c = z;
}
Void Triangle: showMessage ()
{
If (isTriangle ())
{
Cout <"the three sides of the triangle are respectively" <a <'\ t' <B <' \ t' <c <endl;
Cout <"the circumference of the triangle is:" <perimeter () <'\ t' <"area:" <area () <endl;
}
Else
Cout <"cannot be a triangle! "<Endl;
}
Void main (void)
{
Triangle Tri1; // defines an instance (object) of the Triangle class. A default constructor is required. The initial values of the three sides are 1.
Tri1.showMessage ();
Triangle Tri2 (, 9); // defines an instance of the Triangle class (object)
Tri2.showMessage ();
}