RU beehive logo ITEC dept promo banner
ITEC 320
2018fall
nokie
ibarland

arrays 2-D
itec320 hw04 (tethered)

Due: 2018-Oct-16 23:5915 15:00, D2L and hardcopy
10% extra-credit if submitted before break, by Oct.14 23:59.

Updates: ignoring formatting and minor phrasing changes Last modified

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

This programming assignment is similar to shop.html, but there are several important differences:

Sample Run:

Here is a sample run of the program. Assume that this sample input data is in the file in7.txt:

3 14 8 98 3 16 3 15 2 3 2 1 2 2 5 97 5 98 5 99 7 1 7 2 7 8 7 9 8 97 8 99 9 95 9 96 9 97 11 2

Assume that you run the program from the command line, with the input redirected from this input file, as follows: rucs% tethered < in7.txt Then this will be the resulting output:

Tethered: Continue and enter aisle 2 at 0 and proceed to location 3, traveling 3 Reverse and enter aisle 3 at 0 and proceed to location 16, traveling 19 Reverse and enter aisle 7 at 0 and proceed to location 9, traveling 25 Reverse and enter aisle 11 at 0 and proceed to location 2, traveling 11 Continue and enter aisle 9 at 100 and proceed to location 95, traveling 103 Reverse and enter aisle 8 at 100 and proceed to location 97, traveling 8 Reverse and enter aisle 5 at 100 and proceed to location 97, traveling 6 Continue and exit aisle 5 at 0 and proceed to cashier, traveling 97 Aisle count: 7 Total distance: 272 Average: 38.9 Untethered: Continue and enter aisle 2 at 0 and proceed to location 3, traveling 3 Reverse and enter aisle 3 at 0 and proceed to location 16, traveling 19 Continue and enter aisle 5 at 100 and proceed to location 97, traveling 87 Reverse and enter aisle 7 at 100 and proceed to location 1, traveling 102 Continue and enter aisle 8 at 0 and proceed to location 99, traveling 100 Continue and enter aisle 9 at 100 and proceed to location 95, traveling 6 Continue and enter aisle 11 at 0 and proceed to location 2, traveling 97 Reverse and exit aisle 11 at 0 and proceed to cashier, traveling 2 Aisle count: 7 Total distance: 416 Average: 59.4


Notes:

As in the previous assignment, the last line in each group is different from the others, even though bits of it should align with the previous lines. It will always contain “exit” and “at 0” and “cashier, ”.

Input specification:
  1. Input is a sequence pairs of natural numbers, each of which represents an aisle and location.
  2. Aisle numbers can be in any order, and within an aisle, location numbers can be in any order.
  3. Reading continues until end_of_file.
  4. Aisle numbers to process will be between 1 and 1_000, inclusive.
  5. Location numbers will be between 0 to 100, inclusive.
  6. There will always be at least one item in the near-half of some aisle, and at least one item in the far-half of some aisle to process.
    For some extra-credit: Have your code work even without the in-each-half guarantee (and perhaps even without needing any items at all!). (Mention this feature in your comments, so we'll know to look for that.)
  7. Your program does not need to check for errors in the input.
  8. Your program is to read from stdin (which is the default for Ada.Text_IO.Get).

Output specification: Essentially the same as the previous assignment.

Distance:

  1. Aisles are of course numbered starting from one. Within an aisle, we'll number locations from 0 to a maximum amount (for this assignment, 100). You might think of location 0 being the end of the aisle near the front of the store, and the maximum-location-number as being at the back of the store.

    Locations do not have any width; for example, within an aisle, location 20 is distance 20 from location 0, and is distance 80 from location 100. Locations 0 and 100 are themselves valid locations (You might think of them as endcaps).

  2. You can assume that you begin walking at aisle 1, location 0.
  3. Only consider the distance that you walk up an down the aisles. Do not include the distance walked from one aisle to the next.
  4. As in the previous assignment, after processing the locations in an aisle, if going either direction results in the same distance, then you should continue in the direction that you are going (i.e. continuing going forward, instead of reversing). This of course applies only to the non-tethered version.

Extra credit:

Specify verbose vs quiet execution with a command line argument. Here are some example executions:

   > tethered -q < p2.txt
   > tethered -v < p2.txt
   > tethered --quiet < p2.txt
   > tethered --verbose < p2.txt
   
Quiet mode is to print only the 3 line summary for each method. Verbose mode is to print the output specified in the assignment (i.e.verbose is the default3. Invalid flags should be reported with warnings. Here and here are examples of using the command line. If more than one flag are given, your program can do anything (including crash), but please mention the behavior in a comment, as well as what more-desired behavior you might implement had you more time.

Other points

  1. You must use a 2D array of booleans (or an array of arrays of booleans).
  2. You must break decompose your program into procedures and functions.

  3. You must define appropriate types or subtypes for aisle-numbers and locations.
  4. You must define a type to represent which end of the aisle you use, rather than 0 or 100. (I called the two values of that type near and far.)

  5. Use named constants as appropriate.

  6. Use good variable-names ("self-documenting").
  7. Do not store the locations in a collection of any kind (e.g. no arrays and no lists).

  8. Read numbers using numeric I/O, not by reading the input as one or more strings.
  9. Make sure that your program reads from stdin, not from a file whose name is specified in the program.

  10. Your program should be called tethered.adb

  11. See the previous assignment for information on creating data files, standard input, (stdin) redirection, end of file for intereactive input, and good style.
  12. For more information on redirecting input, see final section of www.radford.edu/itec320/2018fall-ibarland/Homeworks/shop.html

Partial Credit:

One of the difficulties of the tethered algorithm is changing from processing the near-ends (Location 0) to processing the far-ends (Location 100) of the aisles. There are two simplistic ways of doing this that simplify the problem a little. You might want to try one of them first.

  1. Always go to the very-last aisle and walk all the way down it to get to the other end of the aisles (i.e. to start processing the far ends of the aisles).
  2. Treat the last aisle processed before turning around the same as any other, and then turn around. In other words, if aisle 11 had locations 2 and 99, go from 0 to 2, reverse back to 0, then move to 100, then to 99 and reverse to 100 (whew -- definitely not optimal!).


1 Maybe the shopper is a Roomba, and its power-cord only reaches halfway down an aisle. Or, maybe the store's wireless has a dead spot at the middle of each aisle, keeping the reddit-reading-shopper from wanting to cross that zone.      
2 This is so that immediately after reading that last number, end_of_file will return True.      
3 Traditional Unix programs are quiet by default, and verbose only with a flag. However, we have backwards compatibility with the non-extra-credit version to consider.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.