CSE 1001
Project ID (for submit server purposes):
Assignment 4
ass04
Panther Solver
Deadline: Nov 14, 2012 11:59pm
The goal of this assignment is to practise control state- Sample Dialog (user inputs are underlined)
ments, strings and methods / functions. Panther Solver is a
solver that accepts exactly three comma-separated, integer-
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZonly inputs a, b and c. It solves the quadratic equation
========================================2ax + bx + c = 0 using the quadratic formula0|0 |
x=
−b ±
√
b2 − 4ac
2a
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 30
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3u
Invalid key.
Key: 3U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 246
Invalid key.
Key: -146
Invalid key.
Key: 7T
Invalid key.
Key: 2T
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 46
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1,-9 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 2T
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1,-9 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3U
and displays the two solutions on the screen. If a = 0, the
equation cannot be solved. Otherwise, if b2 − 4ac ≥ 0, the
equation has two real solutions as specified by the quadratic
formula. If b2 − 4ac < 0, it has two complex solutions p + qi
√√2and p − qi where p = −b , q = 4ac−b , and i = −1.
2a2a
The solver’s keyboard consists of the digits 0-9, and +/-
for negative numbers. Pressing +/- more than once reverses
the sign. A ‘,’ key separates inputs a, b and c. Pressing SOLVE
solves the equation. AC (All-clear) clears the display, and OFF
is used to switch OFF the solver and stop the program.
The solver is organized as a 5 × 27 grid (excluding the
extremities), displayed in the sample dialog, with grid co-
ordinates labelled 0-9 and A-Z as a guide. A keypress is sim-
ulated by specifying its horizontal and vertical co-ordinates
one after another, in that order, case-sensitive. User inputs
are validated. Valid, non-functional co-ordinates on the cal-
culator result in no action.
The program first displays the solver on the screen with
the number zero and prompts the user to enter a digit. As and
when a digit is keyed in (by specifying its co-ordinates), the
digit is accumulated into a number that is displayed on the
solver. When the comma key is entered, it is displayed and
the digits taken so far form the first number (with the optional
+/-). Once a digit key is pressed, no change can be made to
its sign. (For this reason, press the +/- key and press again to
reverse it, but before keying a digit.) The process continues
for the remaining two numbers.
When SOLVE is now pressed (pressing any one letter of this
word accomplishes this task), the solver displays the two solu-
tions of the quadratic equation with a comma between them,
or the word Error. No further keys are now taken except for
AC that clears the solver and displays a zero. The solutions
can be either integers, reals, or complex numbers. Integers
solutions should be displayed without the decimal point and
without trailing zeros. Real numbers are displayed correct to
two decimal places. Complex numbers are displayed in the
form p + qi and p − qi.
Not entering exactly three integers a, b and c, or the equa-
tion not being solvable, results in Error getting displayed if
SOLVE got pressed.
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1,-9, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 32
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1,-9,2 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 48
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|1,-9,20 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 4X
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|4, 5 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 1Z
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|4, 5 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 2Z
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 48
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 34
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0,3 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0,3, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 2U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0,3, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 30
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0,3,-1 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 4V
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|Error |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 2Y
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 48
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 38
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 2U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 33
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 32
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5,-2 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 3U
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5,-2, |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 40
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|5,-2,6 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 4Z
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0.2+1.08i, 0.2-1.08i|
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 2Z
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0|0 |
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Key: 22
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
========================================
0||
1|--------------------------------------|
2| OFF+/- AC |
3| 1 2 3 4 5,|
4| 6 7 8 9 0SOLVE |
========================================
Test your program to solve the following quadratic equa-
tions (answers given in braces):
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
x2 + 84x + 1764 = 0,
x2 + 85x + 1764 = 0,
x2 + 2x − 63 = 0,
x2 + 9x − 630 = 0,
x2 + 9x − 6300 = 0,
x2 + 2x − 63000 = 0,
3x2 − 10x + 3 = 0,
27x2 − 48x − 512 = 0,
x2 − 4x + 9 = 0,
x2 + 4x − 9 = 0,
5x2 − 17x = 0,
9x2 − 432x + 5184 = 0,
4x2 − 47x + 300 = 0,
x2 + 25 = 0,
{−42} (will show as -42, -42)
{−49, −36}
{−9, 7}
{−30, 21}
{−84, 75}
{−252, 250}
{3, 0.33}
{5.33, −3.56}
{2 + 2.24i, 2 − 2.24i}
{−5.61, 1.61}
{0, 3.40}
{24} (will show as 24, 24)
{5.88 + 6.36i, 5.88 − 6.36i}
{5i, −5i}