Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. class Point {
  6. private:
  7. int x;
  8. int y;
  9. public:
  10. Point(int i = 0, int j = 0):x(i), y(j) {}
  11. /* The above use of Initializer list is optional as the
  12. constructor can also be written as:
  13. Point(int i = 0, int j = 0) {
  14. x = i;
  15. y = j;
  16. }
  17. */
  18.  
  19. int getX() const {return x;}
  20. int getY() const {return y;}
  21. };
  22.  
  23. int main() {
  24. Point t1(10, 15);
  25. cout<<"x = "<<t1.getX()<<", ";
  26. cout<<"y = "<<t1.getY();
  27. return 0;
  28. }
  29.  
  30. /* OUTPUT:
  31. x = 10, y = 15
  32. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement