Fundamentals of CS I (CS151 2001S)
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Start DrScheme.
Define a one-field object tally that responds
to exactly four
messages:
':show-contents,
':set-contents-to-zero!,
':increment!, which has the effect of increasing the
number stored in the contents field by 1.
':decrement!, which has the effect of decreasing the
number stored in the contents field by 1.
The initial value of the field should be 0.
Test the switches created by the make-switch
procedure from the reading. Here are a few possible instructions.
> (define lamp-switch (make-switch)) > (define vacuum-cleaner-switch (make-switch)) > (lamp-switch ':show-position) > (vacuum-cleaner-switch ':show-position) > (lamp-switch ':toggle!) > (lamp-switch ':show-position) > (vacuum-cleaner-switch ':show-position) > (lamp-switch ':toggle!) > (vacuum-cleaner-switch ':toggle!) > (lamp-switch ':show-position) > (vacuum-cleaner-switch ':show-position)
a. Define a make-tally procedure that constructs and returns
objects similar to the tally object you defined in exercise
1.
b. Create two tally objects and demonstrate that they can be incremented and reset independently.
Write a new make-tally procedure that allows the client
to create new tallys with a specied initial value. For example, I
might say that a starting grade is 90 with
> (define grade (make-tally 90))
I would then increment and decrement it as students do good or bad work.
a. Define a constructor procedure, make-monitored-tally, for
objects similar to the tally objects from exercise 2 above,
except that each such object keeps track of the total
number of messages that it has received.
Hint: For this exercise, you will want to make a two-element vector. Element 0 of that vector will be the value of the tally. Element 1 of that vector will be the count of operations.
b. Test your procedure.
Wednesday, 6 December 2001 [Samuel A. Rebelsky]
http://www.math.grin.edu/~stone/courses/scheme/object-oriented-programming.xhtml.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/oop.html.
Tuesday, 1 May 2001 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/oop.html.
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Thu May 3 23:07:55 2001.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/oop.html.
You may validate
this page's HTML.
The source was last modified Thu May 3 08:52:33 2001.