Homework 1

CS 220

40 points, due Sept. 26, 1997

  1. (10 pts.) Problem 2.11.

  2. (30 pts.) Write a simple calculator program in SAL. Input to the program will be a single line of the form:
    x op y
    
    where x and y are non-negative integers and op is one of the four arithmetic operations. op is surrounded by a single space character on each side.

    Write a procedure to read a non-negative integer, character by character and use that procedure in your program. Here is the algorithm for reading a number, in case you've forgotten it:

    value = 0;
    c = getchar();
    while ('0' <= c && c <= '9')
    {
       value = 10 * value + c - '0';
       c = getchar();
    }
    

    Your program should validate its inputs before computing any results. Hand in a source SAL listing of your program and several sample runs (use script; see its man page).



Thomas P. Kelliher
Thu Sep 18 20:54:12 EDT 1997
Tom Kelliher