New operator into the vector the main function should

Info icon This preview shows pages 2–3. Sign up to view the full content.

View Full Document Right Arrow Icon
new operator into the vector. The main function should then iterate through the vector, using each pointer in it to call the print function. Build your solution, fix any errors or warnings, and run your program to make sure the right information is being printed out. As the answer to this exercise, please show the output of your program. 4. (Adapter pattern – object form). Add a look method to your Giraffe struct that prints out a message indicating that the giraffe is awake and looking around. Add a hide method to your Ostrich struct that prints out a message indicating that the ostrich has buried its head in the sand. Declare a ZooAnimal struct and from it derive (via public inheritance) GiraffeAdapter and OstrichAdapter structs, each of which has a pointer to the appropriate type of animal ( Giraffe or Ostrich respectively) as a member variable and a constructor that takes a pointer of the appropriate type and uses it to initialize its member variable. In the ZooAnimal struct declare a pure virtual act method, and override it in each derived adapter struct by using the pointer member variable to call the adapted animal’s look or hide method as appropriate. In your main function declare a vector of pointers to zoo animals. Declare several more ostriches and giraffes, and use their addresses to initialize appropriate adapter objects for them, pushing back the address of each adapter into the vector of zoo animal pointers. Iterate through that vector, using each pointer in it to call the act function. Build your program, fix all warnings and errors, and run your program. As the answer to this exercise, give the output your program produced. 5. (Adapter pattern – class form). Remove the constructors and pointer member variables you added in the previous exercise, from the derived adapter structs. Reimplement their act methods using multiple inheritance from the ZooAnimal struct (public) and the appropriate animal struct (private, from either Giraffe or Ostrich as appropriate).
Image of page 2

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern