#include <iostream>
using namespace std;
class Shape {
protected:
int _w, _h;
public:
Shape(int w, int h) : _w(w), _h(h) { }
//declaration of area and volume function
};
class Rectangle : public Shape {
public:
Rectangle(int w, int h) : Shape(w, h) { }
};
class Cube : public Shape {
public:
int _b;
public:
Cube(int w, int h, int b) : Shape(w, h), _b(b) { }
int area() { return 2 * (_w * _h + _w * _b + _b * _h); }
int volume() { return _w * _h * _b; }
};
int main() {
Shape *pt;
int w, h, b, v;
cin >> w >> h >> b;
pt = new Rectangle(w, h);
cout << pt->area() << " ";
if ((v = pt->volume()) == -1)
cout << "Undefined ";
else
cout << v << " ";
pt = new Cube(w, h, b);
cout << pt->area() << " ";
if ((v = pt->volume()) == -1)
cout << "Undefined ";
else
cout << v << " ";
}
for the input 4 5 8
the output will be 20 Undefined 184 160
and in another test case the input is 10 20 10
and the output is
200 Undefined 1000 2000
how to declare and define area() and volume() to satisfy the given test cases.