Question: c++ #includerectangle5-12.h #include using namespace std; class cube512 : public rectangle512 { private: float depth; public: cube512() : rectangle512() { depth = 1; area =

c++ c++ #include"rectangle5-12.h" #include using namespace std; class cube512 : public rectangle512 {

#include"rectangle5-12.h"

#include

using namespace std;

class cube512 : public rectangle512

{

private:

float depth;

public:

cube512() : rectangle512()

{

depth = 1;

area = 2 * length * width + 2 * length * depth +

2 * width * depth;

perimeter = 2 * (length + width) + 2 * (length + depth) +

2 * (width + depth);

}

cube512(float l, float w, float d) : rectangle512(l, w)

{

depth = d;

area = 2 * length * width + 2 * length * depth +

2 * width * depth;

perimeter = 2 * (length + width) + 2 * (length + depth) +

2 * (width + depth);

}

void print()

{

rectangle512::print();

cout

}

};

-----------------------------------------------------

#include"rectangle5-12.h"

#include

#include

using namespace std;

class colorrectangle512 : public rectangle512

{

private:

char color[20];

public:

colorrectangle512() : rectangle512()

{

strcpy(color, "blue");

}

colorrectangle512(float l, float w, char c[]) : rectangle512(l, w)

{

strcpy(color, c);

}

void print()

{

rectangle512::print();

cout

}

};

--------------------------------------------

#ifndef rectangle512_h

#define rectangle512_h

#include

using namespace std;

class rectangle512

{

protected:

float length;

float width;

float area;

float perimeter;

public:

rectangle512()

{

length = 1;

width = 1;

area = 1;

perimeter = 4;

}

rectangle512(float l, float w)

{

length = l;

width = w;

area = length * width;

perimeter = 2 * (length + width);

}

void virtual print()

{

cout

cout

cout

cout

}

};

#endif

Create a main that declares an array of three rectangle pointers. Each element should be a different kind of object that "is a rectangle (rectangle, cube, colored rectangle), then separately run the three different constructors (you can send it any values that match up with the argument constructors) and assign to each element of the array (ex. spot 0 rectangle, spot 1 cube, spot 2 colored rectangle). Then in a for loop, print the address of each object that "is a" rectangle (the address in the pointer) and then use dynamic binding to call the print function to print each of the objects in the array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!