Programming in Perl

Homework 2

Due Tuesday, February 18th at 11:59:59pm EST

See the Sample I/O and FAQ.

Perl Calculator

Write a Perl script which will read a mathematical sentence from the user, evaluate the solution, and print this solution to the screen. For example, if the user types
5 + 4 =
your program will output 9. All formulas will be given in the format
Operand_1 Operator Operand_2 =
The characters in the formulas may or may not be seperated by whitespace. The operators you must support are: + - / * %
For the division operator, you will support a "C++ Style" division system. That is, if both operands are integers, the answer must be truncated to an integer (HINT: look at the Camel or perl.com for either int or sprintf). If either or both operands are floating point numbers, the answer should be left in floating point form.
For the modulus operator, you may give whatever result Perl would give under the given circumstances (Perl will truncate any operands of % to integers)

Once the user enters the phrase "done" (case insenstive), you are to present the user with a list of all formulas entered and their solutions. The list must be sorted by order of operation first, and then by value of the solution. (This means one sorted list - the formulas grouped by operation, and sorted by solution value within this grouping).

Note that the values of the operands may be negative (in which case the minus sign will be immediately in front of the operand, with no spaces), and may be decimals. Any decimal number betwen 0 and 1 will be specified with a 0 before the decimal point. Any whole number will either not have a decimal point at all, or will have a decimal followed by one or more 0's. (Whole numbers written with decimal-zero are not to be treated as integers by the division system).

Grading Criteria

Parse +, -, *, and % and produce corect result:25%
Parse integer division and produce correct result:15%
Parse decimal division and produce correct result:10%
Print list of all formulas and solutions:15%
Sort list first by formula type:10%
Sort list secondly by solution value:5%
Compilation:5%
Code Style:5%
Output Style:5%
Error Checking:5%
As before, 5 above and beyond points are available for Added Functionality to the code

Submission Instructions

The same two submission options are available - either go to the submission script, or run ~lallip/public/submit.pl. Again, please use only one method of submitting. As before, this assignment must work on rcs-sun1.rpi.edu

The homework is due due Tuesday, February 18th at 11:59:59pm EST. It will be accepted until Wednesday, 2/19 11:59:59 at a reduction of 20%.