Hello, i have this class
class Shape //abstract class "class with only virtual function"
{
public:
virtual void draw() = 0;
virtual void rotate(int i) = 0;
virtual void is_closed() = 0;
virtual ~Shape() {} ;
};
which has this sub-class
class Triangle : public Polygon
{
private :
Pt2d *vertices;
public :
Triangle(Pt2d*);
~Triangle()
{
delete vertices;
}
void rotate(int);
void draw()
{
cout << "tri: ";
for (int i = 0; i < 3; i++)
{
vertices[i].draw();
cout << '\t';
}
}
};
Now I have to :
1.Generate an abstract base class called PrintingDevice. It should
provide the interface PrintPoint() and PrintLine()
2. Derive from it the specific class ConsolePrintingDevice which should
implement the interface PrintPoint and PrintLine
3. Have the abstract base class shape use that inteface by passing the
pointer printingDevice to it
4. Reimplement the draw() function of Triangle to use the
interface of the printing, e.g. as follows
void Triangle::draw(PrintingDevice* pd){
cout << "tri: " ;
for (int i=0; i<3; i++) pd->PrintPoint(vertices[i]); cout << '\t';}
I'm blocked at point 3 (and consequently point 4).
Thanks for your attention Image may be NSFW.
Clik here to view.