Question

C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the...

C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the compiler.

Vertebrates are the types of animals that typically have backbones with a bony skeleton and a brain. Vertebrates can be mammals, reptiles, amphibians, fish, and birds.

Based on this information, do the following:

  • Create a C++ hierarchy of the vertebrates class along with the attributes (variables) and behaviors (functions) using C++ syntax.
  • Is this an example of single inheritance or multiple inheritance? Why or why not?
  • Provide the access specifiers (public, private, and protected) for each class member in a class, and state the reason.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

 #include <iostream> using namespace std; class Vertebrates { protected: string name; public: void Print(); }; void Vertebrates::Print() { cout << "Vertebrates can be mammals, reptiles, amphibians, fish, and birds" << endl; } /////////////////////////////////////// // THE Mammals DERIVED CLASS class Mammals: public Vertebrates // <- if you don't include that public keyword, public methods won't get inherited. { private: bool alive; public: Mammals(); void RegulateBodyTemperature(); }; Mammals::Mammals() { // We're able to access the protected variables from the Vertebrates class // even though we didn't declare it in this class. name = "Mammals"; // We can also access our own private variables. alive = true; } void Mammals::RegulateBodyTemperature() { cout << "Mammals can regulate their body temperature." << endl; } /////////////////////////////////////// // THE Reptiles DERIVED CLASS class Reptiles: public Vertebrates // <- if you don't include that public keyword, public methods won't get inherited. { private: bool hasLimbs;//Snakes are exception public: Reptiles(); void LayEggs(); }; Reptiles::Reptiles() { // We're able to access the protected variables from the Fish class // even though we didn't declare it in this class. name = "Reptiles"; // We can also access our own private variables. hasLimbs = true; } void Reptiles::LayEggs() { cout << "Reptiles are oviparous and the eggs are very yolky." << endl; } /////////////////////////////////////// // THE Birds DERIVED CLASS class Birds: public Vertebrates // <- if you don't include that public keyword, public methods won't get inherited. { private: bool canFly;//Snakes are exception public: Birds(); void Fly(); }; Birds::Birds() { // We're able to access the protected variables from the Fish class // even though we didn't declare it in this class. name = "Birds"; // We can also access our own private variables. canFly = true; } void Birds::Fly() { cout << "Birds have ability to fly." << endl; } /////////////////////////////////////// // MAIN int main() { Vertebrates vertebrates; vertebrates.Print(); Mammals mammals; mammals.RegulateBodyTemperature(); Reptiles reptiles; reptiles.LayEggs(); Birds birds; birds.Fly(); // The derived classes inherited the Verebrates Print method ONLY because we used // the public keywordwhen we did "class Mammals: public Vertebrates". You don't // HAVE to use the public keyword, but if you do then the derived class // inherits the base classes public variables and methods. mammals.Print(); birds.Print(); reptiles.Print(); return 0; } 


OUTPUT:

Vertebrates can be mammals, reptiles, amphibians, fish, and birds Mammalsa can regulate their body temperature. Reptiles are oviparous and the eggs are very yolky. Birds have ability to fly. Vertebrates can be mammals, reptiles, amphibians, fish, and birds Vertebrates can be mammals, reptiles, amphibians, fish, and birds Vertebrates can be mammals, reptiles, amphibians, fish, and birds


The above program is an example of Single Inheritance because there is only one parent class from which all the child classes are deriving from.

Add a comment
Know the answer?
Add Answer to:
C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the...

    C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the compiler. Write a program that takes two rectangle objects and then adds them and returns the final rectangle object. You are required to overload the addition operator to add the two objects.

  • State Ty zip Code 1705 Based on pages 820-841, 852-869, 880-897, and 908-923 in your textbook...

    State Ty zip Code 1705 Based on pages 820-841, 852-869, 880-897, and 908-923 in your textbook 51-56 in your study guide. and discussions Circle T if the statement is true; F if it is false. During embryonic development, the vertebral column is replaced by the notochord 2. TF The ncural crest is important because several significant vertebrate features develop from it. 3. TF There are more species of living fishes than of all other species of vertebrates combined. 4. TFCrayfish,...

  • C# - Inheritance exercise I could not firgure out why my code was not working. I...

    C# - Inheritance exercise I could not firgure out why my code was not working. I was hoping someone could do it so i can see where i went wrong. STEP 1: Start a new C# Console Application project and rename its main class Program to ZooPark. Along with the ZooPark class, you need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Add the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT