5.8.EXERCISES 83
- Anarcherytargetconsistsofa centralcircleofyellowsurroundedbyconcentricringsofred,blue,
blackandwhite.Eachringhasthesame“width,” whichis thesameastheradiusoftheyellow circle.
Writea programthatdrawssucha target.Hint:Objectsdrawnlaterwillappearontopofobjectsdrawn
earlier.
- Writea programthatdrawssomesortofface.
- Writea programthatdrawsa winterscenewitha Christmastreeanda snowman.
- Writea programthatdraws5 diceonthescreendepictinga straight(1,2, 3, 4, 5 or2, 3, 4, 5, 6).
- Modifythegraphicalfuturevalueprogramsothattheinput(principalandapr)alsoaredoneina
graphicalfashionusingEntryobjects.
- CircleIntersection.Writea programthatcomputestheintersectionofa circlewitha horizontalline
anddisplaystheinformationtextuallyandgraphically.
Input:Radiusofthecircleandthey-interceptoftheline.
Output:Draw a circlecenteredat
0 0 withthegivenradiusina window withcoordinatesrunning
from-10,-10to10,10.
Draw a horizontallineacrossthewindow withthegiveny-intercept.
Draw thetwo pointsofintersectioninred.
Printoutthexvaluesofthepointsofintersection.
Formula:x
r^2 y^2
- LineInformation.
Thisprogramallowstheusertodrawa linesegmentandthendisplayssomegraphicalandtextual
informationaboutthelinesegment.
Input:2 mouseclicksfortheendpointsofthelinesegment.
Output:Draw themidpointofthesegmentincyan.
Draw theline.
Printthelengthandtheslopeoftheline.
Formulas: dx x 2 x 1
dy y 2 y 1
slo pe dy
dx
length dx^2 dy^2
- RectangleInformation.
Thisprogramdisplaysinformationabouta rectangledrawnbytheuser.
Input:2 mouseclicksfortheoppositecornersofa rectangle.
Output:Draw therectangle.
Printtheperimeterandareaoftherectangle.
Formulas:
area
length
width
perimeter 2
length width
- TriangleInformation.
Sameaspreviousproblem,butwith3 clicksfortheverticiesofa triangle.
Formulas:Forperimeter, seelengthfromlineproblem.
area s
s a
s b
s cwhereabandcarethelengthsofthesidesands a