Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE READ INSTRUCTIONS ON THE PICTURE PROVIDED..... 2 ::: CODE IS GIVEN HERE JUST COMPLETE THIS CODE TO GET THE OUTPUT GIVEN IN PICTURE WITH
PLEASE READ INSTRUCTIONS ON THE PICTURE PROVIDED..... ::: CODE IS GIVEN HERE JUST COMPLETE THIS CODE TO GET THE OUTPUT GIVEN IN PICTURE WITH BORDERS..::: ONLY C PROGRAMMING...
#define CRTSECURENOWARNINGS
#include
function prototypes
void turtleDrawconst int;
int main
int commands go to start of first letter and put pen down
B
go to start of next letter and put pen down
O
go to start of next letter and put pen down
B
; finish off
Invoke function which will execute commands
turtleDrawcommands;
define enum types
enum TCmnds PENUP PENDWN TURNRIGHT TURNLEFT MOVE DISPLAY ENDOFDATA ;
enum Dirs BEGINVALUE, NORTH, EAST, SOUTH, WEST, ENDVALUE ;
#define NROWS number of rows in floor
#define NCOLS number of colums in floor
#define TRUE
#define FALSE
const unsigned int STARTINGROW ;
const unsigned int STARTINGCOL ;
const enum Dirs STARTINGDIRECTION SOUTH; direction that turtle
will be facing at the start
const short STARTINGPENPOSITION FALSE; Pen will be up when
some more function prototypes
void displayFloorconst shortNCOLS;
void moveTurtleshortNCOLS const int, const enum Dirs, const short, int int;
turtleDraw function responsible for executing commands
void turtleDrawconst int cmds
short floorNROWSNCOLS FALSE ; init to all FALSE
enum Dirs direction STARTINGDIRECTION; used to represent current direction that the turtle is moving
unsigned int row STARTINGROW; used to represent current row that turtle is at
unsigned int col STARTINGCOL; used to represent current column that turtle is at
short pen STARTINGPENPOSITION; starting position of pen up or down
is up is down
int cmdNo ; The position in cmds array we are currently processing
do until ENDOFDATA is encountered
switch cmdscmdNo Switch statment that processes commands
case PENUP: Pen up
pen FALSE;
break;
case PENDWN: Pen down
STUDENT PROVIDES THIS CODE
case TURNRIGHT: Turn right
direction; for example, change from NORTH to EAST
if direction ENDVALUE in case we turn right when facing WEST
direction NORTH;
break;
case TURNLEFT: Turn left
STUDENT PROVIDES THIS CODE
case MOVE: Move forward
cmdNo; move to next command in the command array
we need next value to know how many spaces to move
moveTurtlefloor cmdscmdNo direction, pen, &row, &col; move turtle as required
and update floor as req.
break; end of case MOVE:
case DISPLAY: display the floor matrix
displayFloorfloor;
break;
case ENDOFDATA: end of data reached
break; no action required, will exit dowhile loop automatically
default: should never get here
puts
ERROR invalid command encountered in
turtleDraw switch statement.
;
return; major error, so go home
end of switch statment
cmdNo; move to next command
while cmdscmdNo ENDOFDATA; repeat until end of data is reached
moveTurtle responsible for moving the turtle on the floor and modifying floor if pen is down.
This function is passed pointers to row and col because they need to be passed by reference
because this function must update the row and col when moving turtle. Note that
floor is also passed by reference, but because an arry name is a pointer, the array
is automatically passed by reference.
void moveTurtleshort floorNCOLS const int numOfMoves, const enum Dirs currDir, const short penPos, int rowPtr, int colPtr
STUDENT PROVIDES THIS CODE
end of moveTurtle
Responsible for displaying the floor
void displayFloorconst short floorSurfaceNCOLS
for int i ; i NROWS; i
for int j ; j NCOLS; j
if floorSurfaceij
printf;
else
printf;
printf
;
STUDENT PROVIDES THIS CODE:::::::
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