Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program should deal with polymorphism, virtual methods, and overloading. Wh

ID: 3693107 • Letter: T

Question

This program should deal with polymorphism, virtual methods, and overloading. What the program does is not important, just that it has this functionality.

Turn in a C++ code file (.cpp) that will have the following functionality

In main, create an array that can hold both (or more)of your subclasses.

Populate the array with a minimum of two of each subclass.

Create a loop that will access each index of the array.

The loop will have a minimum of two method calls, using the current object that is in the array at the time. The first will be a method that implemented a virtual ABC method. The second will be the overloading method; so it will have the same name as the first, but will accept a different input type.

The different methods that the subclasses implement should have a clear form of output that distinguishes them from both the other subclasses andthe overloaded method.

Be explicit if you need to

Explanation / Answer

#include <iostream>
#include <stdlib.h>
#include <stdlib.h>
#include <cstring>

using namespace std;

class Box
{
public:
// Constructor definition
Box(double l=2.0, double b=2.0, double h=2.0)
{
length = l;
breadth = b;
height = h;
}
double Volume()
{
return length * breadth * height;
}
int compare(Box box)
{
return this->Volume() > box.Volume();
}
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};


class ColorBox : public Box
{
public:
ColorBox(char* c, double l=2.0, double b=2.0, double h=2.0): Box(l, b, h)
{
color = c;
}

char* getColor()
{
return color;
}
ColorBox operator+(const ColorBox cb)
{
char* a = this->color;
ColorBox cbox(a,
this->length + cb.length,
this->breadth + cb.breadth,
this->height + cb.height);
return cbox;
}

public:
char* color;
};

int main(void)
{
ColorBox redBox("red", 3.3, 1.2, 1.5);
ColorBox blueBox("blue", 8.5, 6.0, 2.0);
ColorBox greenBox("green", 2.7, 3.1, 2.5);
Box unitaryBox(1, 1, 1);
ColorBox bigBox("yellow", 20, 20, 20);

ColorBox colorBoxes[] = {redBox, blueBox, greenBox};
for(int i=0; i<3; i++)
{

ColorBox cb = colorBoxes[i] + bigBox;
cout<<"overloading call "<<colorBoxes[i].getColor() <<" + bigBox:"<<endl;
cout << cb.getColor() << " "<< cb.length<< " " << cb.breadth << " " <<cb.height<< endl;
cout<<"ABC method Volume of superclass Box"<<cb.Volume()<<endl<<endl;

}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote