Due Thursday, February 27 at 11:59 P.M.
Reading: Kruse and Ryba Chapters 7 and 10.1, 10.2, 10.3. Get started on Chapter 8.
Please keep in mind the policy on collaboration, as described on the syllabus.
Your code will be graded for style as well as correctness and should conform to the following style guidelines.
The following program should output an integer square root of its input. That is, given an unsigned integer x, it should find the largest integer y such that y*y<=x. Implement the missing code using binary search.
The following program should take as input a bunch of strings and print them upon request in ascending and descending order. The user can input
?
followed by a string,
at which point the program takes in the string, or
a
,
at which point the strings should be printed in ascending
order, or
d
, at which point the strings should
be printed in descending order, or
q
, at which point the program should quit.
? Boston
? Denver
? Chicago
? Cincinnati
a
Boston
Chicago
Cincinnati
Denver
d
Denver
Cincinnati
Chicago
Boston
? Brownsfield
? Exeter
? Albuquerque
a
Albuquerque
Boston
Brownsfield
Chicago
Cincinnati
Denver
Exeter
q
You need to implement this using a binary search tree
to store the strings in order. Some code is already provided for you;
fill in the missing code. It may be handy to know that the >
and <
operators work on strings.
Note: If you call your executable "strings", then be sure to type
./strings
in order to run it, because there is another Unix command "strings" that may
run instead if you just type "strings."
Modify the RPN calculator from HW 1
to do the following. Instead of performing the operation requested,
the calculator should create and push on the stack
the expression tree representing the operation requested.
Upon receiving the command =
, the calculator
should print out the infix version of the expression,
then evaluate it and print out the result. Here is a sample
input and output:
? 5 ? 2.5 / = ? 4 ? 3.2 ? 4.0 + + = p ? 1.5 - = q
Please be sure to follow the output format exactly (including
parentheses, spaces
around the operators and the equal sign, etc.) or we may take off points.
(5 / 2.5) = 2
(4 + (3.2 + 4)) = 11.2
((5 / 2.5) - 1.5) = 0.5
You may use any stack implementation you want (see solutions to hw1 or hw2). Whiechever you use, however, please to call the files stack2.cpp and stack2.h, respectively, so that your include file is correct.
Your itemtype.h will look
as follows:
class TreeNode;
typedef TreeNode * ItemType;
Much of the implementation is provided, you need only fill in the missing code:
We want you to use a make file for this assignment, and from now on.
If you download this sample Makefile
and run command make
it will make targets
binsqrt and strings, but will not work for
postfixinfix. Add target postfixinfix, which should
depend on stack2.o and postfixinfix.o, and targets
stack2.o and postfixinfix.o (think about dependencies there).
Once you are done with this part, make should compile
your entire assignment. You may find the Labs
web page helpful.
To submit hw3:
hw3
, using the mkdir command.
gsubmit cs112b1 -cp hw3
Important: Please follow all instructions about file names and how to submit assignment exactly, or there is a very real chance that your assignment will not be accepted! For example, a directory named "Hw3" will probably not be seen by the grader.