Question: C++ Please help with the dogcat class Code: #include #include #include #include #include #include class animal { public: virtual ~animal() { } virtual std::string kind()
C++ Please help with the dogcat class 
Code:
#include
#include
#include
#include
#include
#include
class animal
{
public:
virtual ~animal() { }
virtual std::string kind() const = 0;
};
using animal_ptr = std::unique_ptr
template
animal_ptr make_animal(T&& t)
{
using type = std::remove_cvref_t
return animal_ptr{ new type(std::forward
}
class cat : public animal
{
public:
std::string kind() const override
{
using namespace std::literals;
return "Felis catus\"s";
}
};
class dog : public animal
{
std::string value;
public:
dog() = delete;
dog(dog &obj) = default;
dog &operator=(const dog &) = default;
dog(std::string const &str) : value(str)
{ }
std::string kind() const override
{
return "Canis lupus familiaris";
}
std::string const &name()
{
return value;
}
};
class dogcat : public dog, public cat
{
}
Writing the dogcat Class Unfortunately you have to deal with hybrid organisms too --so you need to define a class called dogcat as follows: the class (multiply) inherits both publicly and virtually from both dog and from cat, the class has a default constructor that invokes the parent dog constructor with the name "hybrid" and the default cat constructor, the class has a constructor that has two parameters (dog const& d and cat const& c) and invokes the corresponding parameter class' copy constructor passing in d or c respectively, the class has a defaulted copy constructor, the class has a defaulted copy assignment operator, and, the class has a kind() member function that overrides animal::kind and returns the result of calling dog's kind(), + (i.e., string append), the string" +", + (i.e., string append), and calling cat's kind(). Tips: A dogcat's kind() function returns a string that is a concatenation of its dog's kind()," +", and its cat's kind(). A dogcat's name is always "hybrid" if default constructed. Writing operator+(dog const& d, cat const& c) To make it easier to create dogcat hyrbids, write an operator +() overload as follows: the function has two parameters: dog const& d and cat const& c, the function return type is dogcat, and, the return expression must create a dogcat object from d and c passing in d and c to a dogcat constructor. Writing the dogcat Class Unfortunately you have to deal with hybrid organisms too --so you need to define a class called dogcat as follows: the class (multiply) inherits both publicly and virtually from both dog and from cat, the class has a default constructor that invokes the parent dog constructor with the name "hybrid" and the default cat constructor, the class has a constructor that has two parameters (dog const& d and cat const& c) and invokes the corresponding parameter class' copy constructor passing in d or c respectively, the class has a defaulted copy constructor, the class has a defaulted copy assignment operator, and, the class has a kind() member function that overrides animal::kind and returns the result of calling dog's kind(), + (i.e., string append), the string" +", + (i.e., string append), and calling cat's kind(). Tips: A dogcat's kind() function returns a string that is a concatenation of its dog's kind()," +", and its cat's kind(). A dogcat's name is always "hybrid" if default constructed. Writing operator+(dog const& d, cat const& c) To make it easier to create dogcat hyrbids, write an operator +() overload as follows: the function has two parameters: dog const& d and cat const& c, the function return type is dogcat, and, the return expression must create a dogcat object from d and c passing in d and c to a dogcat constructor
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
