--Point point class (II) on a plane

Description
Mathematically, the point on the plane rectangular coordinate system uniquely determined by two coordinate values of X and Y axes. Now we can encapsulate a "Point class" to achieve an operating point on the plane.

The "append.cc", and the method completes the construction of Point class Show () method, the output order of the constructor and destructor of Point objects.

Description Interface:
Point :: Show () method: Point object output by the output format.

Input
input multiple rows, each set of coordinates the behavior of a "x, y", represents the x coordinate and y coordinate values of x and y are within the range of double data.

Output
Output constructor and destructor Point behavior of each object. Point for each object, call show () method and outputs the values: X coordinate of the front, Y coordinates after, Y coordinates in front of a multi-output space. Each coordinate output accuracy is up to 16 bits. Output format See sample.

Input and output C language is disabled.

Sample Input

1,2
3,3
2,1

Sample Output

Point : (0, 0) is created.
Point : (1, 2) is created.
Point : (1, 2) Point : (1, 2) is erased.
Point : (3, 3) is created.
Point : (3, 3)
Point : (3, 3) is erased.
Point : (2, 1) is created.
Point : (2, 1)
Point : (2, 1) is erased.
Point : (0, 0) is copied.
Point : (1, 1) is created.
Point : (0, 0) Point : (1, 1)
Point : (0, 0) Point : (1, 1) is erased.
Point : (0, 0) is erased.
Point : (0, 0) is erased.

HINT
Reflection constructor, copy constructor, destructor call timing.

append.cc

int main()
{
    char c;
    double a, b;
    Point q;
    while(std::cin>>a>>c>>b)
    {
        Point p(a, b);
        p.show();
    }
    Point q1(q), q2(1);
    q1.show();
    q2.show();
    q.show();
}

answer

#include <iostream>
#include<iomanip>
using namespace std;
class Point
{
private:
    double x,y;
public:
    Point()
    {
        x=0;
        y=0;
        cout<<setprecision(16)<<"Point : (0, 0) is created."<<endl;
    }
    Point(int _x,int _y)
    {
        x = _x;
        y = _y;
        cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")is created."<<endl;
    }
    Point(int _x)
    {
        x=_x;
        y=_x;
        cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")is copied."<<endl;

    }
    ~Point ()
    {
        cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")is erased."<<endl;
    }
    Point(Point const &p)
    {
        x=p.x;
        y=p.y;
        cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")is copied."<<endl;

    }
    void show()
    {
        cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")"<<endl;
    }
};
Published 35 original articles · won praise 1 · views 1038

Guess you like

Origin blog.csdn.net/qq_43839907/article/details/104089025