Questions and codes:
/* *copyright (c) 2016, Yantai University School of computer *all rights reserved. * File name: Zwj.cpp *: 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;}; Point::P oint (double a,double b) { x=a; Y=b;} The coordinates of void Point::show_point () { cout<< "point are:" <<x<< "," <<Y<<ENDL;} int main () {point P1; P1.show_point (); return 0;}
Operation Result:
Summary of Knowledge points:
Derived class constructor: the constructor for 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 (1)