word-puzzle.c file, a working Makefile, and tests.txt to Gradescope under the corresponding assignment.
You may submit as many times as you like up until the deadline.
In this assigment you will write a program that solves a word-find puzzle, similar to those found in newspapers.
The input data will be a grid of characters (the puzzle board) followed by a list of words. The object of the puzzle is to search the puzzle board for the words in the word list. Words may appear in the puzzle board horizontally or vertically (but not diagonally). Horizontal words will run left to right; vertical words will run top to bottom. Words will not “wrap around” in either direction, so for example, a word could not occupy columns {15,16,1,2}. Each word will appear at most once in the puzzle board.
You will practice many concepts from class to complete this assignment, but one of the newer things we’ve learned is reading fomatted input.
Put your program in a file named word-puzzle.c.
Your program should use an argument to main to specify the name of the file to read from. Review a past lab if you’ve forgotten how to use command line arguments. Then you will need to open and read the file, review the relevant lab on files if needed.
Here is an example of how to run the program:
$ ./word-puzzle puzzle1.txt
The first line of a puzzle file will be the dimensions of the grid: two positive integers, representing the number of rows and number of columns, respectively. The puzzle board is given next. It will consist of a matrix of upper-case letters, with a single space between each character on each row.
Next the file will contain a list of upper-case words, each on a separate line, and each of which could fit within the puzzle board. The number of words is not specified, so your program should read until the end of the file is reached. There will be no blank lines anywhere in the file.
You may assume that any puzzle we use to test your code will be in the correct format.
Your program should print a solution in two formats. First, it should print each word found (in any order), followed by its starting location in the puzzle (in row, column format) and its orientation. Next, it should print a visual key to the puzzle, which is a version of the puzzle board matrix containing only the words which your program has found. All other characters of the board should be removed.
$ ./word-puzzle puzzle-1.txt
THEORY (8, 2) vertical
STRING (5 4) horizontal
ARRAY (6, 5) vertical
GRINNELL (12 1) horizontal
COMPUTER (1 1) horizontal
PHYSICS (8, 3) vertical
CALCULUS (7, 7) vertical
ALGEBRA (5, 11) vertical
SCHEME (8, 15) vertical
NETWORK (4 3) horizontal
PROGRAM (2 4) horizontal
EQUATION (4, 14) vertical
MEMORY (3 1) horizontal
LOGIC (6, 8) vertical
SYSTEM (0 5) horizontal
S Y S T E M
C O M P U T E R
P R O G R A M
M E M O R Y
N E T W O R K E
S T R I N G A Q
A L L U
R C O G A
T P R A G E T S
H H A L I B I C
E Y Y C C R O H
O S U A N E
G R I N N E L L M
Y C U E
S S
This program will likely be more complex than those we’ve written before. You are required to carefully consider the organization and style of your finished program before turing it in. You should decompose your program into smaller functions for readability and maintainability. Here are some basic guidelines to ensure your program is well-decomposed:
Here are some examples to clarify these constraints:
/* WRONG -- the two loops are at the same level.
Place each loop in separate functions. */
for ()
{
...
}
for ()
{
...
}
/* OK -- the two loops are at different levels */
for ()
{
for ()
{
...
}
}
/* WRONG -- the two nested loops are at the same level.
Place each nested loop in a separate function. */
for ()
{
for ()
{
...
}
for ()
{
...
}
}
/* WRONG -- loops are triply nested, one level too deep.
Place at least one loop in a separate function. */
for ()
{
for ()
{
for ()
{
...
}
}
}
In this assignment you will need to use variable length arrays (VLAs). This means that the size of your arrays will need to be stored as a variable that we only know at runtime after reading in the file. There should be no hard coded upper bounds to the size of the puzzle in your code. The same goes for the size of the word list, there should be no hard coded upper bound. Of course, there is an upper bound on the length of the words themselves (based on the dimension of the grid).
Keep in mind that VLAs may not be returned from functions, though they may be passed as paramaters to other functions for use and modification. Carefully consider how you will declare and store the puzzle information.
Your assignment will be graded on a scale of 0–100 points based on the following criteria:
Makefile with correctly-defined targets all, clean, and wordsearch (15 points)tests.txt file describes a reasonably comprehensive set of tests for the implementation (20 points)
tests.txt format from our previous assignment.There will be potential deductions for any code quality violations. In addition to the requirements about decomposition listed above, there are additional requirements for quality code:
if–else block that explains what the purpose of that code is. The comment should not simply restate the code; it should add information for a human who reads the code and is confused.This problem is adapted from Henry Walker, supplemental problem 5.