Item 1-point-circle-cylinder Group Design (2)

Source: Internet
Author: User

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<< "," &LT;&LT;Y&LT;&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.