Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Using C lanuage. Solve Programming Project 3, p.217, of Chapter 9 by creating a program named proj2_2.c . This program is actually the same as

image text in transcribedimage text in transcribed

Using C lanuage. Solve Programming Project 3, p.217, of Chapter 9 by creating a program named proj2_2.c. This program is actually the same as Programming Project 9, p.179, of Chapter 8 but is re-designed to use two functions, each requires to pass a 2D char array as its input. Refer to p.195~7 of Chapter 9 for functions with array arguments.

As a way to help you to build this program and also a requirement of this program, you will use exactly the same lines of code shown below in green in your proj2_2.c without changing anything. Your job here is to complete the rest parts of the program, including a few lines of directives for preprocessing and implementation of the two functions specified on p.217.

void generate_random_walk(char walk[N][N]); void print_array(char walk[N][N]);

int main(void) { char walk[N][N];

srand((unsigned) time(NULL)); generate_random_walk(walk); print_array(walk);

return 0; }

A demo of executable file is available for your testing: proj2_2.exe

Be sure your output display begins and ends with a blank line as seen in the demo.image text in transcribed

9. Write a program that generates a "random walk" across a 10 x 10 array. The array will con- tain characters (all'. ' initially). The program must randomly "walk from element to ele- ment, always going up, down, left, or right by one element. The elements visited by the program will be labeled with the letters A through Z, in the order visited. Here's an example of the desired output: A . B C D . . . . . . . FE.... HG. . . . . . . . A K . . R S T U V Y . LMPO... W X. NO. . . . . . . Hint: Use the srand and rand functions (see deal.c) to generate random numbers. After generating a number, look at its remainder when divided by 4. There are four possible values for the remainder-0, 1, 2, and 3-indicating the direction of the next move. Before performing a move, check that (a) it won't go outside the array, and (b) it doesn't take us to 3. Modify Programming Project 9 from Chapter 8 so that it includes the following functions: void generate_random walk (char walk [10] [101); void print_array (char walk[10] [10]); main first calls generate_random_walk, which initializes the array to contain '.' characters and then replaces some of these characters by the letters A through Z, as described in the original project. main then calls print_array to display the array on the screen. C:\3515\Proj2\Proj2_solution>proj2_2 w DOD ... D Czo. . . Qac.. J. . . . . . SIWX.. . . . . . . An execution that uses all of A ~ Z. .. . . C:\3515\Proj2\Proj2_solution>proj2_2 BCD REF. . . . . . PU. GH NK JI . . . . . An unfortunate execution that uses only A~R. . . . . . . . . ... C:\3515\Proj2\Proj2_solution)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions