Questions and codes:
/*copyright School of Computer and control engineering completion Date: May 6, 2016 Ma Yanyan problem Description: Based on point, derive a circle (circle) class, increase the data member R (RADIUS), and the area of the member function areas to implement other required member functions, Design main function to complete the test; Input Description: No output description: coordinate value; */#include <iostream>using namespace std;const float Pi=3.1415926;class point{ Public:point (double x=0,double y=0); constructor void SetPoint (double,double); Sets the coordinate value double GetX () const {return x;} X-coordinate double GetY () const {return y;} Y-coordinate void show (); Protected member Double x, y;}; 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{private:double R; Public:circle (double x=0,double y=0,double r=0); void Setr (double); Double area () const; void Show ();}; Circle:: Circle (Double a,double b,double R):P Oint (A, B), R (r) {}//Set circleThe constructor of void Circle::setr (double R) {this->r=r;} Double Circle::area () const{return pi*r*r;//the area of the Circle}void Circle:: Show () {cout<< "center coordinates are:" <<endl; cout<< "(" <<x<< "," <<y<< ")" <<endl; cout<< "Radius:" <<endl; Cout<<r<<endl;} int main () {Circle C (3.1,4.5,2.1); C.show (); C.setpoint (5,8); C.show (); return 0;}
Operation Result:
Summary of Knowledge points:
When point is the base class for circle, if Circle is accessing the private member of the base class is not possible, then the original private member is defined as a protected class or public class
Tenth Week-design project of Circle Group