Questions and codes:
/* *copyright (c) 2016, Yantai University School of computer *all rights reserved. * File name: Zwj.cpp * Author: Zhang Weijing * Completion Date: May 4, 2016 * version number: v1.0 * * Problem Description: Follow the prompts, starting from the base class gradually complete the point--circle--cylinder class family design. * Input Description: * Program output: */#include <iostream>using namespace Std;class point{public:point (double a=0,double b=0); void Show_point (); Double Getx () {return x;} Double Gety () {return y;} Protected:double x; Double y;}; Class Circle:public point{protected:double r;public:circle (double a,double b,double c):P oint (A, B), R (c) {} double Area (); void Show_circle ();}; Point::P oint (double a,double b) {x=a; Y=b;} The coordinates of void Point::show_point () {cout<< "point are:" <<x<< "," <<Y<<ENDL;} Double Circle::area () {return r*r*3.1415926;} The area of void Circle::show_circle () {cout<< "circle is:" <<area () <<endl;} int main () {point P1; Circle R1 (1,2,2.0); P1.show_point (); R1.show_circle (); return 0;}
Operation Result:
Summary of Knowledge points:
Derived class constructors:
The constructor of the ① base class is not inherited, and its constructor is declared in the derived class.
When you define a constructor, you only need to initialize the new members of the class, initialize the inherited base class members, or automatically call the base class constructor to complete the ②.
③ to ensure that the constructors required by the derived class are defined in the base class.
Learning experience:
Item 1-point-circle-cylinder Group Design (2)