A. Based on the above class definition, provide the derived classes below that will override the function cage_size from the base class Animal: i.Elephant, cage_size = 1.5 x length x height ii.Giraffe, cage_size = 2.5 x length x height B. Write the complete main () function that will create the object Elephant and Giraffe. Insert their length and height to calculate their cage_size.
Assignment Question :
#include <iostream>
using namespace std;
class Animal {
protected:
int length, height;
public:
void set_values (int l, int h)
{ length = l; height = h; }
virtual int cage_size (void) =0;
};
A. Based on the above class definition, provide the derived classes below that will override the function cage_size from the base class Animal:
i.Elephant, cage_size = 1.5 x length x height
ii.Giraffe, cage_size = 2.5 x length x height
B. Write the complete main () function that will create the object Elephant and Giraffe. Insert their length and height to calculate their cage_size.
Note: A virtual function is a member function which is declared within a base class and is expected to be re-defined (overridden) by a derived class.
Step by step
Solved in 4 steps with 1 images