CS 340 - Software Design

Machine Problem 1, Fall 2001

I Get Around

Due: Thursday, September 6, 2001 at 11:59 pm

Turnin will be enabled until Saturday 9/7/2001 at noon because of the permission problem that occurred.

In this program, you will be maintaining information about a number of transportation routes between various cities. The primary purpose of this program will be to determine a path that get a person from one city to another with the fewest amount of transfers between routes. A transfer is when a person is riding along one route and switches to another route. Ideally a person would like to make zero transfers, i.e. find a route that contains both cities. We will not care about any other factors of the routes (i.e. cost, distance, travel time, etc.). The only criteria used will be the number of transfers.

This program is basically a graph problem that uses a breadth-first search to solve the problem. You may wish to refer to a data structures text to get ideas on how your data structure should be set up. You are to write a program that will compile using the g++ compiler (i.e. in either C or C++). You will be required to submit a makefile with your program that will compile your program and create an executable called mp1.

The program is to use text input to get commands from standard input or a file. Each command will be given on its own line in the input and can be in either upper or lower case. The command will be the first non-white space character on the line. If the first non-white space character is not a command some error message should be produced. For this program, you may assume that the white-space characters are the space and tab characters. You may also assume that each line is at most 100 characters long. Each command (except for the # command) is to produce a message stating the command occurred. The commands are:

q
Quit the program.
h
Display help information for the program. This information must include all commands and a short description on how to use each command.
#
Do nothing. This indicates the command is a comment. This is primarily to be use to document the commands given in a file. The comment will be given on the same line as the # character. Any input line in which the first non-white space is a #, the input line should be ignored. Note, a line starting with a # can be given while processing input lines for other commands.
t
Specify a transportation route. On the first line after the command, the name of the route will be given. On the lines following the name of the route, the name of the cities that the route connects will be given (one city per line). Each city will be listed on its own line. Each name (whether route name or city name) will be fit entirely on a single line (i.e. names will be 100 characters or less). If the name of the route entered with a command already exists, the command is to add the given cities to the existing route. If the name of the route entered does not exist, a new route is being created. If a city name is listed multiple times for the same route, it should only be stored once with the route. The end of this command will be indicated by a line that is blank or only containing white-space characters.
f
Get commands from the specified file. The filename will be given on the following line. The commands in the file can be any command except the f command (expect future assignments to allow this recursive access). When you get the the end of the file (assuming the file does not contain the q command), your program is to continue processing commands from the standard input.

Here are a list of data files that we created. These do NOT test all possible input to your program. So you will have to create your own tests for this. Also, these files are not the only ones that will be used when grading your program.

s
Search for the path (a set of routes) that allows a person to travel from one city to another with the fewest transfers. If there are multiple paths that have the same fewest number of transfers, only one need be found. The starting city name will be given on the first line after the command. The ending city name will be given on the second line after the command. You must output the path in such a way that clearly shows the starting and ending cities, the routes taken and the cities in which a transfer takes place.
d
Delete a route. Remove the given route from the stored information. The name of the route will be given on the following line.
c
For a given city name, list all of the routes that stop in that city. The name of the city will be given on the following line. The route names are to be listed in lexicographical order.
r
For a given route, list all of the cities on that route. The name of the route will be given on the following line. The city names are to be listed in lexicographical order.
y
List the names of all cities known to the program in lexicographical order.
e
List the names of all routes known to the program in lexicographical order.
o
Write out the entire knowledge of program to a file. The file name will be given on the following line. If the file already exists, you are to append to the end of the file. The knowledge of the program is to be written such that the information can be read in using the f command. This means that the output is to be given as a sequence of t commands.

Lexicographical order is normal sorting order used for strings. All names will not be case sensitive, thus the city name of "Chicago" is the same as "chicago" or "CHICAGO" or "ChIcAgO"; however, when storing names in your program the first letter of each word must be in upper case, while all remaining letters in the name are in lower case. Thus the name given as "nEw yoRK" would be stored as "New York". Your program is responsible for any neeeded case conversions.

Also all names are to stored with no leading or trailing white space characters (white space characters are blanks/spaces, horizontal tabs, vertical tabs and newline characters - in this program, since all names will be given on a single line, only the blank/space and horizontal tabs will be considered as white space) and only a single space character is used to separate words. Thus if a name has leading white space, multiple white space between words or trailing white space, your program will have to modify the name to deal with these.

When storing a name in your program, you must allocate only an much memory as the name requires. Therefore the city name of "Chicago" must not be stored in a character array of 100 characters. You may use null terminated strings, thus storing "Chicago" in 8 characters. Since you will have to look up both route and city names, you must use some fast look-up algorithm like a hash table to quickly find the name's location in the graph.

This program will NOT require the use of multiple source code files and separate compilation. This will be manditory for all future assignments, so you may wish to try it out here. The division of the subroutines between the multiple source code files must be logical. One suggestion would be to have the graph rountines in one source code file and the command interface commands in another source code file. This suggestion only specifies two source code files, you may wish to have more that two source code files for your program. Note: a "source code file" is not the same as a "header file". Source code files will have a file extension of .c (or .cpp, .C, .CC, etc.), while a header file will have a file extension of .h. To perform separate compilation, your makefile must separately compile the source code files into ".o" files and then link the ".o" files together. Using a #include statement with a source code file (a .c file) will NOT satisfy a requirement of separate compilation.

In addition to using and submitting a makefile, this program will also require a 1-2 page write up of the data structures used in the program and the logical division of your program into multiple source code files (i.e. which routines are where). Remember that this write-up is to be written in ASCII format and is to be electronically turned in with your program. The name of this file should be "readme.txt". Also recall that your program will be given to another student to write a critique. Therefore, it is suggested that you do not include your Social Security Number in your program. Instead use your name and your CS User ID to identify yourself.

Your program must be written in good programming style. This includes (but is not limited to) meaningful identifier names, a file header at the beginning of each source code file, a function header at the beginning of the function, proper use of blank lines and indentation to aide in the reading of your code, explanatory "value-added" in-line comments, etc.

The work you turn in must be 100% your own. You are not allowed to share code with any other person (inside this class or not). You may discuss the project with other persons; however, you may not show any code you write to another person nor may you look at any other person's written code.

You are to submit this project using the CS Department's UNIX machine's turnin command. The project name for this assignment is mp1. Be sure to submit all source code, header files, makefile as well as your program description. Failure to turnin all required pieces will result in a lower grade for the assignment.