Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 : Setup Write a C program called scrabble, which reads in a list of words and their location on the board, places them

Problem 1: Setup
Write a C program called scrabble, which reads in a list of words and their location on the board, places
them to the board, and then displays the board.
Input
Your program will read its input from stdin. The remainder of the input consists of several lines:
The first line contains a single integer (N) denoting the size of the board (N
N).
The second line contains a second integer (W) denoting the number of words to place.
This is followed by W lines, each containing the location (X,Y), direction (D), and the word (S).
X Y D S
where
X is an integer in the range 0 X < N, denoting the X coordinate of the first letter of the word
Y is an integer in the range 0 Y < N, denoting the Y coordinate of the first letter of the word
D is either H or V, denoting the direction of the word. H for horizontal (left to right) and V for
vertical (top to bottom).
S is a single lower-case word which will be one or more letters.
Finally, there is another integer (F), which for this problem will always be 0.
All words will be in lower-case letters. (Hint: Use scanf to read the input). See example below.
Processing
The program should use a 2D array to represent an (N
N) scrabble and add the words to this board.
To allocate a 2D array of characters use the declaration:
char board[n][n];
in the main() function after your program has read in the value for N and stored it in variable n.
The top-left corner of the board has coordinate (0,0) and the bottom right corner is (N-1,N-1).
Empty spaces are represented by periods (.). Hint: initialize all board elements to . before plac-
ing any words.
Horizontal words are placed left to right and vertical words placed top to bottom.
All words will be correctly placed.
Output
All output should be performed to stdout. The output must be exactly as specified. The output should
consist of an N
N block of characters representing a Scrabble board with the word placed on it. The top-
left corner of the board is location (0,0) and the bottom right corner is (N-1,N-1). All words should be in
lower case

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_2

Step: 3

blur-text-image_3

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