Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Base class: Polygon Derived classes: Rectangle, Triangle Make Square a derived class of Rectangle. There can be several ways to represent the shapes. For example,

Base class: Polygon

Derived classes: Rectangle, Triangle

Make Square a derived class of Rectangle.

There can be several ways to represent the shapes. For example, a shape can be represented by an array of side lengths counted in the clock-wise order. For example, {2, 4, 2, 4} for a rectangle of width 2 and height 4, and {4, 4, 4, 4} for a square. You need to design your representation.

Each polygon should have a function area() that returns its area, and perimeter() that returns its perimeter.

The area of a triangle, given three sides a, b, and c, can be calculated using Heron's formula (http://www.mathopenref.com/heronsformula.html).

In a main program, create an array of pointers to Polygon; create at least one object from each derived class, assign it to the array, and print out the area and perimeter of each array member.

Polygon * shapes[3];

shapes[0] = new Rectangle(4.0, 2.0);

shapes[1] = new Square(4.0);

shapes[3] = new Triangle(4.0, 4.0, 4.0);

for (int i=0; i<3)

cout<area()<<" ,"<perimeter()<

Design your classes properly by using dynamic binding and well-thought-out constructors.

Submit 9 C++ files in one zip file: one header file and one cpp file for each of the four classes, plus a client.cpp.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions