/* *copyright (c) 2015, Yantai University School of computer *all rights reserved. * File name: Main.cpp * Author: Han Juan * Completion Date: April 5, 2015 * Version number: v1.0 * Problem Description: Using a constructor with default parameters, the default side length is 1 when no argument is given; note-This version also requires only one constructor to * Enter a description: * Program output: Slightly */#include <iostream> #include <cmath>using namespace Std;class triangle{public:triangle (double a= 1,double b=1,double c=1); Double perimeter ();//Calculate the perimeter of the Triangle double area ();//calculate and return the areas of the triangle void ShowMessage ();p rivate:double a,b,c; Three sides for private member data}; Triangle::triangle (double x,double y,double z) {a=x; B=y; C=z;} The three-edged lengths of void Triangle::showmessage () {cout<< "triangles are:" <<a<< "<<b<<" <<c<< Endl cout<< "The circumference of the triangle is" <<perimeter () << ", the area is:" <<area () <<endl<<endl;} Double Triangle::p erimeter () {return a+b+c;} Double Triangle::area () {double r= (a+b+c)/2; return sqrt (r* (r-a) * (r-b) * (r-c)); int main () {Triangle triangle1; Defines a triangle class instance triangle1.showmessage () with an edge length of 1 1 1; Triangle Triangle2 (1.5);//define a 1.5 1 1 edge lengthTriangle class Instance triangle2.showmessage (); Triangle Triangle3 (1.5,1.5);//define a triangle class instance triangle3.showmessage () with a side length of 1.5 1.5 1; Triangle triangle4 (7,8,9); Defines a triangle class instance triangle4.showmessage () with an edge length of 7 8 9; return 0;}
Learning experience:
Good study Day Day up
Third week Item 13 corner Class (3)