题目内容
#include
#include
#include
using namespace std;
class AbstractFile{
protected:
string name; //文件或目录名称
public:
void printName(){cout$amp; virtual void addChild(AbstractFile *file)=0; //给一个目录增加子目录或文件}
virtual void removeChild(AbstractFile *file)=0; //删除一个目录的子目录或文件
virtual list *getChildren()=0; //获得一个目录的子目录或文件
};
class File:public AbstractFile{
public:
File(string name) {(1) = name;}
void addChild(AbstractFile *file){return;}
void removeChild(AbstractFile *file){return;}
(2) getChildren(){return (3) ;}
};
class Folder :public AbstractFile{
private:
list childList: //存储子目录或文件
public:
Folder(string name){ (4) name;}
void addChild(AbstractFile*file){childList.push_back(file);}
void removeChild(AbstractFile*file){childList.remove(file);}
list*getChildren(){return (5) ;}
};
void main(){
//构造一个树形的文件/目录结构
AbstractFile *rootFolder=new Folder("c:\\ ");
AbstractFile*compositeFolder=new Folder("composite");
AbstractFile *windowsFolder=new Folder("windows");
AbstractFile*file=new File("TestCompositejava");
rootFolder->addChild(compositeFolder);
rootFolder->addChild(windowsFolder);
compositeFolder->addChild(file);
}
查看答案
搜索结果不匹配?点我反馈
更多问题