Answered step by step
Verified Expert Solution
Link Copied!

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 3 and height 5 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 (T_col, T_row) representing its current COLUMN and ROW. Note that rows and columns are 0-indexed, with the leftmost column and topmost row having index 0. A turtle in position (2,1) 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 I/O-test.
print_island(width, height, T_col, T_row) prints out width stars (asterisks: *) followed by a newline (
) for height rows. In column T_col on row T_row, 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 (T_col, T_row).
with "T_col" and "T_row" replaced with the current values of T_col and T_row, and followed by a newline character.
Implement turtle_run(void). 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 2 integers. These parameters must be positive. The turtle should start at position (0,0) on the island. This function should then read an arbitrary length sequence of integers from stdin. If the integers 1-4 are read in, the turtle should be moved to a new location according to the following rules:
1 : up
2 : down
3 : left
4 : right
The turtle's movement should also "wrap around". For example, a turtle at row 0 that moves up should appear at row height -1. A turtle at column width -1 that moves right should appear at column 0.
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 print_island. 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 in/expect files for an example of input and output formatting.

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

More Books

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago