Third week Item 13 corner Class (3)

Source: Internet
Author: User

/* *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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.