|
C M S C 2 1 4 C o m p u t e r S c i e n c e I I S p r i n g 2 0 0 2 |
Early Bonus Date Thursday, November 7th, by 11pm (+5 points)
Click above before submitting (LINK not ready).
You are expected to read FAQ on a daily basis.
Get started right away.
Please note that *all* programming projects in this course (including this one) are to be done independently or with the assistance of the instructional staff of this course only.
Please review the policies outlined on the class syllabus concerning the use of class computer accounts and concerning the University's Code of Academic Integrity. The instructors of this course will review the programs submitted by students for potential violations of the Code of Academic Integrity and if it is believed that a violation has occurred it will be referred to the Office of Judicial Programs and the Student Honor Council.
Hardcoding is considered a violation of academic integrity
Interestingly, a binary search three also implements this same interface. From the class user's point of view, a SortedList implemented as a doubly linked list and a SortedList implemented as a binary search tree are the same. While, you, the implementer will notice the differences right away, the user of the class should not notice the difference in functionality.
The user of the class never has to know exactly how SortedList is implemented, unless they really are concerned about efficiency of the operations.
Good coding practice suggests that you "program to an interface". This is easier done in Java than in C++, but the idea is that an interface (which is a list of public methods defining an abstract data type (ADT)) allows many implementations, and you can simply substitute the appropriate implementation as needed without chaing the interface.
We won't quite do this in this project, but you should appreciate the idea of a binary search tree is implementing a SortedList interface, and that semantically, a user only needs to know it's a sorted list.
Note: Implementing BstMap will be worth up to 5 points of the project. If you find yourself pressed for time, you may wish to skip the implementation of this class.
Since the game has only small changes, you should get the commands to work, and finish that up.
Debug code as needed.
Answers should be typed in TreeExercise.answers. The purpose of this is to help you understand BSTs before writing any code. This is often a good exercise. Once you understand the "theory", it should be easier to write the code.
Here are the specifications: ArrayList
Task 5: Except for Tokenizer, replace all STL vectors
with ArrayList.
You can add new features to ArrayList, but only if
comparable features exist in vector. The changes should
make sense for vectors, and not be entirely specific to this
project (i.e., don't assume you are carrying ArrayList of
Item objects).
The purpose is to stress-test your ArrayList and to show your ArrayList is roughly comparable to a vector.
Task 6: Write MovieBstSortedList unit test
Name the file BstSortedListMovieUnit.cpp and BstSortedListMovieUnit.h. Initially, you will unit test a MovieBstSortedList, but then convert it to BstSortedList<Movie, MovieComparator> after you are done templatizing. The unit tests should remain identical, except for this change.
Come up with at least 5 tests (10 tests should be easy enough, given the number of methods).
Task 7: Implement MovieBstSortedList
Here is the MovieBstSortedList
Specifications.
You will be provided a MovieBstSortedList.h file. You may wish to use a shorter name when writing this code, as you won't submit this However, it's easier to write and debug non-templatized code, which is why you're asked to implement a non-templatized class first.
(10/27) Add string getTitle() const method to Movie. Notice that Movie does not define operator<. DON'T define it. This will give a reason to use the MovieComparator class which will have to use getTitle() and do the comparison in MovieComparator (which it should do case-insensitively).
If you use left standard or right standard, you may either choose to copy the data of the replacement node (i.e., the predecessor or successor) and overwrite the node that's being removed, or actually remove and delete the node to be removed, and put the replacement node in its place. (This technique has been discussed in class and lab, and should be in the book).
Remember to handle pred and succ pointers.
Also, one variation when removing a node with one subtree is to always "pull" up the remaining subtree. Otherwise, if you are using, say, left predecessor, you can still use that technique provided there's a left subtree, and pull up the right subtree, if there's not.
In the README, you will describe which remove() method you used.
Task 8: Templatize MovieBstSortedList into BstSortedList
and use BstSortedList<Item, ItemComparator> in place of
SortedList<Item, ItemComparator>.
You will be given a partial BstSortedList.h and
BstSortedList.cpp. The rest should be filled out by you
using MovieBstSortedList as a guide.
To show that SortedList and BstSortedList implement the same interface, you will replace SortedList<Item, ItemComparator> by BstSortedList<Item, ItemComparator>.
Task 9: Add new features to the game.
Add features to the game as described below. They are
mostly minor.
Task 10: Implement BstMap class. (Extra Credit: +5 points)
This is extra credit. Given a BstSortedList template
class and a Pair class, create a BstMap class.
This class behaves like the SimpleMap class, but is implemented
using pairs and BSTs, which is similar to how map classes are
implemented in STL.
Here is the BstMap Specifications.
These facts are from P2, but placed here for additional clarity.
New changes to the game.
This is now modified to indicate players and food items on target squares.
Input BNF is the same as before:
The output BNF is:
<targetinfo-out> := [ "Player is on target square at " <coord> ]?
"BOXES ON TARGET" <endl>
"----*----*----*" <endl>
[ <target-list> | <no-target-list> ]
<endl>
"EMPTY TARGET SQUARES" <endl>
"----*----*----*----*" <endl>
[ <empty-target-list> | <no-empty-target-list> ]
"FOOD TARGET SQUARES" <endl>
"----*----*----*----*" <endl>
[ <food-target-list> | <no-food-target-list> ]
<target-list> := [ " " <box-color> " " <coord> <food-target> <endl> ]+
<food-target> := [ " " <brack-name-of-item> ]*
<brack-name-of-item> := "[" <name-of-item> "]"
<name-of-item> := <word> [ %% <word> ]*
<food-target-list> := [ <brack-name-of-item> " " <coord> <endl> ]+
<empty-target-list> := [ " " <coord> <endl> ]+
<no-target-list> := " No BOXES lie on target squares" <endl>
<no-empty-target-list> := " There are NO empty target squares" <endl>
<no-food-target-list> := " No FOOD ITEMS lie on target squares" <endl>
The input BNF is:
<history-in> := % HISTORY [ %% <udigit> ] % <endl>
HISTORY can either be a command by itself (with no arguments)
or can take a single argument. The single argument is a positive
number, which indicates which run the command to run.
If the user enters HISTORY with no commands, then the list of commands by the user is printed out. Only VALID commands are listed (invalid commands are not listed). The last command
This is the output BNF of HISTORY without arguments, which
appears after the command echo.
<history-out> := " Command History" <endl>
" ----*----*----*" <endl>
[ " (" <udigit> ") [" <command-list> "]" <endl> ]+
<command-list> := [ <word> | <dquote-word< ]
[ " " [ <word> | <dquote-word< ] ]+
The command list is the command echo, which puts a single space between
the commands and each of its arguments. However, double quoted
arguments still preserve spacing. The number of the command is
the same number used in the command echo.
The last command will be the HISTORY command itself.
What happens if you run a command like DISPLAY by using, say, HISTORY 3, followed by HISTORY again? Instead of printing HISTORY 3 in the Command History output, you will print the command that was numbered 3 (preserving the capitalization as in command 3).
The command echo will be [HISTORY 3], however, when future calls to the HISTORY command are called, you will see [DISPLAY] for the same number (or whatever was command 3).
There are simple ways to implement this command. First, you can have an ArrayList of strings, which represent the command, or better yet, create some sort of History class which has an ArrayList (of Command objects) data member, and perhaps create a Command objects which stores the command.
Storing a list of commands allows re-execution of old commands, and potentially, with work, allows you to "undo" commands. However, you will NOT undo commands in this project.
You can now pick up all items on a box (in addition to picking up indidivdual items as in P2). You may assume that boxes do not have the same names as food items.
The input BNF is:
<pickup-cmmd2> := % "PICKUP" %% <box-color> % <endl>
The output BNF for this is:
<pickup-out2> := <pickup-good2> | <pickup-nobox2>
<pickup-good2> := " Player successfully picked up ALL items on ["
<box-color> "] " <dir8>
" of player at " <box-coord> <endl>
<box-coord> := <coord>
<pickup-nobox2> := " PICKUP ERROR. Player not adjacent to box ["
<box-color> "]" <endl>
Even if there are no items on the box, you can say the player
successfully picked them all up, as long as the player is adjacent
to the box (in one of 8 directions).
You should add the items to the player's list at the END of the list (recall the player stores item in the order that was picked up, and the box also stores items in the order placed on the box).
Once the command is complete, the box will hold no items.
As in P2, <coord> refers to the coordinate of the box
In P2, a player could drop one item on a box. Now, a player can drop all items on a box (this is an additional feature of the DROP command).
This is the input BNF.
<drop-cmmd> := % "DROP" %% <box-color> % <endl>
This is the output BNF.
<drop-out2> := <drop-good> | <drop-nobox2>
<drop-good2> := " Player successfully dropped ALL items on ["
<box-color> "] " <dir8>
" of player at " <coord> <endl>
<dir8> := "NORTH" | "SOUTH" | "EAST" | "WEST" |
"NE" | "NW" | "SE" | "SW"
<drop-nobox2> := " DROP ERROR. Player not adjacent to box ["
<box-color> "]" <endl>
Again, even if the player is not carrying any items, you
still print the player dropped all items if the player is
adjacent to a box in one of eight directions.
This should be added at the end of the ArrayList of food items for the box, in the same order that the player was carrying the items. Thus, if the player picked up a "doughnut", then a "bagel", the "doughtnut" and "bagel" are added at the end of the list of items on the box, in that order.
As in P2, <coord> refers to the coordinate of the box
Furthermore, the box color or item name can also be in any case. You should print the output BNF for the box color and item name using the same case as in the command from the input file.
If a player wants to pickup a BAGEL, or bagel, or Bagel, from a "red" or "RED" or "ReD" box, this should work, provided there is a bagel on a red box adjacent to the player.
Also, make sure any class that USES a template class adds the .cpp file as a dependency. For example, if Foo.mine.cpp or Foo.mine.h uses a ArrayList<int>, list BOTH ArrayList.h and ArrayList.cpp as dependencies.
Also, for ArrayList, it's a good idea to print a message indicating you've gone out-of-bounds, if the index is out-of-bounds. Notice that regular arrays won't tell you such things.
Also, if your executable exceeds about 5 M, you should
make sure that you run:
unlimit filesize
which allows the files to be as large as your quota permits.
This command has to be run each time you log in.
This prevents core dumps because of excessive file sizes.
If you use the -g option, the size of the executable will be much larger, so use this option only when you need to use the debugger.
Furthermore, for quota purposes, go to earlier projects and remove .o files, executables, etc. If you have space in your WAM account, you may wish to copy files of earlier projects there, to back them up (again, removing .o files). Remove core dumps too.
You may also wish to gzip your tar file. This compresses your file, and addds a .gz extension. You say something like gzip p1.tar and it creates p1.tar.gz. You can uncompress it by saying gunzip p1.tar.gz.
As a precaution:
Extensions are unlikely to be given for anyone who accidentally deletes files. You can ask, but we reserve the right to refuse. So be extremely careful.
ladebug p3 coreand type "where" to indicate what happened. This will print the stack, where main() appears at the bottom. You should look at the line numbers and the arguments. Pay close attention to 0x0 which indicates a NULL pointer. Often, core dumps occur when you go out of bounds on an array or linked list, and perform some operation on a NULL pointer or invalid memory.
Unfortunately, rathet than indicate that this operation is happening on invalid memory, it prints that the operation has core dumped. If the method is particularly simple, you may need to look at what calls the method to debug it.
A successful SUBMISSION of your tar file does NOT always guarantee you have passed the primary input
This is why you should test your tarfile prior to submission.
In order to successfully submit your project, it must pass
the primary input and produce the primary output. The primary
input will be sent to your project using input redirection.
p3 < primary.input
Your program MUST produce the executable p3, EXACTLY, when
the command "make p3" is run. Thus, you must use
a makefile named exactly "Makefile".
Your program must use cxx with the options -w0 -std strict_ansi. Unfortunately, while we have aliased this for you, it doesn't always work with Makefile, so use the full name in your makefiles.
We will use "diff -bwi" to test your code. This ignores case, treats N blanks as 1 blank, treats N blank lines as 1 blank line. We will also strip all blank lines from your input when matching to ours. However, diff is sensitive to punctuation, number of dashes, etc. so you should attempt to make your output match ours as closely as possible otherwise you may not be able to submit your program. If this is the case (that your program does not submit) you must fix your code until the output it produces matches that of the primary output. Note: "hardcoding" output is a violation of the University's Code of Academic Integrity.
To submit your project you must first combine the following files (and only these files) into a single tar file using the Unix tar command:
You may name your tarfile anything you want, but p3.tar is the suggested name.
NOTE! You should make a backup copy of all your files BEFORE attempting to create your tarfile!!!! You have been warned.
After creating the tar file you should submit that one file using
the following command:
submit p3.tar 3
where p3.tar can be replaced by whichever tar file you
have created, and 3 refers to the current project,
|
See the class syllabus for policies concerning email Last Modified: Mon Mar 18 20:39:55 EST 2002 |
|
|
|
|
|