Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ 1. Create a base class Polygon from which several other classes of shapes are derived according to the figure below. Constructors for each

IN C++

1. Create a base class Polygon from which several other classes of shapes are derived according to the figure below. Constructors for each derived class should error check that the input argument points form a valid shape of the given type and offer an error message to the user if invalid.

image text in transcribed

Triangle and parallelogram areas are bh and bh, respectively, where the height at point (x0,y0) is

image text in transcribed

with the base passing through points (x1,y1) and (x2,y2). The following header file is provided but the implementations of each member function must be completed. Additional member functions can be added as desired. Class functionality is then tested with the included main function. Extra credit is awarded if the data member array of points vertex is dynamically allocated.

Shapes.h header file with class prototypes:

#include "Point.h"

#include

using namespace std;

class Polygon {

protected:

Point vertex[10];

int numPoints;

string shapeName;

public:

Polygon();

void setPoints (double x[], double y[], int numP);

// Writes shapeName and all vertices to the screen

void displayPoints();

double getPerimeter ();

};

class Triangle : public Polygon {

public:

Triangle(double x1, double y1, double x2, double y2, double x3, double y3);

double getArea();

};

class EquilateralTriangle : public Triangle {

public:

// Displays error if given points do not make equilateral triangle

EquilateralTriangle(double x1, double y1, double x2, double y2,

double x3, double y3);

};

class RightTriangle : public Triangle {

public:

// Displays error if given points do not make right triangle

RightTriangle(double x1, double y1, double x2, double y2,

double x3, double y3);

};

class Parallelogram : public Polygon {

public:

// Displays error if given points do not make parallelogram

Parallelogram(double x1, double y1, double x2, double y2,

double x3, double y3, double x4, double y4);

double getArea();

};

class Rectangle : public Parallelogram {

public:

// Displays error if given points do not make rectangle

Rectangle(double x1, double y1, double x2,

double y2, double x3, double y3, double x4, double y4);

};

Main CPP file for testing:

#include

#include "Shapes.h"

using namespace std;

int main() {

EquilateralTriangle tri1(0,0 , 0.5,0.5 , 1,0),

tri2(0,0 , 0.5,0.8660254 , 1,0);

tri2.displayPoints();

cout

cout

RightTriangle right1(0,0 , 1,1 , 3,0 ),

right2(0,0 , 0,1 , 3,0.5),

right3(0,0 , 0,1 , 3,0 );

right3.displayPoints();

cout

cout

Parallelogram par1(1,0 , 2.1,1 , 4,1 , 3,0),

par2(1,0 , 2,1 , 3.8,1 , 3,0),

par3(1,0 , 2,1 , 4,1 , 3,0);

par3.displayPoints();

cout

cout

Rectangle rect1(1,0 , 2,1 , 4,1 , 3,0),

rect2(1,0 , 2.1,1 , 4,1 , 3,0),

rect3(0,0 , 0,3 , 4,3 , 4,0);

rect3.displayPoints();

cout

cout

return 0;

}

image text in transcribed

Polygon Triangle Parallelogram Right Triangle Equilateral Triangle Rectangle riangle is not equilateral Points for equilateral triangle: (0.0> 0 . 5 , 0 . 866025) 1.0) A -0.433013 riangle is not right riangle is not right Points for right triangle: 0.0) (0.1 P7.16228 =1.5 Opposite sides are not parallel pposite sides are not parallel Points for parallelogran: K1.0> K2.1) K4.1 3.0) P-6.82843 Angles not right pposite sides are not parallel Points for rectangle: 0.0> K4.3) C4.8) P=14 A12 Press any key to continue

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Discuss the importance of identifying the acquisition date.

Answered: 1 week ago

Question

How do exchange-traded funds (ETFs) differ from mutual funds?

Answered: 1 week ago