TWiki
>
CS101 Web
>
CS101Spring2012
>
S12Exam1Solutions
(2012-02-28, Main.troy)
(raw view)
E
dit
A
ttach
Solutions to the First Exam for CS 101 Spring 2012 1 C 1 A 1 D 1 D 1 C 1 E 1 A 1 B 1 B 1 C 1 A 1 B 1 A 1 D 1 C 1 D 1 A 1 D 1 E 1 E <hr /> 1 Below is one solution <blockquote>World w = new World ();<br />Turtle t = new Turtle (w);<br />int index;<br /> <br />// draw red square<br />t.setPenColor (Color.RED);<br />index = 0;<br />while ( index < 4 )<br />{<br /> t.forward (100);<br /> t.turn (-90);<br /> index = index + 1;<br />}<br /> <br />// move to the right to draw second square<br />t.penUp();<br />t.turn (90);<br />t.forward (100);<br />t.penDown();<br /> <br />// draw blue square<br />t.setPenColor (Color.BLUE);<br />index = 0;<br />while ( index < 4 )<br />{<br /> t.forward (100);<br /> t.turn (-90);<br /> index = index + 1;<br />}<br /> <br />// display the world<br />w.show(); </blockquote> --- 22. Below is one solution <blockquote> public static void drawDecagon (Turtle t, int len, Color c)<br /> {<br /> Color saved = t.getPenColor ();<br /> t.setPenColor (c);<br /> <br /> int index;<br /> index = 0;<br /> while ( index < 10 )<br /> {<br /> t.forward (len);<br /> t.turn ( 360/10 ); // 36 degree turn<br /> index = index + 1;<br /> }<br /> t.setPenColor (saved);<br /> } </blockquote> -- Main.troy - 2012-02-28
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2012-02-28 - 19:37:33 - Main.troy
CS101
Syllabus
Lecture Notes
Homeworks
Additional Material
[edit this menu
]
Log In
CS101 Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
ABOUT US
Our Department
Recent News
Contact Us
ACADEMICS
Prospective Students
Undergraduate
CS Minor
Graduate
Courses
RESEARCH
Overview
By Faculty
Labs
PEOPLE
Faculty
Adjuncts
Staff
Students
Alumni
Copyright 2016 The Board of Trustees
of the University of Illinois.
webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF