Multiple Inheritance Question
Hi! Never done multiple inheritance in the past and it is been asked
from my tutor to do so.
I have developed a code after request that follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
class Polygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b;}
};
class Rectangle: public Polygon {
public:
int area ()
{ return width * height; }
};
class Triangle: public Polygon{
public:
int area ()
{
return (width*height)/2;
}
};
int main () {
Rectangle rect;
rect.set_values (5,8);
cout << "Emvadon orthogoniou: " << rect.area() << '\n';
Triangle tria;
tria.set_values(6,4);
cout << "Emvadon trigwnou: " << tria.area() << '\n';
return 0;
}
|
It is been asked to add class PaintCost in the above code and make the appropriate changes so that class Rectangle is a descendant of PaintCost also.
Here is PaintCost:
1 2 3 4 5 6 7 8 9
|
class PaintCost
{
public:
int getCost(int area)
{
return area * 70;
}
};
|
Also add in main the appropriate statements that show message "Overal paint cost: ..."
thanks
1 2 3 4 5
|
class Rectangle: public Polygon, public PaintCost {
public:
int area ()
{ return width * height; }
};
|
Topic archived. No new replies allowed.