Home > Back-end >  Some kind of Point as the base class public derived class Circle Circle, the main (void) function to
Some kind of Point as the base class public derived class Circle Circle, the main (void) function to

Time:04-02

Point class structure elucidation:
Point class data members include:
(1) the private data members: X coordinates X type (double), Y Y type (double),
Point class member functions include:
(1) there are arguments constructor Point (double, double) and copy constructor Point (const Point & amp;) , including the Constructor parameters default value is 0, the output information "Point Constructor run", the copy Constructor output information "Point CopyConstructor run"
(2) the Destructor, the Destructor output information "Point Destructor run"
(3) members of the public function: void your setX (double) and double getX () const returns and sets the X coordinate
(4) members of the public function: void setY (double) and double getY () const return and set the Y coordinate
Const (5) public member functions to void the show () is used to display the coordinates of point information, display format is: (x, y)
6 public member functions to double area (const) is used to calculate points area, the area of the point of 0
Circle class structure elucidation:
Public derived class Circle Circle to Point class Point as the base class, compared to some kind of Point, Circle class structure that is as follows:
Circle class data members include:
(1) the private data members: X coordinates X inherited from Point class, Y Y, inherited from the Point class
(2) the static data of constant PI (double), the value of 3.14159
(3) the private data members: radius radius (double),
Circle a class member function include:
1) define have arguments constructor (1) definition and constructor Circle (double, double, double) and copy constructor Circle (Circle & amp;) , including the Constructor parameters including the center coordinates and radius, call center Point to structure class Constructor, default value is 0, the parameters output information "Circle Constructor run", the copy Constructor output information "Circle CopyConstructor run"
(2) define the Destructor, the Destructor output information "Circle Destructor run"
(3) define the members of the public function: void setRadius (double) and double getRadius () const return and set the radius
(4) define public member functions to double circumference (const) is used to calculate the circumference of the circle
5. Overloaded double area (const) is used to calculate the area of a circle
6. Overloading void show () const is used to display round information, display format is:
(circle X coordinates, circle Y coordinates), Radius of the Radius=
The referee sample testing program:
#include
using namespace std;
The class Point {
Protected:
Double x;
Double y;
Public:
Point (double xv=0, double yv=0).//a parameter structure
Point (const Point & amp; P);//copy structure
~ Point ();//destructors
Void the show () the const;//display Point information
Double area () the const;//area=0
Void your setX (double xv);//set the X coordinate
Void setY (double yv);//set Y
Double getX () const;//get X coordinate
Double getY () const;//get Y
};
//a parameter structure
Point: : Point (double xv, double yv) {
X=xv.
Y=yv;
Cout<& lt;" Point Constructor run "& lt; & lt; Endl;
}
//copy structure
Point: : Point (const Point & amp; P) {
X=p.x;
Y=p.y;
Cout<& lt;" Point CopyConstructor run "& lt; & lt; Endl;
}
//destructors
Point: : ~ Point () {
Cout<& lt;" Point Destructor run "& lt; & lt; Endl;
}
//display Point
The void Point: : show () const {
Cout<& lt;" (" & lt; & lt; x<& lt;" , "& lt; & lt; Y<& lt;" ) ";
}
//set the X coordinate
Void Point: : your setX (double xv) {
X=xv.
}
//set Y
The void Point: : setY (double yv) {
Y=yv;
}
//area function
Double Point: : area () const {
return 0;
}
//get X coordinate
Double Point: : getX () const {
Return the x;
}
//get Y
Double Point: : getY () const {
The return of y;
}

Please fill in the answer here */*/

Int main (void) {
Double r;
Cin> r;
Circle c1, 4-trichlorobenzene (1), c2 and c3 (c1);
C1. The show ();
Cout<& lt; Endl<& lt;" Area="& lt; & lt; C1. Area () & lt; & lt; Endl<& lt;" Circumference="& lt; & lt; C1. Circumference () & lt; & lt; Endl;
C2. The show ();
Cout<& lt; Endl<& lt;" Area="& lt; & lt; C2. Area () & lt; & lt; Endl<& lt;" Circumference="& lt; & lt; C2. Circumference () & lt; & lt; Endl;
C3. SetRadius (r);
C3. The show ();
Cout<& lt; Endl<& lt;" Area="& lt; & lt; C3. Area () & lt; & lt; Endl<& lt;" Circumference="& lt; & lt; C3. Circumference () & lt; & lt; Endl;
return 0;
}
Input the sample:
6.0
The output sample:
Point Constructor run
Circle the Constructor run
Point Constructor run
Circle the Constructor run
Point CopyConstructor run
Circle CopyConstructor run
(1, 2), the Radius=4
Area=50.2654
Circumference=25.1327
(0, 0), the Radius=0
Area=0
Circumference=0
(1, 2), the Radius=6
Area=113.097
Circumference=37.6991
Circle Destructor run
Point Destructor run
Circle Destructor run
Point Destructor run
Circle Destructor run
Point Destructor run
  • Related