Week 5 Project 1 design triangles

Source: Internet
Author: User

Machine purpose: omitted

Computer content: omitted

/** Copyright and version declaration section of the Program * copyright (c) 2012, student * All rightsreserved from computer College of Yantai University. * file name: object. CPP * Author: Liu Yujin * Completion Date: July 15, March 29, 2013 * version: V1.0 * input Description: none * Problem description: triangle side length, circumference and area * program output: triangle side length, circumference, and area */# 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 triangle (Double X = 1, Double Y = 1, Double Z = 1 ): A (x), B (Y), C (z) {} void showmessage (); Private: Double A, B, C; // the three sides are private member data }; void triangle: showmessage () {cout <"the three sides of the triangle are: "<A <" "<B <" "<C <Endl; cout <" the circumference of the triangle is: "<perimeter () <'\ t' <"Area:" <area () <Endl;} void main () {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 (, 9); // defines an instance of the triangle class (object) tri2.showmessage ();} double triangle: Perimeter (void) {double per; per = A + B + C; return per;} double triangle: Area (void) {Double P; P = (A + B + C)/2; return SQRT (p * (p-a) * (p-B) * (p-C ));}

Running result:

Experience: omitted

 

 

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.