0 like 0 dislike

Remember our Point class:

class Point

{

private:

    int x, y;

public:

    Point(int x1, int y1) { x = x1; y = y1; }

    int getX()            {  return x; }

    int getY()            {  return y; }

};

Please modify this class using copy-constructor so we can have in the main:

int main()

{

    Point p1(10, 15); 

    Point p2 = p1; 

    cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY();

    cout << "\np2.x = " << p2.getX() << ", p2.y = " << p2.getY();

    return 0;

}

Expected output:

p1.x = 10, p1.y = 15
p2.x = 10, p2.y = 15 
asked in Introduction to Computer Programming (II) by (10 points)
reshown by | 6 views

3 Answers

0 like 0 dislike
Hidden content!
answered by (10 points)
0 like 0 dislike
Hidden content!
#include *** **

using * std;



class Point



{


*** ** *


* * * * * * * * ** * x, y;


**** **


** * **** * * *** ** * x1, int y1) { x = x1; y = y1; }


****** * * * * *** * *** getX() * * ** * * * ** ** * * *** * *** * * * *** * ** * *** * **** * ** * x; }


**** ** * ** ** ** *** getY() ** ** *** ** ** * ***** ** * ** * * ** ** * * * * *** * * * y; }



};



int main()



{


* ** * * * p1(10, 15);



* * ** ** ** * ** ** p2 = p1;



* * ** * ** * * * * ***** * * * **** * *** * = * * ** ** ** ** * ** * * p1.y = **** * * **** ** *


*** * * ** ** * ***** ** * * * * * * * * *** = ****** * * * ** ***** ** ***** p2.y = ** * ** **** ** * * *


* * * ** **** * * * *** 0;



}
answered by (9.6k points)
0 like 0 dislike
Hidden content!
class Point



{


* *


* ** ** **** * *** * * x, y;



public:


** *** ** *** *** * * x1, int y1) { x = x1; y = y1; }


* ****** * ** ** *** getX() *** * * * ** *** * *** * * ** * * * * *** * ** *** * *** ** **** x; }


** *** *** * ** * * ** getY() * ** *** * * *** * * *** ******** ** ** ** * ** ** * *** *** * ** * ** * y; }



};



int main()



{


******* * ** * ** *** * * * p1(10, 15);



* ** ** * * * * * ** *** * p2 = p1;



** **** * ***** * * * * * **** *** = *** * **** ** p1.getX() *** * * * ** * * p1.y = *** * * ** * *


* * ** * * ***** * ** * * ** * ** * * = * *** ** * ** * ** * ** * * ** p2.y = * ** * ** ** * ** ** *


* * * ** ** ** * ****** ** 0;



}
answered by (9.6k points)
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.68.65.156
©2016-2018

Related questions

0 like 0 dislike
3 answers
asked May 10, 2016 in Introduction to Computer Programming (II) by admin (9.6k points) | 4 views
7 like 0 dislike
45 answers
7 like 0 dislike
32 answers
2,966 questions
57,291 answers
28,945 comments
938 users