copyright Steve J. Hodges   http://steveh.net/cs20j/cs20j-hw06.html

Spring 2019

Assignment 6 (Save the Wumpus)

Directory Name

20j-6

Class with Main

WList

Resources

A sample input textfile

Background

The Wumpus is a stinky creature that lives in dark caverns.

Wumpus hunting became a popular sport in 1972 when Gregory Yob developed a game called Hunt the Wumpus— the first computer game written for a microprocessor. In 1980, the sport was described in Basic Computer Games by David H. Ahl, and Wumpus hunting became all the rage. The Wumpus was nearly hunted to extinction. The Wumpus was saved when it was declared an endangered species under environmental protection laws.

You have been hired, as part of a team, to monitor the recovery of the Wumpus. As a Wumpus is discovered, it is named and tagged with a radio transmitter. You will write a program that receives information about a Wumpus and its current location (x and y coordinates between -1000.0 and 1000.0). You will store the data in a customized linked list.

Program Description

Define a class called Wumpus that has double values for x an y coordinates and a string that names that Wumpus. Add appropriate member functions to allow the values to be accessed. Add a toString() method so that your Wumpus can be conveniently printed (see below for required formatting.) Add an equals() function to test for equality (defined as two Wumpii having the same name.) Your Wumpus should have a copy constructor. Add other member functions as you deem appropriate.

Define a class called WList that implements a 3-class Linked List (as described in class) that can store objects of type Wumpus. The WList class must support at a minimum, the following functions:

Write a main() function in your WList class that reads the input from a textfile. The filename will be provided on the command line as the only argument to your program. If no filename is provided on the command line, read the input from STDIN instead. A sample input textfile will be provided. The format for input is one entry per line. Each entry consists of a character string followed by two doubles each separated by one or more spaces. The string is the Wumpus name, and the doubles represent the x and y coordinates of the Wumpus. Your main program should read all the entries from input, "spotting"each wumpus, calling printList() after the input is completed.

Output

Your program may be tested by another program (not a human being). Your program must follow the following output specification exactly.

  1. The first two lines output by your program will be ignored. This is where you can print out the program name, your name, etc.
  2. One per line, output the name of the wumpus followed by a space, the x coordinate followed by a space and the y coordinate. The x and y coordinates should be printed with two places after the decimal.
  3. The wumpii should be printed in reverse order of discovery (newest first.)

sample output line

Fido 5.60 7.30

Extra Credit Possibilities

  1. Keep the Wumpii in the list in alphabetical order. Add a data member to the Wumpus class so that the Wumpii are numbered as they are discovered. Your printList function must print them alphabetically, and each line should begin with a pound sign followed immediately by an n-digit integer id that gives the order identified and a single space. (Where n is the minimun number of digits to count each wumpus.)
  2. Add a data member to the Wumpus class that is equal to the total straight line travel distance between the observed Wumpus locations (for that Wumpus.) Add this information to your output, printing one place after the decimal. At its initial sighting, the wumpus has traveled a distance of 0.0. Each subsequent sighting will add the distance traveled from the previous location.

sample output line with both extra credit options

(assuming between 10 and 99 wumpii in the list)
#03 Fido 5.60 7.30 12.5