Define the class Animals with protected data member name (of type string). The c
ID: 658234 • Letter: D
Question
Define the class Animals with protected data member name (of type string). The class has the public member function talk( ), and a default parameterized constructor. Define the following derived classes: 1. Define the class Cat which publicly inherits the class Animals. The class has the public member function talk( ), and a default parameterized constructor. 2. Define the class Dog which publicly inherits the class Animals. The class has the public member function talk( ), and a default parameterized constructor. 3. Define the class Duck which publicly inherits the class Animals. The class has the public member function talk( ), and a default parameterized constructor. 4. Define the class Loin which publicly inherits the class Animals. The class has the public member function talk( ), and a default parameterized constructor. Implement all classes. The talk() method shall print out the name of the sound of each animal. Check sample input/output for details on the required names.
testdrive:
#include<iostream>
using namespace std;
#include "Cat.h"
#include "Dog.h"
#include "Duck.h"
#include "Lion.h"
int main()
{
Animal *p[5];
p[0] = new Animal("Animal");
p[1] = new Cat("Cat");
p[2] = new Dog("Dog");
p[3] = new Duck("Duck");
p[4] = new Lion("Lion");
for(int i=0; i<5; i++)
p[i] -> talk();
return 0;
}
Explanation / Answer
#include<iostream>
using namespace std;
public class animal
{
Protected:
String name[n];
public:
void talk()
{
}
class cat: public animal()
{
};
class dog: public animal()
{
};
class duck: public animal()
{
};
class lion: public animal( )
{
};
void main()
{
Animalclass *a = new Animalclass() ;
a = new Animal("Animal");
a = new Cat("Cat");
a= new Dog("Dog");
a= new Duck("Duck");
a = new Lion("Lion");
for(int i=0; i<5; i++)
p[i] -> talk();
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.