Limited Offer Get 25% off — use code BESTW25
No AI No Plagiarism On-Time Delivery Free Revisions
Claim Now
Prices start at $5 per page · plagiarism-free papers · free revisions for 14 days 24/7 support: support@bestwriters.com
Uncategorized

Use Inheritance concepts to create a class

  • Posted
  • Authoradmin
  • Length228 words
  • Reading time1 min
Write My Assignment FREE

Use Inheritance and Polymorphism concepts to create a class named Animal with three derived classes. Each Animal has different characteristics and act different. Create a class that will show these differences by creating objects of type Animal, Dog, Cat and Bird.

  • Create a base class named Animal with three derived classes named
    • Gorilla,
    • Fish, and
    • Bird.
  • Create a derived class named Penguin whose base class is Bird.
  • 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
    • canSwim( ) – this will return true or false
  • 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
  • Create a main method to demonstrate the all functions including the following with appropriate output

Animal animal; animal.makeSound(); Dog dog dog.makeSound(); cout Animal badDog = Dog(); badDog.makeSound(); cout Animal* goodDog = new Dog(); goodDog->makeSound(); cout << goodDog->getLegs;

The post Use Inheritance concepts to create a class appeared first on My Assignment Online.

Plagiarism Free Assignment Help

Expert Help With This Assignment — On Your Terms

✓ Native UK, USA & Australia writers ✓ Deadline from 3 hours ✓ 100% Plagiarism-Free — Turnitin included ✓ Unlimited free revisions ✓ Free to submit — compare quotes

admin

Academic writer and editor at BestWriters.

Get your paper off your plate tonight

Post your instructions for free. Prices start at $5 per page.

Place an order