Use the Animal class file given on the final exam module. Use Inheritance and Polymorphism concepts to create the following classes and functions. Create the following classes that derive from the Animal class. Monkey Kangaroo Create a derived class named Spider Monkey whose base class is Monkey. Create constructors for each class. Create destructors for each class. All classes will have the following private instance fields, including Animal legs that will initialize to 0 boolean swim that will initialize to false; All classes will have the following polymorphic methods, including Animal getLegs( ) – this returns the number of legs the animal has makeSount( ) – this outputs the type of sound the animal makes makeSound( ) method will be a virtual function in the Animal class Create an exception in the getLegs( ) method that makes sure the number of legs are valid (only allow positive number amount of legs) Create a main method to demonstrate the all functions including the following with appropriate output Animal animal; animal.makeSound(); Monkey monkey; monkey.makeSound(); cout << monkey.getLegs(); Animal badMonkey = Monkey(); badMonkey.makeSound(); cout << badMonkey.getLegs(); Animal* goodMonkey = new Monkey(); goodMonkey->makeSound(); cout << goodMonkey->getLegs(); Animal* goodKanga = new Kangaroo(); goodKanga->makeSound(); cout<getLegs(); file from the final module(photo):
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Use the Animal class file given on the final exam module.
Use Inheritance and Polymorphism concepts to create the following classes and functions.
- Create the following classes that derive from the Animal class.
- Monkey
- Kangaroo
- Create a derived class named Spider Monkey whose base class is Monkey.
- Create constructors for each class.
- Create destructors for each class.
- All classes will have the following private instance fields, including Animal
- legs that will initialize to 0
- boolean swim that will initialize to false;
- All classes will have the following polymorphic methods, including Animal
- getLegs( ) – this returns the number of legs the animal has
- makeSount( ) – this outputs the type of sound the animal makes
- makeSound( ) method will be a virtual function in the Animal class
- Create an exception in the getLegs( ) method that makes sure the number of legs are valid (only allow positive number amount of legs)
- Create a main method to demonstrate the all functions including the following with appropriate output
Animal animal;
animal.makeSound();
Monkey monkey;
monkey.makeSound();
cout << monkey.getLegs();
Animal badMonkey = Monkey();
badMonkey.makeSound();
cout << badMonkey.getLegs();
Animal* goodMonkey = new Monkey();
goodMonkey->makeSound();
cout << goodMonkey->getLegs();
Animal* goodKanga = new Kangaroo();
goodKanga->makeSound();
cout<<goodKanga->getLegs();
file from the final module(photo):
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images