Question: The small program below roughly represents a robot in a room. The room is dened as a 2 dimensional array of characters. Objects in the

"The small program below roughly represents a robot in a room. The"The small program below roughly represents a robot in a room. The room is dened as a 2 dimensional array of characters. Objects in the room are stored as characters in the array. For example, the location of the robot is stored as an R in the array. The walls of the room are stored in the array as a - for the top and bottom walls and as | for the side walls. The function named setup() puts all of the initial characters into the 2 dimensional array. For this lab you need to use the curses library (see curses handout) to write a function that prints the room. The function should take the room array as an argument (look at the syntax of the setup function to help with passing the array). The function should loop through the entire array, moving to the correct location of the screen and printing the character stored in the array. E.g., the function should move to location (r,c) and print the [r][c]th element of the array for each r and c within the dimensions of the room. #include // include the curses library using namespace std; const int MAXX = 40; // maximum size of the room const int MAXY = 20; void Setup( char[][MAXY], int x, int y ); // room setup int main() { WINDOW *wnd; char room[MAXX][MAXY]; // stores the room int x = MAXX/2, y = MAXY/2; // robots initial location wnd = initscr(); // initializes the window clear(); // clears the window refresh(); // reprints the window Setup(room,x,y); // setup the room with the robot Print(room); // write this function!! WaitForQuit(); endwin(); // frees the screen for normal use } 2 /* Sets up the room, adding walls, and the robot */ void Setup( char room[][MAXY], int x, int y ) { for(int i = 0; i > ch; } while( ch != q ); } Turn in your program and sample output showing the room drawn on the screen. Exercise 8.2 Add code to search the room for the robot. If it is found, mark it with an X, if not, mark the location with a .. Turn in your modied program and sample output showing the room drawn on the screen."

include and explicitly link it during the compiling process. Common libraries are linked automatically, but because the curses library is not always used it has to be explicitly linked. So, to compile a program that includes the curses library type: g++ prog. cpp -lcurses There are a few basic commands (functions) that are a part of any pro- gram using the curses library WINDOW variable name Declares a variable of type WINDOW. For now, ignore the and WINDOW variable Name init cr Connects the WINDOW variable to the screen clear Clears the screen. refresh() Redraws the screen. It must be used every time you want something new to be displayed. endwin(); Ends curses control of the screen. It should go at the end of the pro- gram. NOTE: If you forget to include it at the end of the program, when the program exits the screen will no longer respond properly and you will have to exit and log back on to the system. Note how each of these commands is used in the sample program fragrnent given below. There are three simple functions that help you place and remove charac- ters on the screen move r, c); This function moves the cursor to row r and column c. r and c can be integers, integer variables or integer expressions. insch ch This function places the character ch at the cursor's current position ch can be a character such as 'R' or a character variable. delch() This function deletes the character at the cursor's current location. include and explicitly link it during the compiling process. Common libraries are linked automatically, but because the curses library is not always used it has to be explicitly linked. So, to compile a program that includes the curses library type: g++ prog. cpp -lcurses There are a few basic commands (functions) that are a part of any pro- gram using the curses library WINDOW variable name Declares a variable of type WINDOW. For now, ignore the and WINDOW variable Name init cr Connects the WINDOW variable to the screen clear Clears the screen. refresh() Redraws the screen. It must be used every time you want something new to be displayed. endwin(); Ends curses control of the screen. It should go at the end of the pro- gram. NOTE: If you forget to include it at the end of the program, when the program exits the screen will no longer respond properly and you will have to exit and log back on to the system. Note how each of these commands is used in the sample program fragrnent given below. There are three simple functions that help you place and remove charac- ters on the screen move r, c); This function moves the cursor to row r and column c. r and c can be integers, integer variables or integer expressions. insch ch This function places the character ch at the cursor's current position ch can be a character such as 'R' or a character variable. delch() This function deletes the character at the cursor's current location

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!