Question
Stuck on this and need help. We have only covered arrays and functions, So I am trying to solve this with a simple C++ program.
Stuck on this and need help. We have only covered arrays and functions, So I am trying to solve this with a simple C++ program.
The Logo computer language made popular a concept of turtle graphics which was popular among personal computer users.
A mechanical turtle walks around a room under the control of a C++ program. Note: There is no animation of the turtle walking around the room.
The turtle holds a pen in one of two positions, up or down.
When the pen is down the turtle draws out the shape as it moves.
When the pen is up, the turtle moves about freely without writing anything.
For this assignment you will write a program to simulate the operation of the turtle thus replicating a computerized drafting board, plotter, and a computerized cutting machine.
Use a n by n array where you determine the size of the array and call the array grid. The array should be initialized to all zeros. The commands to manipulate the turtle are input from an external file called turtle.txt.
A listing of valid commands are shown below:
Command | Meaning |
U | Pen up |
D | Pen down |
R | Turn right |
L | Turn left |
F n | move forward n spaces |
P | Print the array |
Q | End of data sentinel |
Any movement of the turtle when the pen is down will change the elements of the array from a zero to a one.
When the print command is executed the contents of the array will be displayed, except asterisks will be used in place of ones and blanks will be used in place of zeros.
You will have to create a file of turtle commands to print out the word Computer on the screen.
Example of Turtle commands
U ---- pen is up
F 10 ---- move forward 10 squares from the current position i.e. if position 0, will end up at position 10
D ---- Put the pen down
L ---- Turn left
F 5 ---- draw a line starting from the current location to the location + 5, stop at current location + 5
Write the computer program using the commands in turtle.txt to spell the word Computer on the screen.
Initial Starting Conditions of the Turtle:
Turtle is located at 0, 0 in the xy plane.
The turtle will be facing East according to the compass rose.
The initial position of the pen is up.
Note:
Keep track of the position of the turtle at all times.
Keep track if the pen is up or down at all times.
Make sure the drawing is always contained within the bounds of the array.
Hints:
You need to keep track of the direction the turtle is facing at all times because this affects the type of movement in the two dimensional grid. By default the turtle starts out facing east. Suppose you have the following commands:
R
The turtle is facing south.
F 5
The turtle now moves in the vertical direction 5 spaces and the current direction of the turtle is south. Given this information what is changing: The rows or the columns in the two dimensional grid? Are they changing in the positive direction or negative direction?
Execute the command:
R
The turtle is facing west.
Execute the command
F 2
The turtle now moves in the horizontal direction 2 spaces and the current direction the turtle is facing is now west. So in the two dimensional grid, what is changing the rows or the columns? Are they changing in the positive direction or negative direction?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started