Next: Lesson outline: The Next
Up: Lesson Plans: The First
Previous: Mathematical Foundation: Number Bases
Calculator programming project: Writing a program to converting
between number bases and do arithmetic in doing math in bases.
Since we already know how to convert bases by hand, all we need to do is
code or knowledge into the programmable calculator. These are our steps:
- Input phase
- Prompt for the input base, output base, first
number, operation (+, -, *, ,), and second number. One of the
operations should be "0" for no operation, just base conversion.
- Processing phase
- You must write a loop function to convert from the input base to a
base that the calculator can handle.
(This is
your program's "internal representation". People who use the program
don't have to worry about it, and you can change it whenever you
like without changing how the program appear to work on the surface.
Separating the work you do- "implementation"- from the surface
appearance- "interface"- is very important, so you can make changes
and improvements without without changing the instructions for use.)
Next, perform the calculation, using a case-switch based on the
operation the user chose, and store the result.
To prepare for the output, you must convert the input numbers and the
answer into the output base. Use the "string" data format to create a
string of digits that represents the number you need in the appropriate
base.
- Output phase
- Display the arithmetic equation in a pretty format
with the numbers written in the output base.
To test your program, plug in the equations you worked out yesterday,
and see if your calculator gives the right answer. (How's that for a
change of pace: you check the calculator's work!)
Optional homework for bonus credit: Expand the functionality of your
program to do more operations or use a different implementation.
Next: Lesson outline: The Next
Up: Lesson Plans: The First
Previous: Mathematical Foundation: Number Bases
Michael Brauwerman
1999-05-31