01. /* 02. * copyright and version Declaration of the program part 03. * Copyright (c) 2013, Yantai University Computer college student 04. * All rightsreserved. 05. * file name: Triangle. cpp 06. * Author: Zhao guanzhe 07. * Completion Date: April 8, March 28, 2013. * version: v1.0 09. * input Description: 10. * Problem description: 11. */# include <iostream> # include <cmath> using namespace std; class Triangle {public: Triangle (double x = 1, double y = 1, double z = 1 ); double perimeter (void); // calculate the perimeter of the triangle double area (void); // calculate and return the area of the triangle void showMessage (); private: double a, B, c; // The three sides are private member data}; void main (void) {Triangle Tri1; // "()" cannot be added after Tri1. This is an unsupported Tri1.showMessage (); triangle Tri2 (); Tri2.showMessage (); Triangle Tri3 (, 9); // defines an instance (object) of the Triangle class Tri3.showMessage ();} Triangle :: triangle (double x, double y, double z) {a = x; B = y; c = z;} double Triangle: perimeter () {return (a + B + c);} double Triangle: area () {double s; s = (a + B + c)/2; return sqrt (s * (s-a) * (s-B) * (s-c);} void Triangle: showMessage () {cout <"the three sides of the triangle are respectively:" <a <"<B <" <c <endl; cout <"the circumference of the triangle is:" <perimeter () <"<" area: "<area () <endl ;}
Running result: