2.1 The Assignment
2.1 The Assignment
2.1 The Assignment
• n the next input token is a number which is read and placed at top of the
calculator’s store.
• + removes the the top two number in store, adds them and stores the
result at the top.
• * removes the the top two number in store, multiplies them and stores the
result at the top.
After each input token is processed, the calculator prints the current value in
the top of its store.
The assignment comes in several parts, do each part strictly in order
1
Debugging syntax errors
1. Include your name and email in your program using a comment as the
first line of the program.
2. calc.c contains several syntax errors. Correct these errors.
3. Running you code with the input file called test.in. This should output
identical to test.out. Test your corrected code by making sure this happens.
Debugging runtime errors
Some users have complained that the program sometimes give the wrong
values. In real industrial situation you would be expected to find out why, and
fix the problem. Here you are told it is because the the calculators store has
limited size. Rather than fix the problem you must warn users if they try to
store too many numbers. The program must issue the warning store full if
the user tries to exceed the calculators limits, and too few numbers if the user
tries to multiply or add numbers when the store contains less than two numbers.
4. Emulate the problem by change the store size to have a limit of 4 numbers.
You are expected to find out how to do this for yourself. Convince your self you
have emulated the problem by running the program using an input file of your
own devising called mytest.in.
5. Devise a solution and code it into calc.c. The manner of solution is
up to you, but you are strongly advised to look at lines of code such as i =
newnumber( array, N, i );. This is poor code for at least two reasons: (i)
They change a variable that is important to the operation of the store outside
the functions that control the store (these are the library functions). (ii) There
is no way for the calling function to recognise whether the library function has
worked successfully or not.
6. Test your program by showing that it issues appropriate warnings when
run with mytest.in as input. Redirect output to mytest.out. Further test your
code by showing it produces the correct input when the supplied file test.in
is run. The calculator should not issue any warnings for this input.
Here are some hints: (i) If you use pointers (or structures) then you can solve
the first problem in a neat way that open up the possibility of a neat solution to
the second solution. (ii) Think very carefully about which part of the program
should issue warnings, in particular consider whether library functions should
do more than originally intended.
2
You program will be compiled and run on the data files you have submitted.
It will also be run on data files held in private by the tutors. you will receive
feed back by email. The feed back is formative in nature, it does not contribute
to your assessment.
• It tests your coding ability directly. There is no better test on one’s ability
to code than to be asked to write code. The compiler will not compile in-
correct syntax, and a compiled program either produces a correct output,
without crashing, or it does not.