ITEC 320: Programming Assignment 3


Due 11:59:59 p.m. Thursday 10/26/2017

Due 11:59:59 p.m. Tuesday 10/24/2017

Submit Command: submit itec320-01 dotrees.adb


Last modified:
Updates:

  1. 2017 Oct 22 01:55:02 PM: Changed due date to Thursday
  2. 2017 Oct 22 01:55:02 PM: Updated assignment checker to handle invalid IDs correctly

You can see an example of this program at assignment checker (which uses gnoga to integrate the GUI, web server, and problem solution). On-campus or VPN session required.

Write a program that helps a fruit breeder analyze a set of data describing fruit trees and sample pieces of fruit found on those trees. Use records, enumerated types, and other language features in solving the problem.

Input:

Output:
  1. Output should look like the sample run below, lined up in columns, with one decimal place.
  2. Output 0.0 for averages and standard deviation for trees with no fruit samples.
  3. Output commands, data, and ID numbers in upper case.
Sample run:

Assume that the file test1.dat is as follows:

 
tree 1234567
fruit small hard sour
fruit midsize firm bland
fruit large hard sour
    tree 
          
         2234567
tree 3234567
tree 4234567
    fruit 
        small 
        soft 
        sour
tree 1234567
    fruit midsize hard bland
tree 1234567
    fruit large firm sweet
tree 3333333
    fruit midsize hard bland
tree 4444   
    fruit large firm sweet
and that the following is entered via standard input (ie either keyboard or via redirection):
trees
fruits
averages
quit
A sample run of your program would look [approximately] like this:
 
    >dotrees  test1.dat
trees
TREE: 1234567   5
TREE: 2234567   0
TREE: 3234567   0
TREE: 4234567   1
TREE: 3333333   1
TREE:    4444   1
fruits
TREE: 1234567   5:
    HARD      SOUR      SMALL
    FIRM      BLAND     MIDSIZE
    HARD      SOUR      LARGE
    HARD      BLAND     MIDSIZE
    FIRM      SWEET     LARGE
    2.6       2.0       2.2
    0.5       0.9       0.7
TREE: 2234567   0:
    0.0       0.0       0.0
    0.0       0.0       0.0
TREE: 3234567   0:
    0.0       0.0       0.0
    0.0       0.0       0.0
TREE: 4234567   1:
    SOFT      SOUR      SMALL
    1.0       3.0       1.0
    0.0       0.0       0.0
TREE: 3333333   1:
    HARD      BLAND     MIDSIZE
    3.0       1.0       2.0
    0.0       0.0       0.0
TREE:    4444   1:
    FIRM      SWEET     LARGE
    2.0       2.0       3.0
    0.0       0.0       0.0
averages
TREE: 1234567   5:
    2.6       2.0       2.2
    0.5       0.9       0.7
TREE: 2234567   0:
    0.0       0.0       0.0
    0.0       0.0       0.0
TREE: 3234567   0:
    0.0       0.0       0.0
    0.0       0.0       0.0
TREE: 4234567   1:
    1.0       3.0       1.0
    0.0       0.0       0.0
TREE: 3333333   1:
    3.0       1.0       2.0
    0.0       0.0       0.0
TREE:    4444   1:
    2.0       2.0       3.0
    0.0       0.0       0.0
quit

Other points:

Suggestion: Here's a suggested sequence for development:

  1. Define some enumeration types, and use enumeration_io to read values of those types from standard input. Also print the values.
  2. Open a file whose name is specified on the command line, read enumeration values from that file, and then close it.
  3. Read and print a data file that is in the correct format.

  4. Design a data structure that holds a sequence of trees and their associated information, and design an algorithm to read and store a sequence of trees and associated data. (Algorithm + Data Structure = Program)
  5. Read trees from the data file and store them in your data structure. Don't try yet to check if a tree's ID has already been read; instead, just read and store each tree and it's data. Then print the array.
  6. Convert the characteristics (eg sweet or sour) to the correct numbers.
  7. Calculate and print mean and standard deviation for each tree and store these values in your array.

  8. Add enumeration types for commands, read values from standard input, and process those commands
  9. Correctly handle trees that are repeated in the tree data file.

Extra Credit 1 - Efficient Searching: For 5 points extra credit, implement an efficient search algorithm (eg O(1) or O(lg n). If you want credit for doing this, please put a very noticeable comment in your header comment!

Extra Credit 2 - Robustness: For 5 points extra credit, make your program robust by doing the error checking described below. If you want credit for doing this, please put a very noticeable comment in your header comment!

Style: In coming up with your Ada solution to the following problem, please follow my style guide. In particular, please note the use of consistent indentation, named constants, and descriptive constant and variable names. Please remember that the first thing in any program file should be a comment that gives a brief overview of what the file contains (and should do). Also remember to keep your lines less than 80 characters long. Not only does this mean that printouts won't run off the side of the page, but it also makes your programs look neater on an 80 column wide xterm window (a popular size). If you are unsure of an element of programming style, please ask, as I would be more than happy to show you what I want.

Submission: Use the submit command to turn your program in for grading. You may submit as many times as you like, but only the last submission is kept. In particular, be aware that since only the last submission is kept, if the last one is late, then your assignment is late and will thus receive a late penalty. Also remember that you must be on rucs for submit to work. To submit your work for grading use the command above.