[Cpp]
/*
Copyright and version Declaration of the program
Copyright (c) 2012, a student from the computer College of Yantai University
All rightsreserved.
File Name: object. cpp
Author: Liu Qingyuan
Completion date: January 1, March 29, 2013
Version: v1.0
Input Description: None
Problem description: design a class that calculates the circumference and area of a triangle.
Program output: the circumference and area of a triangle
*/
/*
Copyright and version Declaration of the program
Copyright (c) 2012, a student from the computer College of Yantai University
All rightsreserved.
File Name: object. cpp
Author: Liu Qingyuan
Completion date: January 1, March 29, 2013
Version: v1.0
Input Description: None
Problem description: design a class that calculates the circumference and area of a triangle.
Program output: the circumference and area of a triangle
*/
[Cpp]
# Include <iostream>
# Include <Cmath>
Using namespace std;
Class Triangle
{Public:
Triangle (): a (3), B (4), c (5 ){};
Double perimeter (void); // calculates the perimeter of a triangle.
Double area (void); // calculates and returns the area of the triangle.
Void showMessage ();
Private:
Double a, B, c; // the three sides are private member data.
};
Void Triangle: showMessage ()
{
Cout <"the three sides of the triangle are:" <a <'\ t' <B <' \ t' <c <endl;
Cout <"the circumference of the triangle is:" <perimeter () <'\ t' <"area:" <area () <endl;
}
Double Triangle: perimeter ()
{
Return a + B + c;
}
Double Triangle: area ()
{
Double r;
R = (a + B + c)/2;
Return sqrt (r * (r-a) * (r-B) * (r-c ));
}
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 ();
System ("pause ");
}
# Include <iostream>
# Include <Cmath>
Using namespace std;
Class Triangle
{Public:
Triangle (): a (3), B (4), c (5 ){};
Double perimeter (void); // calculates the perimeter of a triangle.
Double area (void); // calculates and returns the area of the triangle.
Void showMessage ();
Private:
Double a, B, c; // the three sides are private member data.
};
Void Triangle: showMessage ()
{
Cout <"the three sides of the triangle are:" <a <'\ t' <B <' \ t' <c <endl;
Cout <"the circumference of the triangle is:" <perimeter () <'\ t' <"area:" <area () <endl;
}
Double Triangle: perimeter ()
{
Return a + B + c;
}
Double Triangle: area ()
{
Double r;
R = (a + B + c)/2;
Return sqrt (r * (r-a) * (r-B) * (r-c ));
}
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 ();
System ("pause ");
}