Question: in c++ Ql: create Animal class as the following: class Animal { protected: string m_name; Animal(const string& name) : m_name{name} { public: const string& getName()

Ql: create Animal class as the following: class Animal { protected: string m_name; Animal(const string& name) : m_name{name} { public: const string& getName() const { return m_name; } virtual string speak() const { return "Meow"; } a. create a friend function void report(const Animal& animal) that print the name of the animal using getName() followed by "says" then call speak answer the following questions in the code as comments: can you declare an object from Animal class direct in a driver e.g. Animal snake("Allen"); why/why not? what if the speak() function is not virtual? you may answer these questions once you are done the whole lab] Q2: create Cat class that inherits Animal class, the class has the following: A constructor Cat(const std::string& name) that calls the Animal() constructor. speak() function that implement the virtual speak() function in Animal() class, it returns "Meow" value Q3: create Dog class that inherits Animal class, the class has the following: A constructor Dog(const std::string& name) that calls the Animal constructor. speak() function that implement the virtual speak() function in the Animal class, it returns "Woof value. Q3: create a main driver then do the following: create the following objects, then print their information using report() function: Cat fred { "Fred" }; Cat misty{ "Misty" }; Cat zeke{ "Zeke" }; Dog garbo { "Garbo" }; Dog pooky{ "Pooky" }; Dog truffle{ "Truffle" }; Create an animals pointer array Animals animals[] that contains all the created objects as elements e.g. & fred. Then loop through the array pointers and print their information using getName() says speak0. Fred says Meow Garbo says Woof Misty says Meow Pooky says Woof Truffle says Woof Zeke says Meow
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
