10th Week Project One-point-round-cylinder class design

Source: Internet
Author: User

Code:

/**copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: main.cpp;* Author: Ye Chengyan May 6, 2016; * Version number: vc++6.0;** problem Description: Add a class Cylinder class, increase data member function h, find surface area, volume.                    * Program input: slightly; * Program output: slightly; */#include <iostream>using namespace Std;class point{public:point (double x=0,double y=0);                  constructor void SetPoint (double,double);   Sets the coordinate value double GetX () const {return x;   Read x-coordinate} double GetY () const {return y; Read y-coordinate} void Show ();p rotected://protected Member double x,y;};/    The/point constructor point::P oint (double a,double b) {x=a; Y=b;}    Set x and Y coordinate values void Point::setpoint (double a,double b) {x=a; Y=b;} void Point::show () {cout<< "[" <<x<< "," <<y<< "]" &LT;&LT;ENDL;}  Class Circle:public Point//circle is the common derived class of the point class {public:circle (double x=0,double y=0,double r=0);                  constructor void Setradius (double);               Set the RADIUS value double Getradius () const; Read RADIUS value DoubLe area () const; Calculate Circle area Void Show ();p rotected:double radius;};/ /definition constructor, circle::circle (double a,double b,double R) for the center coordinate and radius initialization, radius (r) {}//set radius value void Circle::setradius:P oint (b) ( Double r) {radius=r;} Read RADIUS value double Circle::getradius () const{return radius; Calculate Circle Area Double Circle::area () const{return 3.14159*radius*radius;} Output Circle information void Circle::show () {cout<< "center=[" <<x<< "," <<y<< "], r=" <<radius< < ", area=" <<area () <<endl;} Class Cylinder:public Circle{public:cylinder (double x=0,double y=0,double r=0,double h=0);//constructor void SetHeight (Do                      uble);                    Set cylinder high double getheight () const;                         Read cylinder high double area () const;                       Calculates the cylindrical surface area double volume () const;                               Calculates the cylinder volume void show ();p rotected:double height; Cylindrical high};//definition constructor Cylinder::cylinder (double a,double b,double r,double h): CiRcle (a,b,r), height (h) {}//set cylinder high void cylinder::setheight (double h) {height=h;} Read cylinder high double cylinder::getheight () const{return height; Calculate cylindrical surface Area double Cylinder::area () const{return 2*circle::area () +2*3.14159*radius*height; Calculates the cylinder volume double cylinder::volume () const{return Circle::area () *height; void Cylinder::show () {cout<< "center=[" <<x<< "," <<y<< "], r=" <<radius<< ", H= "<
Run Tests


10th Week Project One-point-round-cylinder class design

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.