|
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 Due Date Friday, April 5th, by 11pm
(5 points bonus)
Third Posting: March 22, 2002
(Tutorials added)
Second Posting: March 20, 2002
(Task 10 modified--distribution of proposals changed)
Originally Posted: March 18, 2002
(BNF and tutorials posted soon)
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
Note: "How Locate Works" has been updated as of March 21, 2002. There's a simpler way to write locate().
Note: Implementing BstMap will be worth up to 7 points of the project. If you find yourself pressed for time, you may wish to skip the implementation of this class.
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", you have a much better chance at implementing the code.
In this example, x and y are both ConstIterators. You can now assign iterators of the same type. This was missing from Project 2.
Each operation can now handle dereferenced iterators where iter is a ConstIterator pointing to a valid element of a SortedList object.
Also when printing or reverse printing a list, print the
message:
EMPTY LIST
if the list is empty (this is to replace the phrase "THERE
ARE NO MOVIES IN THIS LIST").
If you are printing using two ConstIterator and the
two iterators point to the same node, then print:
NO OBJECTS IN THIS RANGE
instead of the previous phrase ("NO MOVIES IN THIS RANGE").
This will make it more general.
<msl_in1> := "SORTED" <seps> RUN <seps> <var> <seps> "=" <seps> <var>
<msl_in2> := "SORTED" <seps> VERIFY <seps> <var> <seps> "." <seps>
[ "add" | "remove" | "contains" | "update" ]
<seps> "(" <seps> "*" <seps> <var> <seps> ")"
where <msl_in1> the two variables are ConstIterator
objects, and where the first variable in <msl_in2> is a
SortedList<Movie, MovieComparator> object, and
the second variable is a ConstIterator object.
<msl_out1> := "SORTED RUN " <var> " = " <var>
<msl_out2> := "SORTED VERIFY " <var> "."
[ "add" | "remove" | "contains" | "update" ]
"( * " <var> " ) "
[ "IS SUCCESSFUL" | "FAILS" ]
where <msl_out1> the two variables are ConstIterator
objects, and where the first variable in <msl_out2> is a
SortedList<Movie, MovieComparator> object, and
the second variable is a ConstIterator object.
Notice the output for this "echoes" (mimics) the input.
MovieArrayListTester
In this example, x and y are both ConstIterators or both Iterators. You can now assign iterators of the same type. This command was missing from Project 2.
(CORRECTION 3/21): this should be a RUN operation, not VERIFY.
You can now push back elements of ArrayList<Movie> objects (in addition to plain Movie variables). You may assume the index and ArrayList object are both valid.
(CORRECTION 3/21): this should be a RUN operation, not VERIFY.
You can now push back elements of dereferenced iterators, both Iterator and ConstIterator.
<mal_in1> := "ARRAY" <seps> "RUN" <seps>
[ <mal_in1a> | <mal_in1b> ]
<msl_in1a> := <var> <seps> "=" <seps> <var>
<msl_in1b> := <var> <seps> "." <seps> "pushBack" <seps> "(" <seps>
[ <var> <seps> "[" <seps> <udigits> <seps> "]" |
"*" <seps> <var> ]
<seps> ")"
where the two variables in <msl_in1a> are both
Iterator or both ConstIterator objects. For
<msl_in1b>, the first variable is an
ArrayList<Movie> object, and in the first option,
the second variable is a ArrayList<Movie> object,
and the variable in the second option is a Iterator
or ConstIterator object.
<mal_out1> := "ARRAY RUN " [ <mal_out1a> | <mal_out1b> ]
<msl_out1a> := <var> " = " <var>
<msl_out1b> := <var> ".pushBack( " <seps>
[ <var> [ " <udigits> " ]" | "* " <var> ]
" )"
The output pretty much echoes the input. Notice the output BNF
looks very similar to the input BNF.
Note: You should convert "NO MOVIES IN THIS RANGE" to "NO OBJECTS IN THIS RANGE" for the corresponding spot.
Task 4: 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 this).
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.
As you implement each function, document this in BstSortedList.doc. You will find
that it's less painful to document if you do it after (or
before) each function.
Task 5: Templatize MovieBstSortedList into BstSortedList
You will be given a partial BstSortedList.h and
BstSortedList.cpp. The rest should be filled out by you
using MovieBstSortedList as a guide.
Task 6: Create MBSLTester which is the tester class
for BstSortedList
This class should support all of the operations from
MovieSortedListTester from Project 1 and 2 (and 3).
Notice that BstSortedList supports the same operations
as SortedList (plus a few more).
BstSortedListTester
Declare a variable x of type BstSortedList<Movie, MovieComparator> using the default constructor.
<bst_in1> := "BST" <seps> "DECLARE" <seps> <var>where the variable is a BstSortedList<Movie, MovieComparator>
<bst_out1> := "BST DECLARE " <var> <endl>The syntax is similar to MovieSortedListTester.
Declare a variable x of type BstSortedList<Movie, MovieComparator> using the copy constructor. y is a previously declared BstSortedList<Movie, MovieComparator> object.
<bst_in2> := "BST" <seps> "DECLARE" <seps> <var>
<seps> "=" <seps> <var>
where the two variables are BstSortedList<Movie,
MovieComparator>.
Assignment operator on two BstSortedList<Movie, MovieComparator> objects, x and y.
<bst_in3> := "BST" <seps> "RUN" <seps> <var>
<seps> "=" <seps> <var>
where the two variables are BstSortedList<Movie,
MovieComparator>.
<bst_out3> := "BST RUN " <var> " assign" <endl>(4/5) CORRECTION The original version was correct. This copies two BstSortedList. This now matches the description in Project 1.
Runs clear() method on x.
<bst_in4> := "BST" <seps> "RUN" <seps> <var>
<seps> "." <seps> "clear"
<seps> "(" <seps> ")"
where the variable is BstSortedList<Movie,
MovieComparator>.
<bst_out3> := "BST RUN " <var> " clear" <endl>
where x is a BstSortedList<Movie, MovieComparator> object and movieVar is a Movie variable.
<bst_in5> := "BST" <seps> "VERIFY" <seps> <var>
<seps> "." <seps>
[ "add" | "remove" | "contains" | "update" ]
<seps> "(" <seps> <var> <seps> ")"
where the first variable is BstSortedList<Movie,
MovieComparator> and the second variable is a Movie
variable.
<bst_out5> := "BST VERIFY " <var> <bst_vmethod> [ "IS SUCCESSFUL" | "FAILS" ] <bst_vmethod> := " add " | " remove " | " contains " | " update "
Again, the output is similar to MovieSortedListTester.
where x is a BstSortedList<Movie, MovieComparator> object and iter is a BstSortedList<Movie, MovieComparator>::ConstIterator variable.
<bst_in6> := "BST" <seps> "VERIFY" <seps> <var>
<seps> "." <seps>
[ "add" | "remove" | "contains" | "update" ]
<seps> "(" <seps> "*" <seps> <var> <seps> ")"
where the first variable is BstSortedList<Movie,
MovieComparator> object and the second variable is
a ConstIterator object.
<bst_out6> := "BST VERIFY " <var> "."
[ "add" | "remove" | "contains" | "update" ]
"( * " <var> " ) "
[ "IS SUCCESSFUL" | "FAILS" ]
This is a similar output shown above for MovieSortedList in Task 3 above.
<cmmd> BST VERIFY mList
<list>
"BATMAN" 3000
" Go Go" 1000
" RUN THERE" 2000
</list>
</cmmd>
Again, as in Project 1, the titles and earnings must match in exactly the same order as saved in the BST (i.e., by doing an inorder traversal).
<bst_out7> := "BST VERIFY " <var> " LIST "
[ "IS SUCCESSFUL" | "FAILS" ]
where the variable is a BstSortedList object.
<cmmd> BST VERIFY iter1 iter2
<list>
"BATMAN" 3000
" Go Go" 1000
" RUN THERE" 2000
</list>
</cmmd>
where iter1 and iter2 are both BstSortedList<Movie, MovieComparator>::ConstIterator iterators, and iter1 is either BEFORE or at the same location as iter2. This checks elements from iter1 all the way up to, but not including, iter2. You may assume they point to valid elements of a BstSortedList<Movie, MovieComparator> object.
<bst_out8> := "BST VERIFY " <var> " " <var> " CONST_ITERATOR "
[ "IS SUCCESSFUL" | "FAILS" ]
where the two variables are BstSortedList::ConstIterator objects.
This allows you to declare iterator (initialized to NULL). It allows you to assign one iterator to another iterator (both are const iterators). It allows you to assign to a beginning of a list, and to past the end of a list, and to the last element of a list.
<bst_out9> := "BST CONST_ITERATOR DECLARE " <var>where the variable is a BstSortedList object.
For the RUN methods, you can make similar assignments as DECLARE. You can also move iterators forward or backward by a constant (which can be assumed to be non-negative). You must determine x is an iterator object. You can assume iterator variable names are distinct from other variable names. y is an iterator object and list is a BstSortedList object.
Notice that operator+=() and operator-=() have NOT been defined for SortedList. You must simulate these operation using the operators that have been defined for SortedList. In this respect, the this does not perfectly match with the operations of the SortedList template class.
<bst_out10> := "BST RUN " <var> " assign CONST_ITERATOR"where the variable is a BstSortedList object.
<msl_out1z> := "BST RUN " <var> " = " <var>where the two variables are BstSortedList::ConstIterator objects.
The first one will call the print() method of the BST, which will print the structure of the BST object, tree.
Assume x and y are ConstIterator objects, this
will print the elements from x up to, but not including
y. It will be printed out in the format of a normal print.
(1) "Gone With The Wind" Earnings: 2000
(2) "Matrix" Earnings: 3000
If the ConstIterators point to the same element, then print
NO OBJECTS IN THIS RANGE
The REV_PRINT assumes that x appears AFTER y, so it
will print the list in backwards starting at x, up to, but not
including y. Thus, you will set the iterator to point to
x, then iterate backwards using the -- operator, until
you reach y, although y will not be printed (since it is
NULL).
(1) "Matrix" Earnings: 3000
(2) "Gone With The Wind" Earnings: 2000
Again, if they point to the same object, print
NO OBJECTS IN THIS RANGE
<bst_in11a> := "BST" <seps> "PRINT " <seps> <var> <bst_in11b> := "BST" <seps> "PRINT " <seps> <var> <seps> <var> <bst_in11c> := "BST" <seps> "REV_PRINT " <seps> <var> <seps> <var>where the variable in <bst_in11a> is a BstSortedList object, and the two variables in <bst_in11b> and <bst_in11c> are BstSortedList::ConstIterator objects.
<bst_out11> := "BST " [ "PRINT " | "REV_PRINT " ]
<var> " " <var> <endl>
[ [ "(" <udigits> ") " <dquote> <title> <dquote>
" Earnings: " <udigits> <endl> ]+ |
"NO OBJECTS IN THIS RANGE" <endl> ]
<title> := <word> [<blank> <word>]* [", " <word>]?
(4/2) (CORRECTION)
If PRINT is called with one argument, this means it's
a BstSortedList object. In that case, use the print method
provided to print the structure of the tree (no way to write a simple
BNF for that!). If it has two arguments, then there are two iterators.
In that case, number the outputs just as you did for project 2.
These will call the printInorder(), printPreorder(), and printPostorder() methods, respectively, on tree, which is a BstSortedList object.
<bst_out12> := "BST " [ "PRINT_INORDER" | "PRINT_PREORDER" | "PRINT_POSTORDER" ] <var> <endl>
[ "[PRINT_INORDER]" | "[PRINT_PREORDER]" | "[PRINT_POSTORDER]" ] <endl>
[ [ "(" <udigits> ") " <dquote> <title> <dquote>
" Earnings: " <udigits> <endl> ]+ |
"EMPTY LIST" <endl> ]
<title> := <word> [<blank> <word>]* [", " <word>]?
(4/3) CORRECTION The name of the tree
should be printed at the end of the first line printed.
This will print the height of the tree, and the size of the tree, respectively, in the following format.
The height of 'tree' is 2.
where 'tree' is replaced by the name of the BST
variable, and the correct height printed.
'tree' contains 20 nodes.
where 'tree' is replaced by the name of the BST
variable, and the correct number of nodes is printed.
<bst_out13> := "BST PRINT_HEIGHT " <var> <endl>
"The height of " <squote> <var> <squote>
" is " <udigits> "." <endl>
<bst_out14> := "BST PRINT_SIZE " <var> <endl>
<squote> <var> <squote>
" contains " <udigits> " nodes." <endl>
(4/5) CORRECTION Removed the additional variable
in PRINT_HEIGHT.
The first command determines whether the height of a BST object is equal to some value (e.g., 4 in this example). The second command determines whether the number of nodes in a BST object is equal to some value (e.g., 4 in this example).
The height of 'tree' is 2.
where 'tree' is replaced by the name of the BST
variable, and the correct height printed.
<bst_in15> := "BST" <seps> "VERIFY" <seps>
"==" <seps> <var> <seps> "."
<seps> [ "height" | "size" ] <seps>
"(" <seps> ")" <seps> <udigits>
<bst_out15> := "BST VERIFY == " <var> " . "
[ "height" | "size" ] " ( ) " <udigits>
[ "IS SUCCESSFUL" | "FAILS" ]
(4/2) CORRECTION Added <udigits> to
end of output BNF.
(4/3) CLARIFICATION The <udigits> should refer to the number from the input file (i.e., the height or size entered from the input file), not the actual height or size.
Task 8: Write the header, test driver, and sample output for a second
class.
Pick a different simple class. This time, write a header file.
Leave the data members blank (although you can write it in a comment).
Write public methods only. One of the public methods should be
runTestDriver().
In the implementation file (the .cpp file), place the
implementation of runTestDriver() at the top. For at least
two other functions, write pseudocode using comments only. For
example:
int Foo::bar( int x )
{
#ifdef FOO_bar
// Set temp to x
// Search through array for x
// if ( x is found )
// return index
// else
// return -1
#endif
x++; // Dummy modification to make compiler happy
return 0; // Dummy return value to keep compiler happy
}
Also, include the documentation for the class in a file called
Foo.myclass.doc where Foo is replaced by the name of
your class. This file can leave the data members empty, and
not have any private methods.
Finally, write a file called Foo.driver.output where Foo is replaced by the second class name, and represents the output your class should produce, if the runTestDriver() were running. Thus, you are attempting to predict what behavior your class will have, without implementing it.
The purpose of this exercise is to get your to (a) get you to think about how a class behaves, without worrying about the implementation, and (b) forcing that behavior to be "concrete" by writing a test driver for that class.
You don't have to make the output "perfect". It is merely an exercise to get you to think about the class. Finally, the output should be non-empty. Your test driver should (theoretically) produce some output.
REMEMBER: don't implement this class. Just have a header file, the documentation, a simple implementation file.
The implementation file MUST be called Second.cpp. However, the class inside this file should be something reasonable (for example, you might define a Name class inside). The header file (the .h file) should be named Foo.h where Foo is replaced by the name of your class. Second.cpp will #include the header file with the name you've given.
Make sure the implementation file compiles (this may require returning dummy values in functions). Fortunately, you do not need to implement the entire code for the file to compile.
To test your code, we will simply compile Second.cpp
to see if it produces a .o file. Clearly, this code won't
run, but it's done to make sure you have some meaningful code
in your test driver. You should make the same check.
Task 9: Put old code in a file called Review.txt
This file should contain:
// locate() without recursion .... code here // locate() with recursion .... code here // add() without recursion .... code here // copy() without recursion .... code hereThis will be used to see how your code changed since Project 1.
In a file called Proposal.critique, place the following
information:
// Project 3 -- Proposal Critique
//
// Name: < your name>
// Login ID: < your login>
// Section: < your section>
//
I evaluated the following proposals:
-- AAA
-- BBB
I received the following critiques:
-- bt14299
-- bt14302
-- ch14100
Self Critique
-------------
// comments on what I received
(1) bt14302
------------
// critique
(2) bt14299
------------
// critique
(3) ch14123
------------
// critique
In your self-critique, write comments about what others sent you, if you have time. For example, you might say that you plan to follow the student's suggestions or that you are confused as to what they liked or disliked, etc. It may be that students didn't get time to send it to you. If they did, wonderful, if not, that's OK.
In your critique of other student's proposals, answer the following questions:
For example, you might say "I think I could implement function foo(), but I don't understand what you want from function bar(), should it behave like X or Y? Also, you didn't fill out all the documentation as described in the documentation tutorial. For example, you are missing preconditions and postconditions."
So, you might say that the proposal is well-documented, or that the class seems like it's a good one.
How might the class be improved? Is it a good class? Would you suggest writing a different class? Do you like the name of the class? Should they write copy constructors, etc. or relational operators?
You may wish to copy the questions above into the text file and answer them so the person gets the response.
Some final comments
Make sure you identify yourself when sending the proposal.
Task 11: Implement BstMap class. (Extra Credit: +7 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.
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.
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" is run with no arguments. 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 |
|
|
|
|
|