Week 4 Project 1 triangle

Source: Internet
Author: User

Objective: to private and public

Computer content: calculates the triangle length and area

/** 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 22, 2013 * version: v1.0 * input Description: none * Problem description: design class for triangle circumference and area. * Program output: Triangle length and area */# include <iostream> # include <Cmath> using namespace std; class Triangle {public: void setABC (double x, double y, double z); // set the value of the three sides. Be sure to convert it into a triangle void getABC (double * x, double * y, double * z ); // double perimeter (void); // calculate the triangle perimeter double Area (void); // calculate and return the Triangle Area private: double a, B, c; // the three sides are private member data}; int main () {Triangle tri1; // defines an instance of the Triangle class (object) tri1.setABC (, 6 ); // double x, y, z; tri1.getABC (& x, & y, & z) for the initial values of the three sides; // set the values of the three sides to x, y, z value assignment cout <"three sides:" <x <'\ t' <y <' \ t' <z <endl; cout <"the triangle perimeter is:" <tri1.perimeter () <'\ t' <"Area:" <tri1.Area () <endl; system ("PAUSE"); return 0;} void Triangle: setABC (double x, double y, double z) {if (x + z> y & y + x> z & z + y> x) {a = x; B = y; c = z ;} else {a = 0; B = 0; c = 0 ;}} void Triangle: getABC (double * x, double * y, double * z) {* x =; * y = B; * z = c;} double Triangle: perimeter (void) {return a + B + c;} double Triangle: Area (void) {double p = (a + B + c)/2; return sqrt (p * (p-a) * (p-B) * (p-c ));}

Running result:

Experience: Coming soon;

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.