# Project 1 of Week 4: Triangle

Source: Internet
Author: User
`/** Program Copyright and version description Section * copyright (c) 2012, Yantai University Computer college student * All rightsreserved. * file name: object. CPP * Author: Li Yang * 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); // assign the three sides X, Y, and Z to cout <: "<x <'\ t' <Y <' \ t' <z <Endl; cout <" the triangle perimeter is: "<tri1.perimeter () <'\ t' <" Area: "<tri1.area () <Endl; return 0;} void triangle :: setabc (Double X, Double Y, Double Z) {If (x + y> C & x + z> C & Y + z> X) {A = X; B = y; C = z;} elsecout <"this data cannot constitute a triangle! "<Endl;} void triangle: getabc (double * X, double * y, double * z) {* x = A; * Y = B; * z = C;} double triangle: Perimeter (void) {return (A + B + C);} double triangle: Area (void) {double S; S = (A + B + C)/2; Return (SQRT (S * (S-A) * (S-B) * (s-c )));}`

Related Keywords:

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.