Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

In c++, You have four classes--Polygon, Rectangle, Triangle, and Square. The latter three are subclasses of Polygon. Look through and understand the provided code. Implement

In c++, You have four classes--Polygon, Rectangle, Triangle, and Square. The latter three are subclasses of Polygon. Look through and understand the provided code. Implement the appropriate functions and classes where the comments indicate.

Please make it easy to read.

#include #include

using namespace std;

class Polygon{ protected: vector sides; public: virtual ~Polygon() {} int perimeter() { //Implement this function } virtual double area() = 0; };

class Rectangle : public Polygon { public: Rectangle() { sides.push_back(0.0); sides.push_back(0.0); } Rectangle(double a, double b) { sides.push_back(a); sides.push_back(b); } virtual double area() { // Implement this function } virtual double perimeter() { // Implement this function } };

class Triangle : public Polygon { double base; double height; public: Triangle() { sides.push_back(0.0); sides.push_back(0.0); sides.push_back(0.0); } Triangle(double a, double b, double c) { sides.push_back(a); sides.push_back(b); sides.push_back(c); } // Assume that the base and height will be set correctly externally void setBase(double _base) { base = _base; } void setHeight(double _height) { height = _height; } virtual double area() { // Implement this function } };

class Square : public Polygon { //Implement this class };

// use main for testing int main(){ return 0; }

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students explore these related Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 3 weeks ago

Question

Write short notes on Marketing mix.

Answered: 3 weeks ago