Question
c++ #includerectangle5-12.h #include using namespace std; class cube512 : public rectangle512 { private: float depth; public: cube512() : rectangle512() { depth = 1; area =
c++
#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 arrayStep 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