Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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()

in c++ image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions