Week 5 computer task project 1-(2, 3 default parameter constructor)

Source: Internet
Author: User
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:

 

Related Article

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: info-contact@alibabacloud.com 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.