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<< "]" <<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)