Project 1 of Week 4: Triangle

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: Li Meng * Completion Date: July 15, March 22, 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: 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}; // define each member function void Triangle: setABC (double x, double y, double z) in the Triangle class below) {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) {return (a + B + c);} double Triangle: area (void) {double area, k; k = (a + B + c)/2; area = sqrt (k * (k-a) * (k-B) * (k-c )); return area;} int main () {Triangle tri1; // defines an instance (object) of the Triangle class tri1.setABC (, 6); // double x, y, z; tri1.getABC (& x, & y, & z); // assign values of the three sides as x, y, and z to cout. <"the three sides are: "<x <'\ t' <y <<'\ T' <z <endl; cout <"Triangle perimeter:" <tri1.perimeter () <' \ t' <"area: "<tri1.area () <endl; system (" PAUSE "); return 0;} output result: an error in the program: not found at the beginning, I have not found any errors. I should be careful later!

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.