Answered step by step
Verified Expert Solution
Link Copied!

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 1(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 FIGURE_H
#define FIGURE_H
#include
using namespace std;
class Figure {
public:
Figure();
Figure(string, int);
virtual ~Figure();
void setName(string);
string getName();
void setNoSides(int);
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();
RegularPolygon(string, int, double, double);
~RegularPolygon();
void setApothem(double);
double getApothem();
void setSideMeasurement(double);
double getSideMeasure();
double calculatePerimeter();
double calculateArea();
private:
double apothem;
double sideMeasure;
};
#endif // FIGURE_H
#include "Figure.h"
#include
Figure::Figure()
{
noSides=1;
name="ND";
}
Figure::Figure(string x, int y){
noSides=y;
name=x;
}
Figure::~Figure(){}
void Figure::setName(string x){ name = x; }
string Figure::getName(){ return name; }
void Figure::setNoSides(int x){ noSides = x; }
int Figure::getNoSides(){ return noSides; }
// Implementation of PoligonoRegular methods
RegularPolygon::RegularPolygon() : Figure(), apothem(0), sidemeasure(0){}
RegularPolygon::RegularPolygon(string x, int y, double a, double s) : Figure(x,y)//call the parent's constructor to initialize the values.
{ apothem = a, sideMeasure = s; }
RegularPolygon::~RegularPolygon(){}
voidRegularPolygon::setApothem(double a){ apothem = a; }
doubleRegularPolygon::getApothem(){ return apothem; }
void RegularPolygon::setSideMeasure(double s){ sideMeasure = s; }
double RegularPolygon::getSideMeasure(){ return sideMeasure; }
doubleRegularPolygon::calculatePerimeter(){
return noSides * sideMeasure;
}
doubleRegularPolygon::calculateArea(){
return 0.5* noSides * sideMeasure * apothem;
}
#include
#include "Figure.h"
int main(){
// Example of an octagon
RegularPolygon octagon("Octago",8,4.0,5.0);
cout << octagon.getName()<< endl;
cout << "Perimeter of Octagon: "<< octagon.calculatePerimeter()<< endl;
cout << "Octagon Area: "<< octagon.calculateArea()<< endl;
cout << endl;
// Example of a pentagon
RegularPolygon pentagon("Pentagon",5,3.0,6.0);
cout << pentagon.getName()<< endl;
cout << "Perimeter of Pentagon: "<< pentagon.calculatePerimeter()<< endl;
cout << "Pentagon Area: "<< pentagon.calculateArea()<< endl;
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

Step: 3

blur-text-image

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

Describe the four steps used in the net present value method.

Answered: 1 week ago