Computer Science Fundamentals (CS153 2003S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Summary: In this laboratory, you will experiment with the use and application of some of Scheme's basic input and output procedures.
Procedures Covered:
read
,
write
, and
display
.
Contents
a. Make sure that you understand what
read
,
write
, and
display
are supposed to do. You may find
the reading on input helpful.
b. Start DrScheme.
read
For each of the parts of this exercise, you should use something like
(define val (read))
to read in a value.
a. Use read
to obtain a number.
b. Use read
to obtain a string.
c. Use read
to obtain a character.
d. Use read
to obtain a list of numbers.
e. Use read
to obtain a symbol.
f. Use read
to obtain a list that contains a number,
string, and symbol.
g. What happens when you use read
to obtain a list and
you hit <Enter> in the middle of the list?
Consider the following sequence of Scheme commands:
(display "Please enter a value and I will square it: ") (define val (read)) (define val-squared (* val val)) (display (string-append "The value of " (number->string val) " squared is " (number->string val-squared))) (newline)
a. What do you expect the code to do?
b. Verify your answer via experimentation.
a. Save the above code in a file (e.g., square.scm
).
b. Open a terminal window.
c. In that terminal window, type
mzscheme -r file.scm
Where file.scm is the name you chose in part a.
d. Reflect on what happened. Did you need to type any Scheme? Could someone else use step c without understanding the underlying Scheme?
Rewrite the code from the previous exercise to use let
or
let*
(or both) rather than define
.
a. What happens if someone enters something other than a number?
b. Update your program so that it prints a friendly error message
(using display
) and then asks again if someone enters
something other than a number.
a. Write a Scheme program that reads in the three coefficients of a quadratic equation (the a, b, and c in ax2 + bx + c) and prints out the roots of the equation. You should model this program on the previous exercises. In case you've forgotten, the roots of the quadratic equation are
(-b +/- sqrt(b2 - 4ac)) / 2a
b. Save the program in a file and execute it from the command line.
c. Reflect on what happened. Did you need to type any Scheme? Could someone else use step b without understanding the underlying Scheme?
Write a program repeatedly asks for a value and computes its square root. You will probably need to
a. Put the stuff (request for value, computation of a value, display of that value) in a procedure.
b. Have that procedure recurse.
c. Decide upon a base case to stop recursion. (I'd suggest that you stop when someone enters something other than a number.)
Write a command-line version of the dice game from a recent lab.
Friday, 2 March 2001 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/io.html
.
Monday, 4 November 2002 [Samuel A. Rebelsky]
Tuesday, 5 November 2002 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/io.html
.
Tuesday, 4 March 2003 [Samuel A. Rebelsky]
For this with extra time.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2002F/Labs/io.html
.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue May 6 09:19:51 2003.
The source to the document was last modified on Tue Mar 4 19:28:31 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Labs/io.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby