10th, 11 Weeks-Item 1 (2)

Source: Internet
Author: User

Questions and codes:

<pre class= "cpp" name= "code" >/*copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: main.cpp* Author: Wang Lin * Completion Date: May 9, 2016 * version number: v1.0* The problem description: Derive a circle (circle) class with point, increase the data member R (RADIUS), and the area of the member function, implement other required member functions, design the main function to complete the test;    Input Description: * Output Description: */#include <iostream>using namespace Std;class point{public:point (double x=0,double y=0); void Show ();p rotected:double x, y;};    Point::P oint (double a,double b) {x=a; Y=b;} void Point::show () {cout<< "[" <<x<< "," <<y<< "]" &LT;&LT;ENDL;}    Class Circle:public point{public:circle (double x=0,double y=0,double r=0);    Double area (); void Show ();p rotected:double radius;}; Circle::circle (double a,double b,double R):P Oint (A, B), radius (r) {}double Circle::area () {return 3.14159*radius*radius ;} void Circle::show () {cout<< "center= (" <<x<< "," <<y<< "), r=" <<radius<< ", Area= "<<area () <<endl;}    int main () {Circle C (1.1,2.2,3.3);    C.area (); C.show(); return 0;}


Operation Result:


Summary of Knowledge points:

A constructor of a base class used to initialize data members in a base class;

When there is a default constructor in a base class, the constructor in the derived class implicitly calls the default constructor in the base class.




10th, 11 Weeks-Item 1 (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.