4_2 triangles (2)

Source: Internet
Author: User

[Cpp]/** Copyright and version statement of the program section * Copyright (c) 2012, student * All rightsreserved from computer College of Yantai University. * file name: object. cpp * Author: Ji Zilong * Completion Date: July 15, March 21, 2013 * version: v1.0 * input Description: none * Problem description: design the class of triangle circumference and area. * Program output: Triangle length and area */# include <iostream> # include <Cmath> using namespace std; class Triangle {public: inline void setA (double x) // set the value of the three sides. Note that the triangle {a = x;} inline void setB (double x) {B = x;} inline void setC (double x) {c = x;} inline int getA () // obtain the value {return a;} inline int getB () {return B;} inline int getC () {return c;} double perimeter (void); // calculate the triangle perimeter double area (void); // calculate and return the Triangle area bool isTriangle (); // determine whether the Triangle type is private: double a, B, c; // the three sides are private member data}; double Triangle: perimeter (void) // calculate the perimeter of the Triangle {return a + B + c;} double Triangle: area (void) // calculate and return the Triangle Area {int s = (a + B + c)/2; return sqrt (s * (s-a) * (s-B) * (s-c);} bool Triangle: isTriangle () {if (a + B)> c & (a-B) <c) return true; else return false;} int main () {Triangle tri1; // defines an instance of the Triangle class (object) double x, y, z; cout <"Enter the three sides of the triangle:"; cin> x> y> z; tri1.setA (x); tri1.setB (y); tri1.setC (z ); // if (tri1.isTriangle () {cout <"three sides:" <tri1.getA () <',' <tri1.getB () <',' <tri1.getC () <endl; cout <"Triangle perimeter:" <tri1.perimeter () <'\ t' <"Area:" <tri1.area () <endl;} else cout <"cannot form a triangle" <endl; system ("pause"); return 0;} 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.