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<< "]" <<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