Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Turtle graphics are vector graphics that uses a relative cursor (the turtle), on a Cartesian plane to produce some sketches. Imagine a mechanical turtle that

Turtle graphics are vector graphics that uses a relative cursor (the turtle), on a Cartesian plane to produce some sketches. Imagine a mechanical turtle that walks around the room. It holds a pen in one of two positions: UP or DOWN. While the pen is down, the turtle traces shapes as it moves. While the pen is up, it can move freely without any trace. Write a C++ program to simulate the operations of a turtle. Let the floor or the sketchpad be a 20 x 20 array that is originally initialized to zero. The set of possible turtle commands is: Command Value Action 1 Pen Up 2 Pen Down 3 Turn Right 4 Turn Left 5, x Move forward x steps 6 Print the 20 x 20 array The commands will be stored and read from an array that contains them. Keep track of: the current position of the turtle at all times, the direction of the turtle (UP, DOWN, RIGHT, LEFT), and whether the pen is currently up or down. Assume the turtle starts at position (0, 0) of the floor with its pen up. As the turtle moves with pen down, set the appropriate elements of array floor to 1s. When printing the floor, whenever you have a 1, print an asterisk or any other character of your choice. Whenever you have a 0, print space. Try the following set of commands {2, 5, 12, 3, 5, 12, 3, 5, 12, 3, 5, 12, 1, 6} that will generate a 12 x 12 square. Try different commands to get different sketches. Represent the turtle in a class that encloses its state and behavior. You can use enumeration for the direction of the turtle: enum direction {UP, RIGHT, DOWN, LEFT} enum direction turtleDirection = UP or enum direction turtleDirection = 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions