Print? /*
* 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: Yang shaoning
* Completion date: January 1, March 28, 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
*/
# Include <iostream>
# Include <Cmath>
Using namespace std;
Class Triangle
{
Public:
Triangle (double x = 1, double y = 1, double z = 1): a (x), B (y), c (z ){}
Double perimeter (void); // calculates the perimeter of a triangle.
Double area (void); // calculates and returns the area of the triangle.
Void showMessage (void );
Private:
Double a, B, c; // the three sides are private member data.
};
Double Triangle: perimeter (void)
{
Double l;
L = a + B + c;
Return l;
}
Double Triangle: area (void)
{
Double s, p;
P = (a + B + c)/2;
S = sqrt (p * (p-a) * (p-B) * (p-c ));
Return s;
}
Void Triangle: showMessage ()
{
Cout <"three sides of the triangle are:" <a <'\ t' <B <' \ t' <c <endl;
Cout <"the triangle perimeter is:" <perimeter () <'\ t' <"area:" <area () <endl; // set the initial value for the three sides
}
Int main ()
{
Triangle tri1; // defines an instance (object) of the Triangle class)
Tri1.showMessage ();
Triangle tri2 (, 9); // defines an instance of the Triangle class (object)
Tri2.showMessage ();
Return 0;
}
/*
* 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: Yang shaoning
* Completion date: January 1, March 28, 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
*/
# Include <iostream>
# Include <Cmath>
Using namespace std;
Class Triangle
{
Public:
Triangle (double x = 1, double y = 1, double z = 1): a (x), B (y), c (z ){}
Double perimeter (void); // calculates the perimeter of a triangle.
Double area (void); // calculates and returns the area of the triangle.
Void showMessage (void );
Private:
Double a, B, c; // the three sides are private member data.
};
Double Triangle: perimeter (void)
{
Double l;
L = a + B + c;
Return l;
}
Double Triangle: area (void)
{
Double s, p;
P = (a + B + c)/2;
S = sqrt (p * (p-a) * (p-B) * (p-c ));
Return s;
}
Void Triangle: showMessage ()
{
Cout <"three sides of the triangle are:" <a <'\ t' <B <' \ t' <c <endl;
Cout <"the triangle perimeter is:" <perimeter () <'\ t' <"area:" <area () <endl; // set the initial value for the three sides
}
Int main ()
{
Triangle tri1; // defines an instance (object) of the Triangle class)
Tri1.showMessage ();
Triangle tri2 (, 9); // defines an instance of the Triangle class (object)
Tri2.showMessage ();
Return 0;
}
Feel: If you want to add tri1 .. If you call a member function, no more !! 1, right?