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-04

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; }
//copy structure
Point: : Point (const Point & amp; P) {
X=p.x;
Y=p.y;
Cout<& lt;" Point CopyConstructor run "& lt; }
//destructors
Point: : ~ Point () {
Cout<& lt;" Point Destructor run "& lt; }
//display Point
The void Point: : show () const {
Cout<& lt;" (" & 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
  • Related