Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this question, consider a turtle living on a rectangular island represented by a grid of asterisks of width width and height height. For example,
For this question, consider a turtle living on a rectangular island represented by a grid of asterisks of width width and height height. For example, an island of width and height has the following representation:
The turtle's position on the island can be represented by replacing the asterisk at its current location by T Its location can also be represented by a pair of integers Tcol, Trow representing its current COLUMN and ROW. Note that rows and columns are indexed, with the leftmost column and topmost row having index A turtle in position would be represented as follows:
T
Complete the program that defines, at minimum, the following functions. For examples, see each function documentation and the public IOtest.
printislandwidth height, Tcol, Trow prints out width stars asterisks: followed by a newline
for height rows. In column Tcol on row Trow, instead of an asterisk, your program should instead print the letter T On a new line immediately below that, your program should print the following message:
The turtle is at Tcol, Trow
with Tcol" and Trow" replaced with the current values of Tcol and Trow, and followed by a newline character.
Implement turtlerunvoid This program should initially read in two integers corresponding to the width and height of the rectangular grid that forms the island. You may assume the input contains at least integers. These parameters must be positive. The turtle should start at position on the island. This function should then read an arbitrary length sequence of integers from stdin. If the integers are read in the turtle should be moved to a new location according to the following rules:
: up
: down
: left
: right
The turtle's movement should also "wrap around". For example, a turtle at row that moves up should appear at row height A turtle at column width that moves right should appear at column
Your function should print the representation of the turtle's initial position, as well as a message stating the turtle's current position, using the format of printisland. Every time the turtle is moved, your code should print an updated representation of the turtle's position and the updated message.
Any integer that is not one of the movement instructions should cause the program to terminate. See the provided starter code and the provided inexpect files for an example of input and output formatting.
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