10. Advanced Object-Oriented Principles
Activity 10: An Encyclopedia Application
Solution:
- Start by including all the files that we'll need for the application:
// Activity 10: Encyclopedia Application. #include <iostream> #include <string> #include <vector>
- Create a struct,
AnimalInfo
, that can store name, origin, life expectancy, and weight:struct AnimalInfo { std::string name = ""; std::string origin = ""; int lifeExpectancy = 0; float weight = 0; };
- Create a function to print that data out in a neat format. Name it
PrintAnimalInfo
:void PrintAnimalInfo(AnimalInfo info) { std::cout << "Name: " << info.name << std::endl; std::cout << "Origin: " << info.origin << std::endl; std::cout << "...