问答题

简单应用 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程包含程序文件main.cpp,其中有类Animal("动物")、类Dog("狗")、类Cat("猫")的定义和主函数main的定义。请在程序中"//****found****"下的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: Dog named Lucky speaks Woof Cat named Daisy speaks Miaow 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动"//****found****"。 #include using namespace std; class Animal { public: Animal(char* str="Animal") { //**********found********** name = new ___________________; strcpy(name,str); } virtual ~Animal() { delete[] name; } char* getName() const { return name; } virtual char* getType() const { return "Animal"; } virtual char* getVoice() const { return "Voice"; } private: char* name; }; class Dog : public Animal { public: Dog(char* str) : Animal(str) { } char* getType() const { return "Dog"; } //**********found********** char* getVoice() const { ___________________ } }; class Cat : public Animal { public: //**********found********** Cat(char* str) : ______________ { } char* getType() const { return "Cat"; } char* getVoice() const { return "Miaow"; } }; void type(Animal& a) { cout<
【参考答案】

(1)char[strlen(str)+1](2)return "Woof";(3)Animal(str)(4)Anim......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)