Advertisement
avr39-ripe

PV913ClassesBasics

May 12th, 2020
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Point
  4. {
  5. private:
  6. //protected:
  7.     int coords[2];
  8.     int secretMethod() {};
  9. public:
  10.     void show() {/* point specific code*/ };
  11.     void hide() {/* point specific code*/ };
  12.     void move(int dx, int dy) { hide(); coords[1] += dx; coords[0] += dy; show(); }
  13.     bool setX(int aX)
  14.     {
  15.         if (aX < -1000 or aX > 1000 )
  16.         {
  17.             return false;
  18.         }
  19.         coords[1] = aX;
  20.         return true;
  21.     };
  22.     bool setY(int aY)
  23.     {
  24.         if (aY < -1500 or aY > 1500)
  25.         {
  26.             return false;
  27.         }
  28.         coords[0] = aY;
  29.         return true;
  30.     };
  31.     int getX() { return coords[1]; };
  32.     int getY() { return coords[0]; };
  33. };
  34.  
  35. class Circle : public Point
  36. {
  37.     int r;
  38. public:
  39. //  void printXY() { std::cout << x << y; }
  40. //  void show() {/* circle specific code*/};
  41. //  void hide() {/* circle specific code*/ };
  42. };
  43.  
  44. int main()
  45. {
  46.     Point myPoint; // myPoint.x myPoint.y
  47.     //myPoint.x = 10;
  48.     //myPoint.y = 20;
  49.     //myPoint.secretMethod();
  50.     myPoint.setX(0);
  51.     myPoint.setY(0);
  52.     if (myPoint.setX(900))
  53.     {
  54.         std::cout << "x changed successfuly!\nx = " << myPoint.getX() << '\n';
  55.     }
  56.     else
  57.     {
  58.         std::cout << "x UNchanged! Check value!\nx = " << myPoint.getX() << '\n';
  59.     }
  60.     myPoint.hide();
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement