Implement class Cat derived from Animal in which makeSound i

Implement class Cat derived from Animal in which makeSound is overridden and outputs \"Meow\". Cat also has a member double tailLength that should be between 0 and 20. (So include getter and setter for tailLength.) Constructor for Cat takes two parameters: first one is for weight and second one is for tailLength. The Cat constructor should call the base class constructor to initialize weight, then call the setter to initialize tailLength. Default parameter values for weight and tailLength are 1.0 and 10.0 respectively.

Solution

Here is the code for you:

#include <iostream>
using namespace std;
class Animal
{
double weight;
public:
Animal()
{
weight = 1.0;
}
Animal(double w)
{
weight = w;
}
void setWeight(double w)
{
weight = w;
}
double getWeight()
{
return weight;
}
string makeSound();
};

class Cat : public Animal
{
double tailLength;
public:
Cat()
{
Animal();
tailLength = 10.0;
}
Cat(double w, double tL) : Animal(w)
{
tailLength = tL;
}
string makeSound()
{
return \"Meow\";
}
};

 Implement class Cat derived from Animal in which makeSound is overridden and outputs \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site