Project 1 of week 5: triangle (default constructor and constructor with parameters)

Source: Internet
Author: User
/** Program Copyright and version description Section * copyright (c) 2012, Yantai University Computer college student * All rightsreserved. * Author: Li Yang * Completion Date: July 15, March 31, 2013 * version: V1.0 * input Description: none * Problem description: none * program output: none */# include <iostream> # include <cmath> using namespace STD; Class triangle {public: Double perimeter (void); // calculate the triangle perimeter double area (void ); // calculate and return the Triangle Area void showmessage (); triangle (Double X, Double Y, Double Z); Private: Double A, B, C; // The three sides are private member data}; triangle: triangle () {A = 1; B = 1; C = 1;} 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 <"Triangle's three sides are: "<A <" "<B <" "<C <Endl; cout <" the circumference of the triangle is: "<perimeter () <" <"Area:" <area () <Endl;} void main (void) {triangle tri1; // defines an instance (object) of the triangle class. A default constructor is required. The initial values of the three sides are 1tri1. showmessage (); triangle tri2 (7,8, 9); tri2.showmessage ();}

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.