![]() |
CSE 143 Spring 2001Homework 1Due: Electronic submission by 10 pm, Wednesday April 4. Paper receipt and written report due in quiz section on Thursday April 5. |
You've been hired as a contractor to implement a small geography database. The main idea is to read a file containing a lists of places and their locations, then answer questions about distances to various places.
As with all assignments, please read the instructions all the way through before beginning. Read them once again before you turn in your assignment, to be sure you've left nothing out.
The purpose of this assignment is to review some ideas from previous courses and explore basic parts of C++.
The program should operate in two phases:
The file contains three pieces of information for each place: the x and y distances of the place measured in miles from the Center of the Universe, and the place name (a string). The Center of the Universe has x and y coordinates 0.0. The file might contain a place name with coordinates (0.0,0.0) or there might be no place with those coordinates. The x coordinate gives the east-west distance from the Center of the Universe; positive distances are east and negative distances are west. The y coordinate gives the north-south distance; positive distances are north, negative ones are south.
To keep things simple, place names are restricted to be a single string. So, for example, NewYork is a valid place name; New York (with the embedded blank), is not.
The end of the file is indicated by an entry with a place name of "." (a single period). This end marker will have x and y coordinates, but the values of these are not specified - they may be any value, positive or negative.
You may assume that there are at most 30 places in the input file (not including the end marker with the period as a place name). You should also assume that the input file contains clean data, i.e., you do not need to check for input errors like incorrectly formatted numbers, duplicate place names, etc.
Example: Here is a sample places.txt file giving distances to various Seattle neighborhoods. (These numbers are a guesstimate by the course staff and may not correspond to reality.)
-1.7 1.1 Ballard 1.0 2.0 GreenLake 2.0 0.5 UDistrict 0.0 0.0 Fremont -2.5 -1.0 Magnolia -1.0 -1.3 QueenAnn 2.4 -2.0 CapitolHill 0.5 -2.8 Belltown 8.5 -2.0 Bellevue 11.0 2.5 Redmond 28.0 -49.0 MtRainier 17.42 0.0 .According to this file, Ballard is 1.7 miles west and 1.1 miles north of the Center of the Universe; MtRanier is 28 miles east and 49 miles south of the Center of the Universe, and, of course, Fremont is the Center of the Universe.
Once the program has read the places.txt file, it should prompt the user to enter place names, look up the place name, and print the following:
The place name must exactly match the name in the database, including capitalization.
When the user is done, she should enter a single period (".") to indicate that the program should terminate execution.
Distances should be computed as floating-point numbers, not integers. The number of decimal places to print on a distance is not specified - feel free to use the default precision provided by C++ output streams.
Example: Here is a sample of what the interaction should look like, using the Seattle neighborhood data given above. User input is underlined and in italics, like this.
Enter place name: Ballard Ballard is 2.03 miles from the Center of the Universe Enter place name: redmond Never heard of redmond Enter place name: MtRainier MtRanier is 56.44 miles from the Center of the Universe Enter place name: Fremont Fremont is the Center of the Universe Enter place name: Pullman Never heard of Pullman Enter place name: .
A primary purpose of this assignment, besides learning basic C++, is for you to gain experience designing a program, including data structures, breaking the code apart into functions in some sensible way, and so forth. But there are a few specific implementation requirements - things you must do as specified here.
You should split your code into a couple of different source files, and partition your code into files so that related code is together. In particular, you will need a data structure to hold the place/location information. You will also need various functions to manipulate this data structure, for example, adding new information to it, locating the distance information given a particular place name, etc.
You must separate your source code so that the functions that process the internal details of the place data structure are in a separate source (.cpp) file from the main program. You will also need an associated header (.h) file containing declarations of the data structure(s) and function prototypes for the routines in this source file. The source (.cpp) file containing the main program should #include the header file to access the data structure definitions and function prototypes. The main program must call appropriate functions to manipulate the place/location information - it should not access the internal details itself.
cin
, cout
, ifstream
,
etc.). Do not use printf/scanf/fscanf
or other C library
functions for I/O.#include <string>
), not the
C library functions strcpy
, strcmp
, and so forth.#include "file.h"
to include header
files that you write and that are in your project folder. The angle brackets in #include
<library>
are used to indicate libraries that are part of
Visual C++ or other implementations.Part of your job as a programmer is to verify that your code works by running appropriate tests. That means more than just trying it with the example data given above. You need to invent test data that will check your program under various conditions. For example, your tests should check that the program works properly if
As part of the report you turn in with this assignment (see below), you will need to describe how you tested the program and why you believe that your tests demonstrate that it works properly.
There is no sample program for this assignment; you should create a program that works as specified. In cases where the specification is not clear, you may need to make some reasonable assumptions. Also, feel free to discuss issues about the specifications on the course newsgroup, in sections, with your colleagues, etc.
In any non-trivial project, programming or otherwise, the job can often seem overwhelming at first - too many things to do all at once and no clear idea where to start. An important skill to develop is to figure out what you can do first, without having to finish other things. Here are some suggestions.
Time spent planning and thinking at the beginning of the project will be more than repaid by time saved that would otherwise be needed to debug and fix problems.
When you turn in your program, you must also turn in a short report that discusses the following issues:
This report need not be long, but it should be complete enough to give us a good picture of what you accomplished.
When you've finished your program, turn it in using this turnin form. Print out the receipt that appears, staple it and your report together, and hand it in during quiz section.