For this project, you will be writing code for a Menagerie. Like the Bookstore example we looked at in class, Menagerie takes a list of animals and condenses them into a list of the names of the animals and their average age.
You have some code to start you off in menagerie.tar.gz. (See the SFTP and zip handout if you're having trouble handling a *.tar.gz file, or ask on Piazza if you still can't figure it out.) In it you'll find Animal_type.h and Animal_type.cpp, both of which have been implemented for you. You'll need to implement Menagerie.cpp, which will consist of a main function that can take input and collapse it.
Also in the zip file are the files input and sample_output. Your Menagerie.cpp should process the input file and produce exactly the sample_output file, at least in its first iteration. Much of the heavy lifting has been done for you in the Animal_type definitions. To get started, you should take a look through the Animal_type definitions to understand what operations are available. The easiest thing to do may be to start taking a look at Animal_type.h, since the header file has the most compact representation of what the class can do.
What gets turned in: You need to create a zip file that contains a README file, your Menagerie.cpp file and your Animal_type.cpp file. The README should contain answers to the comprehension questions below. You should also submit a file containing your own set of input, listing a set of animals including the type of animal, their name and age. Your input file should contain at least 5 animals total. As usual, you should submit your zipped project on Blackboard.
Testing your code: Once you've written a Menagerie.cpp, you should be able to test your code using the following commands:
$ g++ -o menagerie Menagerie.cpp Animal_type.cpp $ ./menagerie < input Dog Tom, Harry 7 Parrot Kiki 3 Cat Snowball, Lila, Joseph 8.66667
At the top of your README, put a header containing your name, the project name, and the date. Number the answers to your questions. Feel free to get as creative as you like, but if you make any major changes, please note them in your README.
Animal_typeAnimal_type class. Look at the private data members. What are the private data members? Where does each one first get initialized? What's the purpose of each of these variables?Animal_type class? What's the difference between them?
operator>> and operator<<. In plain English, what are the types of the parameters? Why?Now look at the implementation in the Animal_type.cpp file. This looks similar to the Bookstore.cpp code we wrote in class, but has a few key differences, mostly having to do with the fact that the Animal_type code keeps track of a vector of strings in order to hold on to the names of all the animals of a certain species. Peruse the code and answer the following in your README.
operator!= says !(lhs == rhs). Normally in Boolean logic, saying !(A == B) is equivalent to saying (A != B). Why did we use this syntax?operator+ in terms of operator+=, instead of the other way around?>> and << respectively) have a return type that isn't void? What does this allow you to do? (Think of the lines we sometimes write that involve multiple uses of an operator on a single line.)
operator>>, we only sometimes used the default constructor to re-initialize the Sales_item variable. Why does this code always re-initialize a?
Menagerie.cpp$ g++ -o menagerie Menagerie.cpp Animal_type.cpp $ ./menagerieDon't turn in your code yet.
Bookstore.cpp, write a full Menagerie.cpp that can handle the input file available in the tarball. Be sure that your output matches the sample_output file exactly. What changes did you have to make from the Bookstore code? Why?const_iterator in the definitions for both operator+= and operator<< in order to iterate through all the names in an Animal_type. Why did we use const_iterator over iterator? Try changing the code to read just iterator - what happens when you try to compile it?Animal_type code to accomodate her request. Think about what sort of data type you need to store the ages, and how you will know which age goes with which animal.Animal_type class. Is there room in Animal_type to store specific age information? Add a variable that can store this data.Animal_type will correctly modify the data member for the ages.menagerie executable produces now includes the ages next to the names of the animals, so that the first line of the output using the input file included should look like this:
Dog Tom-9,Harry-5 7