For example, if we want to be able to accept negative operands, the place to look is the operand module - get_opnd().
The algorithm we might have for get_opnd() is:
Given: the first character of the operand
Return: the next operand typed as an integer
skip leading white space
while character is a digit character
display it
convert and add it in to the number
get the next character
while character is an exponent character
display it
convert and add it in to the exponent
get the next character
if there was an exponent
compute the base to exponent
if character is a space
display it
return the result
otherwise do error handling
To handle negative operands, we would expect a '-' before the first
digit of the base. So we could modify the algorithm to be:
Given: the first character of the operand
Return: the next operand typed as an integer
skip leading white space
if the character is '-'
display it
remember the number is negative
while character is a digit character
display it
convert and add it in to the number
get the next character
if the number is supposed to be negative
negate the number
while character is an exponent character
display it
convert and add it in to the exponent
get the next character
if there was an exponent
compute the base to exponent
if character is a space
display it
return the result
otherwise do error handling
Similarly, we could add steps to handle float values for the operand.
In this case we add code to detect the '.' after the digits, and
accumulate the fractional part. We would also need to modify the print
results module to print float values.
Or if we wanted negative exponents as well. We could modifiy get_opnd() to detect the '-' exponent character and negate the exponent. We would also need to modify the exponent module to handle negative exponenets, not just pos_power().