Due Thursday, February 13 at 11:59 P.M.
Reading: Kruse and Ryba Chapters 3 (except 3.5) and 5.
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.
Don't forget to sign up for our email list by typing
csmail -a cs112b1
on csa. Instructions on forwarding your csa mail elsewhere are here.
Here is a linked-list-based stack, without the Pop()
method.
Add it to stack2.cpp and test it using your calculator from
the previous homework (or the
solutions version). Note
that you will need not modify anything in calculator.cpp, assuming,
of course, it was correct (with one exception: if you called IsFull
and never looked at the value return by Push, now IsFull is useless,
and you actually need to look at the return value of Push).
cp /cs/www/html/faculty/reyzin/teaching/s03cs112b/hw2/{stack2.h,stack2.cpp,itemtype.h} .
at the Unix prompt to get these files into your current directory.
Here is an ordered list, without the
bool Remove(ItemType item)
method, which should return
false if the item is not the list, and otherwise remove the item
from the list and returns true. Add it to orderedlist.cpp and test
it.
Here is the header for the class Polynomial.
Implement it in a new file polynomial.cpp. It may help you implementEqualToSum
,
EqualToDiff
, and EqualToProd
if you remember
that a method of a class is allowed to access private members
of other instances of the same class. Be sure to handle memory management
properly, not leaving any dangling pointers and lost memory. Also
be sure to follow the comments in polynomial.h
about how the linked list arranged, and print the polynomials
as shown below.
Note: For grading,
the polynomials must print precisely as in the examples
below. We will take points off if they do not.
Create an RPN calculator for polynomials. The input syntax is the
same as in the previous homework, with the following exceptions:
a /
is not allowed, and
a ?
should be followed by a float coefficient,
a space, and an integer degree. This inputs a monomial.
To input a polynomial, input its monomials and add them.
Here is a sample input and output:
? 1.5 3 ? 4.3 2 ? 2 0 ++ = ? 4 3 ? 1 1 + = * = ? 2 1 ? -7 0 + = - = ? 0 0 =
* = q
It may help to use the RPN calculator from the previous homework
as a starting point (you may
take the one from the solution
if you wish), and either of the stack implementations. The stack
now should hold pointers to polynomials. You will need to modify
1.5x^3 + 4.3x^2 + 2
4x^3 + x
6x^6 + 17.2x^5 + 1.5x^4 + 12.3x^3 + 2x
2x - 7
6x^6 + 17.2x^5 + 1.5x^4 + 12.3x^3 + 7
0
0
itemtype.h
but not the stack implementation itself.
The new itemptype.h
will read as follows:
Because your stack now holds pointer, you'll have to handle creation
and deallocation of polynomials via
class Polynomial;
typedef Polynomial * ItemType;
new
and
delete
carefully. Again, be sure to deallocate memory before losing track of it.
Put your new calculator into polycalc.cpp
.
To submit hw2:
hw2
, using the mkdir command.
gsubmit cs112b1 -cp hw2
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 "Hw2" will probably not be seen by the grader.