class Animal {
public:
string name;
Animal(string n) : name(n) {}
string speak() { return "..."; }
};
class Dog : public Animal {
public:
Dog(string n) : Animal(n) {} // call base constructor
string speak() { return "Woof!"; }
};
class Cat : public Animal {
public:
Cat(string n) : Animal(n) {}
string speak() { return "Meow!"; }
};
Dog d("Rex");
cout << d.name; // Rex (inherited from Animal)
cout << d.speak(); // Woof!
public — anywhereprotected — this class + derived classesprivate — this class onlyCreate Shape base class with string color and getColor().
Derive Square (with side) and Triangle (with base and height), each with area().
Click "Run" to execute your code.