Lab 5

This week, like last, we are focusing on looping and we will be working on writing functions. You will read in a series of strings, and pairs of ints. Then make a choice, compute a value and print the results. You should use last week's as a "template" or basic structure to follow. Additionally, instead of computing the results in our main processing loop, we will write and call functions to do the work for us.

Details

This program will compute basic integer math. We will use five commands, add, subtract, multiply, divide and remainder. Your program will read this word into a string, then perform the correct calculation on the following two integers. For example, if you read the word "add", then you should add the following integers and print the result. The rest of the operations are performed as you would expect, "subtract" you use subtraction, "multiply" you multiply, etc.

Requirements

Format for the input: The input will have the following form: <operation>space<integer>space<integer>

Where <operation> will be one of the following five commands: add, subtract, multiply, divide or remainder

<integer> will be an integer number.

There will only be an unknown number of commands in the input stream.

Samples:

add 1 1
subtract 1 1
multiply 1 1
divide 1 1
remainder 1 1

Output Sample

For this will we make another pretty table. So the corresponding output to the samples from above would look like this:

Operand1 Operation Operand2 Answer
1        +         1        2
1        -         1        0
1        *         1        1
1        /         1        1
1        %         1        0

Again, your output will depend on your input. Notice that we are using the symbols to represent the command you were given. For testing, you can use this main.cpp:

#include "compute.h"
#include <iostream>

using std::cin;
using std::cout;
int main()
{
    compute( cin, cout );
    return 0;
}