The operators supported by the calculator are:
+ for addition
- for subtraction
x for multiplication (note this is not *)
/ for division
= for evaluation
Operands for this calculator may be arbitrary positive integers which may be entered in one of two forms, but MUST ALWAYS be followed by a single space character (this makes implementation easier). You will note that the display shows a small '@' character to indicate when the required space following an operand has been entered. Other than the newline at the end of an expression, all other white space characters entered are ignored by the calculator and not displayed. The forms of operands are:
Expressions are entered as an operand followed by an operator. For the arithmetic operators ('+', '-', 'x', and '/'), another operand is expected to follow. As described above, when the evaluate operator ('=') is entered, the result is displayed until a newline is entered.
One additional expression can be entered; namely, a 'q' character entered as the first character after the calculator prompt. This expression terminates the calculator.
Sample output from the calculator is given in lieu of a hand example. There are more details to look at but the implementation page shows what each driver is responsible for each of these sample outputs.
This program is one of moderately significant size, and the only way to even hope to get it working is to take a systematic, modular approach to its implementation. For this homework, I will do the portioning into modules for you to show you how it is done. (Later in the course will you be required to perform this type of design on your own). The development steps you will go through below are the same that I used when writing the sample.
In this section I describe the partioning I choose to approach this task. This is by no means the only partioning possible, but is a reasonable one. Looking at the specification for the calculator, it appears we will need to do things like:
So, I will divide the task into five subtasks or modules,
the Operands Module, the Operators Module, the Results Module, and the Display Module. Of course, we will also need a Driver Module
as the "glue" that binds this whole thing together. (In fact, we will be writing several driver modules as we go along to test the other modules).
Here is the structure diagram for the entire project:
******************Insert Image****************
Before beginning any implementation, let us first discuss the organization we will use for the source code files. It makes sense to store the code for each module in its own file or files.
*********Insert Image***************
the Operands Module,
This module is divided into two submodules, each implemented in its own file:
the Operators Module,
the Results Module,
This module is divided into two submodules, each implemented in its own file:
the Display Module.
I have written the code for the Display module. I will only give you the compiled module, display.o, with functions with prototypes in display.h.
and the Driver Module
You will be writing 5 drivers in developing this project. See the implementation for details.
In addition, we may be making use of functions provided in chrutil.c with prototypes in chrutil.h.
Even with all this organization, implementing this project is a big task. So we will take a bottom up approach - developing small portions of the overall program, one at a time. We will then test each portion using a "throw away" driver to make sure it works before going on to the next part. We will require you to develop and test your calculator in pieces as described in the implementation.
Submit using the format according to HW 1, HW2 and HW3
Include all .c files, .h files, and the makefile. Do not submit executables, or the makefile.
Don't forget about the Rating.