Lab 1: Sequential Elements of the SR Programming Language
Lab 1: Sequential Elements of the SR Programming Language
Goals: This lab provides experience with the sequential elements of
the SR programming language.
Resources:
-
All sample programs from Hartley's textbook are available in directory
~walker/parallel/sr/book .
-
Program examples from class are available in directory
~walker/parallel/sr/examples .
Steps for this Lab:
-
Copy the darts program ~walker/parallel/sr/examples/darts.sr to
your account. Compile it with the statement
sr -o darts darts.sr
Run it by typing darts.
-
Edit darts.sr to introduce a variety of typographical errors.
After creating each error, try recompiling and note how the compiler
responds.
-
Write an SR program which uses the random number generator to simulate the
rolling of a die 10 times. The program should print the results of
each roll.
-
Modify the previous program to record the number of 2's that are obtained
when a die is rolled 1000 times. (The program should not print the results
of each roll -- only the total number of 2's out of the 1000 rolls.)
-
Modify the previous program to record the number of times that one roll of
a die gives the same result as the previous roll over 1000 rolls of the
die. For example, in the sequence 6, 5, 5, 2, 2, 2, the program should
print the count 3 (the double 5's gives one duplicate and the sequence 2,
2, 2 contains the duplicate 2, 2 twice).
Compare the results you obtained on this part and on the previous part.
Explain any similarities or differences in the results obtained.
-
Write a program for Section 2.3.1 in Hartley's text.
In this assignment, your program must have at least one procedure and must
show the use of both value and reference parameters.
Format for Submitting Lab Work
All programs for this course must start with the following header:
# Your name
# Assignment or Lab Title
# Short description
Once a program is in its final form, it should be submitted using the
following steps:
-
Start recording work in a window using the submit command.
-
Use cat to list all relevant program files, giving the file for
the main program (with the above header) first.
-
Compile all parts of the program with the sr command.
-
Show appropriate test runs.
-
Stop recording and print the file.
-
On the printout (in pen), argue why you believe that your
program is correct, based on the given output.
Work to be turned in:
-
Observations and comments for parts 2 and 5.
-
A copy of the program, in the prescribed format, for programs in parts 4,
5, and 6.
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/295/lab1.html
created January 13, 1997
last revised January 17, 1997