Printing Objects of Copy Constructors || Copy Constructor || C++
In this, we are going to see a Print objects of Copy Constructor in C++.

 
#include <stdio.h>
using namespace std;

class Point
{
    int x, y, z;

    public:
    Point(int x1, int y1, int z1)
    {
        x = x1;
        y = y1;
        z = z1;
    }

    Point(const Point &p1)
    {
        x = p1.x;
        y = p1.y;
        z = p1.z;
    }

    getCoord()
    {
        cout << "x=" << x << " y=" << y << " z=" << z << endl;
    }
};

int main()
{
    int x, y, z;
    cout << "Enter coordinates-" << endl;
    cin >> x >> y >> z;

    Point p1(x, y, z);
    Point p2(p1);
    
    cout << "The coordinates are: \n";
    p2.getCoord();
    return 0;
}

//..........Coded by SAHIL SHAIKH

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post