IUP Computer Science
COSC 110    Spring 2008

Project #5
Competition at the Arboretum
(Due 11 April 2008)

Each year, Ms. Peach and Ms. Patterson take their fifth grade classes to the Urbandale Arboretum on a science field trip.  Each teacher tells her students to find the common names of as many trees as they can during the free-for-all segment of the trip.  Over the years, the teachers have worked out an arrangement with the Arboretum staff so that each exhibited tree has a small card dispenser next to it which produces a small card containing the common and scientific names of the tree when a button is pressed.  A timer attached to the dispenser insures that a student cannot get more than one card per tree.  The students collect the small cards to get the common names and to show how many trees they have visited.  The students are also required to identify which tree, of those they visited, is their favorite; they may choose their favorite using any criteria they want - height, shape, bark, leaves, flowers, whatever.

When the class gets back to the school, each teacher collects the students cards and creates a file containing information in the following form (one student per line in the file).

First-name Last-Name     No.-of-trees  List-of-common-names  Rating  Favorite-tree

Here is an abbreviated sample, the first few lines of Ms. Patterson's file.

Jon Arbuckle    7  Green-Spire-Birch  Variegated-Aralia  ...   9  American-Chestnut
Beetle Bailey   6  Swamp-White-Oak  American-Hornbeam  ...   8  Giant-Sequoia
Buster Brown    5  Giant-Sequoia  Tulip-Tree  Swamp-White-Oak  ...   6  Black-Maple
Andy Capp      14  Freeman-Maple  Shellbark-Hickory  ...  10  Western-Red-Cedar

Each of these lines have been shortened to display here; the ... replaces several more tree names.  In this sample, Jon Arbuckle has visited 7 trees (Green Spire Birch, Variegated Aralia, etc)  He rates the field trip as a 9, on a scale of 0 to 10; and his favorite tree was the American Chestnut.  As you can see, the names are hyphenated (this is to make it easy for you to treat each one as a single string).  There are < 100 different trees and < 40 students per class.

Write a program to do the following with each of the files produced from the field trip.

  1. Prompt for and read in the name of the file.  The two files that will be provided are peachclass.txt and pattersonclass.txt  - both of these files can be found on the I:\ drive in I:\jlwolfe\110
  2. Then, using the provided file name, read in the data for the file.  As your program reads the file, it should collect all of the student names and the number of trees visited associated with each student.  It should also collect the names of all trees that were visited and the number of times each tree was visited.
  3. Calculate and display the average rating the students in a class had for the field trip.  This average should show two decimal places of accuracy.
  4. Sort the student names and number visited based on the number visited in descending order.  Then display the student names and number visited so that the name of the student that visited the most trees appears first and the one that visited the fewest trees appears last.
  5. Determine the tree which was selected by the most students as their favorite.  Display this tree's name and the number of students that selected it as their favorite.
  6. Sort the tree names and number of times visited in descending order.  Then, display the tree names and number of times visited so that the name of the tree visited most often appears first and the one visited least often appears last.
For Ms. Patterson's class, the program should produce a display similar to the following (the prompting and reading of the file name is not shown).

Average Student rating for field trip: 7.21

Student's Names         Trees Found
Snuffy Smith                     18
Linus VanPelt                    18
Funky Winkerbean                 18
...

Most popular tree: Shagbark-Hickory with 4 votes.

Common Tree Name           Reported
Bigleaf-Maple                    10
Japanese-Snowbell                 7
American-Hornbeam                 7
...

Your program is required to have at least three functions in addition to main.  Your program is also required to be structured so that it needs to be executed only once to produce the report for Ms. Patterson's class and  to produce the report for Ms. Peach's class; that is, the program needs to do all of its actions twice.  You are required to hand in a printout showing both reports.

Hand in a well-documented printout of your program and a printout of the captured output from both reports.  Also, copy the program's .cpp file to the handin folder on the P: drive for COSC 110, your section.  Be sure to name the .cpp file after yourself so that it can be distinguished from other student file names.  For example, I would name my file wolfep5.cpp

Extra Credit:

Do either or both of the following tasks to gain extra credit.  If you do either of these, you need to make a note on the printout telling me that you are doing it.

  1. Calculate and display the average number of trees visited by each of the two classes.  Ms. Patterson and Ms. Peach are rather competitive and use these values to determine which class did best on the field trip.
  2. Combine the visits from the two classes and list the tree names and number of times visited by the two classes together.  This listing should also be in descending order by number of visits.