Assignment 2

Due 12 noon, on Wednesday, September 21, 1994

Grader: Sriram Narasimhan

Purpose

The purpose of this assignment is to write a simple SAL program and use the simulator.

Problem

The user is prompted to enter an integer that is greater than zero. The SAL program determines if a user-entered integer is evenly divisible by 3, 4, and 5. The program then prints this result. Several sample runs of the program might look like:


  Enter an integer > 0:  16
  The integer is not evenly divisible by 3.
  The integer is evenly divisible by 4.
  The integer is not evenly divisible by 5.

  Enter an integer > 0:  20
  The integer is not evenly divisible by 3.
  The integer is evenly divisible by 4.
  The integer is evenly divisible by 5.

  Enter an integer > 0:  16
  The integer is not evenly divisible by 3.
  The integer is evenly divisible by 4.
  The integer is not evenly divisible by 5.

Requirements

The following requirements must be followed to receive full credit for the assignment.

  • You may not assume that the user will enter an integer that is greater than zero. The program should check that the integer is greater than zero. If not, the program should print an error message and exit.
  • The SAL program must use procedures, and it must use the procedure call and return mechanism described in Chapter 2 of the text. Three procedures are required for full credit:

    get_int -- a procedure to prompt for an integer, get one user-entered integer, and check if it is greater than zero.

    divisible -- a procedure to check if one integer is evenly divisible by another integer. It sets a flag based on the result.

    print -- a procedure to print a message about whether an integer is or is not evenly divisible based on the flag.

    How to turn in your assignment

    You are to turn in the source code for your program by using the handin2 program. When you have completed the assignment, hand in your source code by typing:

    ~cs354-1/bin/handin2 filename

    where filename is the file containing the source code. You may receive feedback from the grader of your assignment by handing in a printout of your source code.