Question: CS-116 - C++ Programming I Create a structure that will contain information about animals. The information includes: - a name (a string up to 20

CS-116 - C++ Programming I Create a structure that will contain information about animals. The information includes: - a name (a string up to 20 characters long) - a type (up to 10 characters long) - an age (integer) Your program should create an array to hold animal information. The maximum number of entries in the array should be 25. The program should begin by prompting the user for the name of a file (filenames can be up to 32 characters long). Open the file and read animal information from the file into the array of structures. If the file open fails, display an error message and terminate the program. The file format is as follows: - there is one line of data in the file for each animal. - each line of data will contain the animal's name, type, and age in successive fields separated by whitespace. - each line will have a carriage return at the end of the line except the last line in the file. Here is a sample file: Goofy dog 8 Minnie mouse 22 Daisy duck 18 Mickey mouse 25 Pluto dog 10 Donald duck 21 Note: you can assume that names and types in the file are all single words. Once your program has read the file contents into the array of structures, the following menu should appear: Menu: 1 - display all the animals in forward order 2 - display all the animals in reverse order 3 - display all animals sorted by age (youngest first) 4 - determine the average animal age 5 - determine which animal is oldest 6 - determine which animal is youngest q - quit the program Choose: *** Note: the menu options MUST be numbers 1-6 and the letter 'q'. Do not deviate from this. Here's a sample output for each option given the data file presented above: Option 1 - this is the order that the animal information appears in the file. Name Type Age -------------------- ---------- --- Goofy dog 8 Minnie mouse 22 Daisy duck 18 Mickey mouse 25 Pluto dog 10 Donald duck 21 Option 2 - this is the reverse order that the animal information appears in the file. Name Type Age -------------------- ---------- --- Donald duck 21 Pluto dog 10 Mickey mouse 25 Daisy duck 18 Minnie mouse 22 Goofy dog 8 Option 3 - this is ascending order based on the age for each animal. Name Type Age -------------------- ---------- --- Goofy dog 8 Pluto dog 10 Daisy duck 18 Donald duck 21 Minnie mouse 22 Mickey mouse 25 Option 3: The average age is 17.3 years. Option 4: Mickey is the oldest. Option 5: Goofy is the youngest. Option q: The program exits Anything else: An error message should be displayed. After a menu option is selected and the appropriate action is taken, the menu should be redisplayed. This should continue until the user selects option 'q' and the program exits. For this assignment do NOT use global variables (unless they are prefixed with "const"). Implement your programs using functions that pass parameters and return values. There are lots of opportunities to use functions to break this assignment down into small units of functionality. There will also be some opportunities to use functions to prevent duplicating algorithms. These are things I'll be specifically looking for when grading this assignment. Your program should be flexible enough to handle a different numbers of animals in the data file up to the maximum of 25. You are to use #define constant values for the length of the file (you can also define this as a "const int" in the global scope -- the only allowed type of global!), string lengths (for the name and type), and for the maximum number of animals. You can assume that there are no errors in the contents of the data file. It will follow the rules described above. You will find a sample executable and sample data file for this assignment on the assignments web page. You are NOT allowed to use the std::string datatype defined in the  header. All strings needed for this assignment should be implemented with null-terminated character arrays (c-strings). What to include in your source code: - correct functionality - good coding style (commenting, white space, ...) - good use of functions to break your program into logical chunks and/or to eliminate duplicate code - proper use of streams, including clean formatting of the output - proper use of arrays (including passing them as parameters to functions) - proper use of structures - no recursion - no global variables Recommendation #1: design this program before trying to write the code. Use a top-down design approach ... it will work very well for this assignment. Use me as a sounding-board for your design if you'd like. Recommendation #2: check out the FAQ for some suggestions on how to approach this assignment. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!