class Rect { public: // constructor Rect(); Rect(int x, int y, int width, int height); // attributes int x, y, width, height; // methods bool contains(const Point& pt) const; bool contains(const Rect& other) const; bool intersects(const Rect& other) const; // operator overloads bool operator==(const Rect& other) const; bool operator!=(const Rect& other) const; };
// create a Rect object with default values Rect rect1; // create a Rect object with specific values Rect rect2(10, 20, 30, 40); // check if a point is inside a rectangle Point pt(15, 25); if (rect2.contains(pt)) { // do something } // check if two rectangles intersect Rect rect3(20, 30, 40, 50); if (rect2.intersects(rect3)) { // do something }
class QRect { public: // constructor QRect(); QRect(int x, int y, int width, int height); // attributes int x() const; int y() const; int width() const; int height() const; // methods bool contains(const QPoint& point) const; bool contains(const QRect& rectangle) const; bool intersects(const QRect& rectangle) const; // operator overloads bool operator==(const QRect& rectangle) const; bool operator!=(const QRect& rectangle) const; };
// create a Rect object with default values QRect rect1; // create a Rect object with specific values QRect rect2(10, 20, 30, 40); // check if a point is inside a rectangle QPoint point(15, 25); if (rect2.contains(point)) { // do something } // check if two rectangles intersect QRect rect3(20, 30, 40, 50); if (rect2.intersects(rect3)) { // do something }