/ * * @Issue: generating an abstract class Object * @Author: next scholar * @LastEditTime: 2020-02-24 10:34:13 * / #include <the iostream> the using namespace STD; // Point class class Point { X int, Y; public: // constructor with reference Point (int X1, Y1 int) { this-> X = X1; this-> Y = Y1; } // default constructor Point () { this-> X 0 =; this-> Y = 0; } // destructor ~ Point () {} int GetX () { return X; } int GetY () { return Y; } void setX (int X1) { X = X1; } setY void (int Y1) { Y = Y1; } void the MoveTo (int X1, Y1 int) { setX (X1); setY (Y1); } void Display () { COUT << "X:" X << << endl; COUT << "Y:" Y << << endl; } }; // abstract class Object class Object { public: Virtual Double CalArea () = 0; Virtual BOOL IsIn (Point P) = 0; }; / / Rect rectangle class class Rect: {public Object Point lt; // left corner Point rb; // bottom right public: // constructor initializer list Rect (Point p1, Point p2) : lt (p1), rb (p2) } { RB (P2) {} // find the area function Double CalArea () { return (rb.GetX () - lt.GetX ()) * (rb.GetY () - lt.GetY ()); } // in the matrix determines whether the point (edge are also considered) BOOL IsIn (Point P) { return (p.GetX ()> = lt.GetX () && p.GetX () <= rb.GetX () && p.GetY ()> = lt.GetY () && p.GetY () <= rb.GetY () ); } }; int main () { Object obj * [2]; obj [0] = new new Rect (Point (0,0), Point (3,3)); COUT << obj [0] -> CalArea () << endl; return 0; }