请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了Component类、Composite类和Leaf类。Component是抽象基类,Composite和Leaf是Component的公有派生类。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
Leaf Node
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“// ****found****”。
#include<iostream>
using namespace std;
class Component
public:
//声明纯虚函数print()
//**********found**********
;
class Composite:public Component
public:
//**********found**********
void setChild(______)
m_child=child;
virtual void print()const
m_child->print();
private:
Component*m_child;
;
class Leaf:public Component
public:
virtual void print()const
//**********found**********
______
;
int main()
Leaf node;
Composite comp;
comp.setChild(&node);
Component*p=∁
p->print();
return 0;