14186 - EE2310_Lec13-1   

Description

Modify Lab 12-2 to include the following two pure virtual functions for the class GeometricObject

double getArea() const;
double getPerimeter() const;

This way, GeometricObject will become an abstract class, i.e. you can't declare any concrete object of this class. These two functions are designed to be overridden by later descendant classes later.

 

/* ----------------------------------------

 *  Do not change anything below

 */

void displayByReference(const GeometricObject &g) {
  cout << g.toString() << ": area = " << g.getArea()
       << ", perimeter = " << g.getPerimeter() << endl;
}

void displayByPointer(GeometricObject *ptr_g) {
  cout << ptr_g->toString() << ": area = " << ptr_g->getArea()
       << ", perimeter = " << ptr_g->getPerimeter() << endl;
}

int main() {
   Rectangle rectangle(2, 3, "orange", true);
   Square square(4, "blue", false);
   displayByReference(square);
   displayByPointer(&square);

}

Input

Output

Square object: area = 16, perimeter = 16
Square object: area = 16, perimeter = 16

Sample Input  Download

Sample Output  Download

Tags




Discuss