14184 - EE2310_Lab12-2   

Description

Modify your GeometricObject class definition
Define and implement its constructors well so that the main function works.
Define the toString() function as a virtual function.

Modify your Rectangle class. Define its toString() as a virtual function, too.
Define another class as follows.

class Square: public Rectangle {
public:
   Square();
   Square(double,  const string& , bool);
   virtual string toString() const;

};

/*
 * Implement its member functions.
 *
 */


//-------------------------------------

// Do not change anything below this line, or you will lose points

//-------------------------------------

void displayByValue(const GeometricObject g) {
   cout << g.toString() << endl;
}

void displayByReference(const GeometricObject &g) {
   cout << g.toString() << endl;
}

void displayByPointer(GeometricObject *ptr_g) {
   cout << ptr_g->toString() << endl;
}

int main() {
   GeometricObject shape("Red", true);
   Rectangle rectangle(2, 3, "orange", true);
   Square square(4, "blue", false);
   displayByValue(square);
   displayByReference(square);
   displayByPointer(&square);
   return 0;
}

 

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss