Project 1 in week 3-triangle type 1 and project triangle in week 3

Source: Internet
Author: User
Tags cmath

Project 1 in week 3-triangle type 1 and project triangle in week 3

# Include <iostream> # include <Cmath> using namespace std; class Triangle {public: void setABC (double x, double y, double z); // set the value of three sides, note that you must create a triangle void getABC (double * x, double * y, double * z); // obtain the value of double perimeter (void) on the three sides ); // 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 (object) of the Triangle class tri1.setABC (, 6); // values double x, y, and z for the three sides; tri1.getABC (& x, & y, & z); // assign values of the three sides x, y, and z to cout. <"the three sides are: "<x <'\ t' <y <' \ t' <z <endl; cout <" the triangle perimeter is: "<tri1.perimeter () <'\ t' <" Area: "<tri1.area () <endl; return 0 ;} // define the member functions in the Triangle class below

 

My answer:

 
/* Copyright (c) 2014, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Chen Danni * Completion Date: July 15, March 25, 2015 * version number: v1.0 * Problem description: design a triangle class below, please give the definition of each member function * input description: enter the number of three double types. * Output result: the length and area of the double type are output */# include <iostream> # include <cmath> using namespace std; class Triangle {public: void setABC (double x, double y, double z); void getABC (double * x, double * y, double * z); double perimeter (void); double area (void); private: double, b, c ;}; int main () {Triangle t; t. setABC (4,5, 6); double x, y, z; t. getABC (& x, & y, & z); cout <"three sides: "<x <'\ t' <y <' \ t' <z <endl; cout <" Triangle perimeter: "<t. perimeter () <'\ t' <"Area:" <t. area () <endl; return 0;} void Triangle: setABC (double x, double y, double z) {a = x; B = y; c = z ;} void Triangle: getABC (double * x, double * y, double * z) {* x = a; * y = B; * z = c;} double Triangle :: perimeter (void) {double sum; sum = a + B + c; return sum;} double Triangle: area (void) {double s, p; p = (a + B + c)/2; s = sqrt (p * (p-a) * (p-B) * (p-c )); return s ;}


Experience: I believe I will be better. Come on !!

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.