Code:
/**copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: main.cpp;* Author: Ye Chengyan; * Completion Date: May 6, 2015; * Version number: vc++6.0;** problem description As a base class of point, a circle class is derived, the radius r of the data member is increased, and the area of the member function is calculated. * 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;} int main () {Circle C (3.5,6.4,5.2); cout<< "Original circle:\n"; C.show (); C.setpoint (5,5); cout<< "New circle:\n"; C.show (); return 0;}Run the test;
10th Week Project One-point-round-cylinder design (2)