Due Friday October 19 at 11:59pm
This document contains a list of some recommended extra credit. Before you start working on extra credit, you should probably look at the course policies on extra credit.
For any extra credit you implement, you should include in your group writeup:
Here are some suggested extra credit ideas. Feel free to also come up with your own extra credit ideas if you don't feel like doing these ones -- the only restriction is that your idea needs to related to the course content and needs be approved by the course instructor first.
Implement a solve
function
Try writing a solve(...)
function that solves for
some user-specified variable. For example,
solve(equal(3, x + 2), x)
would return 1
.
Before implementing this, you will need to add support for the
equal(x, y)
math operator. (Here, we treat
equal(x, y)
as having the same meaning as
$x = y$.)
You can add support for this equals
operator
similarly to how you added support for operators like
+
or *
. You will also need to
add a handleSolve(...)
method to ExpressionManipulator
and register your handleSolve(...)
method inside the
Calculator
class's constructor.
What exactly your solve function does is up to you: you either try and approximate an answer perhaps within a user-specified range (easier) or try and solve the equation symbolically (harder).
Implement a derive
function
Try implementing a function that can take the derivative of
some user-specified expression. Your derive
function doesn't need to support arbitrary expressions: you
could have it support only polynomials, for example. (If you
support more types of expressions, that'll be more extra credit).
Implement more plotting functions or a drawing library
Currently, we can only plot line plots. Try adding more plotting functions to draw different kinds of charts and visualizations!
You should add a new method to the ImageDrawer
class for each new plotting function you implement. Please do
not change or modify any of the existing methods.
Alternatively, add commands that can let the user draw arbitrary
images. Our graphing calculator, under the hood, is built on top
of a Graphics
object (which is the same one you used
in CSE 142 or 143 to draw images). The ImageDrawer
class
has a method you can call to gain access to the Graphics
object.
For bonus points, draw an image using those commands and include the image (and the commands used to draw the image) in your group writeup.
Implement control flow (if statements, loops) and implement a programming language
We will first start by implementing two basic control flow primitives: if statements, and loops.
Try creating an if(cond, then, else)
function.
The function should first evaluate the cond
expression and returns then
if it evaluates to
true and returns else
otherwise.
Since our expressions always evaluate to numbers, we'll treat 1 as being synonymous to true, and 0 as being synonymous to 'false'.
Similarly, implement a repeat(amount, body)
function that repeatedly evalutes the body
multiple times.
(See ControlFlowManipulators
for some starter code.)
Once you have finished implementing those two primitives, add more and more control flow elements (while loops, user-defined functions, etc...) to let the user compute increasingly more complex things.