Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

c++ image text in transcribed

#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

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago

Question

=+ What are the information and consultation requirements?

Answered: 1 week ago

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago