Answered step by step
Verified Expert Solution
Link Copied!

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..... 2::: CODE IS GIVEN HERE JUST COMPLETE THIS CODE TO GET THE OUTPUT GIVEN IN PICTURE WITH BORDERS...3::: ONLY C PROGRAMMING...
#define _CRT_SECURE_NO_WARNINGS
#include
// function prototypes
void turtleDraw(const int[]);
int main()
{
int commands[]={5,5,4,5,9,2,// go to start of first letter and put pen down
// B
5,12,1,3,5,1,4,2,5,1,1,3,5,1,2,5,2,1,3,5,1,4,2,5,1,1,3,5,1,2,5,11,3,5,5,
1,3,5,12,3,5,5,5,1,4,2,5,1,1,3,5,1,2,5,2,1,3,5,1,4,2,5,1,1,3,5,1,2,5,11,3,5,5,
1,5,5,3,5,22,2,// go to start of next letter and put pen down
// O
5,10,1,3,5,1,4,2,5,1,1,3,5,1,2,5,7,1,3,5,1,4,2,5,1,
1,3,5,1,2,5,10,1,3,5,1,4,2,5,1,1,3,5,1,2,5,7,1,3,5,1,4,2,5,1,
1,3,5,19,2,// go to start of next letter and put pen down
// B
5,12,1,3,5,1,4,2,5,1,1,3,5,1,2,5,2,1,3,5,1,4,2,5,1,1,3,5,1,2,5,11,3,5,5,
1,3,5,12,3,5,5,5,1,4,2,5,1,1,3,5,1,2,5,2,1,3,5,1,4,2,5,1,1,3,5,1,2,5,11,3,5,5,
1,6,9}; // finish off
// Invoke function which will execute commands
turtleDraw(commands);
}
// define 2 enum types
enum TCmnds { PEN_UP =1, PEN_DWN =2, TURN_RIGHT =3, TURN_LEFT =4, MOVE =5, DISPLAY =6, END_OF_DATA =9};
enum Dirs { BEGIN_VALUE, NORTH, EAST, SOUTH, WEST, END_VALUE };
#define NROWS 22// number of rows in floor
#define NCOLS 70// number of colums in floor
#define TRUE 1
#define FALSE 0
const unsigned int STARTING_ROW =0;
const unsigned int STARTING_COL =0;
const enum Dirs STARTING_DIRECTION = SOUTH; // direction that turtle
// will be facing at the start
const short STARTING_PEN_POSITION = FALSE; // Pen will be up when
// some more function prototypes
void displayFloor(const short[][NCOLS]);
void moveTurtle(short[][NCOLS], const int, const enum Dirs, const short, int*, int*);
// turtleDraw()- function responsible for executing commands
void turtleDraw(const int cmds[])
{
short floor[NROWS][NCOLS]={ FALSE }; //init to all FALSE (0).
enum Dirs direction = STARTING_DIRECTION; // used to represent current direction that the turtle is moving
unsigned int row = STARTING_ROW; // used to represent current row that turtle is at
unsigned int col = STARTING_COL; // used to represent current column that turtle is at
short pen = STARTING_PEN_POSITION; // starting position of pen (up or down)
//0 is up,1 is down
int cmdNo =0; // The position in cmds array we are currently processing
do {// until END_OF_DATA is encountered
switch (cmds[cmdNo]){// Switch statment that processes commands
case PEN_UP: // Pen up
pen = FALSE;
break;
case PEN_DWN: // Pen down
// STUDENT PROVIDES THIS CODE
case TURN_RIGHT: // Turn right
++direction; // for example, change from NORTH to EAST
if (direction >= END_VALUE)// in case we turn right when facing WEST
{
direction = NORTH;
}
break;
case TURN_LEFT: // 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
moveTurtle(floor, cmds[cmdNo], direction, pen, &row, &col); // move turtle as required
// and update floor as req.
break; // end of case MOVE:
case DISPLAY: // display the floor matrix
displayFloor(floor);
break;
case END_OF_DATA: // end of data reached
break; // no action required, will exit do-while 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 (cmds[cmdNo]!= END_OF_DATA); // 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 moveTurtle(short floor[][NCOLS], 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 displayFloor(const short floorSurface[][NCOLS])
{
for (int i =0; i NROWS; i++){
for (int j =0; j NCOLS; j++){
if (floorSurface[i][j]){
printf("*");
}
else {
printf("");
}
}
printf("
");
}
// STUDENT PROVIDES THIS CODE:::::::
}
image text in transcribed

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago