Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Modify the practice of the previous topic with the following elements: - - Add a class called Square, which will inherit the elements of the
Modify the practice of the previous topic with the following elements:
Add a class called "Square", which will inherit the elements of the Shape class and will have an attribute called Side to store the measurement of one of its sides
Adds a virtual method in the Figure class called "calculaArea", which will return adds the same characteristics as the PoligonoRegular class method
Add this same method in the Square class
In the main, call the calculateArea method for the two daughter classes, first directly, and then through an array
I need the following files.
Square.h file code
Square file code.cpp
Main.cpp file code
Here is the last practice to modify.
#ifndef FIGUREH
#define FIGUREH
#include
using namespace std;
class Figure
public:
Figure;
Figurestring int;
virtual ~Figure;
void setNamestring;
string getName;
void setNoSidesint;
int getNoSides;
protected:access to your children's class
string name;
int noSides;
;
Definition of the RegularPolygon class
class RegularPolygon : public Figure public derivation of the Figure class
public:
Regular polygon;
RegularPolygonstring int, double, double;
~RegularPolygon;
void setApothemdouble;
double getApothem;
void setSideMeasurementdouble;
double getSideMeasure;
double calculatePerimeter;
double calculateArea;
private:
double apothem;
double sideMeasure;
;
#endif FIGUREH
#include "Figure.h
#include
Figure::Figure
noSides;
nameND;
Figure::Figurestring x int y
noSidesy;
namex;
Figure::~Figure
void Figure::setNamestring x name x;
string Figure::getName return name;
void Figure::setNoSidesint x noSides x;
int Figure::getNoSides return noSides;
Implementation of PoligonoRegular methods
RegularPolygon::RegularPolygon : Figure apothem sidemeasure
RegularPolygon::RegularPolygonstring x int y double a double s : Figurexycall the parent's constructor to initialize the values.
apothem a sideMeasure s;
RegularPolygon::~RegularPolygon
voidRegularPolygon::setApothemdouble a apothem a;
doubleRegularPolygon::getApothem return apothem;
void RegularPolygon::setSideMeasuredouble s sideMeasure s;
double RegularPolygon::getSideMeasure return sideMeasure;
doubleRegularPolygon::calculatePerimeter
return noSides sideMeasure;
doubleRegularPolygon::calculateArea
return noSides sideMeasure apothem;
#include
#include "Figure.h
int main
Example of an octagon
RegularPolygon octagonOctago;
cout octagon.getName endl;
cout "Perimeter of Octagon: octagon.calculatePerimeter endl;
cout "Octagon Area: octagon.calculateArea endl;
cout endl;
Example of a pentagon
RegularPolygon pentagonPentagon;
cout pentagon.getName endl;
cout "Perimeter of Pentagon: pentagon.calculatePerimeter endl;
cout "Pentagon Area: pentagon.calculateArea endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started