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;