Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3790695 • Letter: I

Question

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.

Explanation / Answer

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";
}
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote