|
For this program you will be creating an operation table. The operation will be chosen by the user, from addition, subtraction, multiplicaation, and division with remainders. The table will go from 1 to 10 on each side.
There will be a dialogue where you ask the user which operation they want. Based on their answer, you should produce an operation table for that operation. You should keep asking for an operation until you get a satisfactory answer. This dialogue should be in a function, with the good operation as the return value.
Sample output - Screen:
Enter an operation: + - * / ^ Enter an operation: + - * / @ Enter an operation: + - * / $ Enter an operation: + - * / / / 1 2 3 4 5 6 7 8 9 10 ------------------------------------------------------------- 1 | 1 R0 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 2 | 2 R0 1 R0 0 R2 0 R2 0 R2 0 R2 0 R2 0 R2 0 R2 0 R2 3 | 3 R0 1 R1 1 R0 0 R3 0 R3 0 R3 0 R3 0 R3 0 R3 0 R3 4 | 4 R0 2 R0 1 R1 1 R0 0 R4 0 R4 0 R4 0 R4 0 R4 0 R4 5 | 5 R0 2 R1 1 R2 1 R1 1 R0 0 R5 0 R5 0 R5 0 R5 0 R5 6 | 6 R0 3 R0 2 R0 1 R2 1 R1 1 R0 0 R6 0 R6 0 R6 0 R6 7 | 7 R0 3 R1 2 R1 1 R3 1 R2 1 R1 1 R0 0 R7 0 R7 0 R7 8 | 8 R0 4 R0 2 R2 2 R0 1 R3 1 R2 1 R1 1 R0 0 R8 0 R8 9 | 9 R0 4 R1 3 R0 2 R1 1 R4 1 R3 1 R2 1 R1 1 R0 0 R9 10 | 10 R0 5 R0 3 R1 2 R2 2 R0 1 R4 1 R3 1 R2 1 R1 1 R0
Sample output - File (table.txt):
/ 1 2 3 4 5 6 7 8 9 10 ------------------------------------------------------------- 1 | 1 R0 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 0 R1 2 | 2 R0 1 R0 0 R2 0 R2 0 R2 0 R2 0 R2 0 R2 0 R2 0 R2 3 | 3 R0 1 R1 1 R0 0 R3 0 R3 0 R3 0 R3 0 R3 0 R3 0 R3 4 | 4 R0 2 R0 1 R1 1 R0 0 R4 0 R4 0 R4 0 R4 0 R4 0 R4 5 | 5 R0 2 R1 1 R2 1 R1 1 R0 0 R5 0 R5 0 R5 0 R5 0 R5 6 | 6 R0 3 R0 2 R0 1 R2 1 R1 1 R0 0 R6 0 R6 0 R6 0 R6 7 | 7 R0 3 R1 2 R1 1 R3 1 R2 1 R1 1 R0 0 R7 0 R7 0 R7 8 | 8 R0 4 R0 2 R2 2 R0 1 R3 1 R2 1 R1 1 R0 0 R8 0 R8 9 | 9 R0 4 R1 3 R0 2 R1 1 R4 1 R3 1 R2 1 R1 1 R0 0 R9 10 | 10 R0 5 R0 3 R1 2 R2 2 R0 1 R4 1 R3 1 R2 1 R1 1 R0
You must use a switch statement to deal with the choice of operation. You can have either:
1. a switch statement that calls one of four functions, each designed to produce a table for a particular operation, or 2. a function that produces a table with a switch statement that is only used for the calculation, or 3. you might choose to combine the two, with one function to handle +, -, and *, and another for division with remainders.
The table should be printed to both the screen and a file, table.txt.
|