Programming Problem Description: you are asked to write a \"puzzle\" program. Wh
ID: 3633564 • Letter: P
Question
Programming Problem Description:
you are asked to write a "puzzle" program. When the user runs this program, the program will output a list of words and a word puzzle in which the words are randomly positioned and random letters are filled around the words. The user is then prompted to hit enter in order to view the puzzle answers where the random letters are replaced with a single character like an underscore so that the user can see all of the words locations.
Programming Problem Instructions:
1) Initialize five constant strings which comprise of the five words that will be randomly placed into the word puzzle. Each word will be only four letters long
and will consist of all capital letters. The programmer can store those words in a single character array with multiple strings or in an array of pointers where each pointer in the array points to each constant string or word.
2) Declare two different arrays for two different puzzles with each containing enough elements for a word puzzle of size 16x16. One puzzle array will contain the words of the puzzle and random characters in every other element and one puzzle array for a clear puzzle that contains only the words of the puzzle and underscore characters in every other element instead of random characters so that the words can be easily found. The arrays could be multidimensional or they could be single-subscripted arrays that are treated like multidimensional arrays. It is suggested to initialize the clear puzzle with all underscores and the main puzzle with a value of zero in all elements.
3) Declare other necessary variables and possibly seed the random function. In
initial stages it is not necessary to seed in order to make debugging easier.Print a header so that the user knows that a list of words will follow.
4) The program will then need to go through the logic of placing each word in both
puzzle arrays without overlapping on another word and without going across boundaries of the table. The logic would look like the following:
a) Pick a word and print it so that the user can see it in the list of words.
b) Pick a random orientation or direction for the word (right, left, up, down).
c) Pick a random starting position that will not cause the word to cross over the side boundaries of the word puzzle based on the chosen direction.
d) Check that this position for the word would not overwrite another word in the puzzle. If it does repeat steps b) and c).
e) If it does not conflict with another word then write the word to both puzzle
arrays (need only to check against one of the puzzle arrays in the previous step).
f) Repeat the previous steps for the next word until all words are placed.
5) Once the words are placed in the array, the program should randomly fill the
unfilled elements of the puzzle array with random capital letters. Then the program should print a header for the puzzle and then print the puzzle array with a space between each letter on each row and a newline between each row.
The user then will be prompted to hit enter if he wants a printout of the clear puzzle. When the user hits enter the clear puzzle should be printed in the same fashion.
Extra Credit Opportunity (20 Points):
Multiple lists of 10 constant words would be built into the program in which each list contains words of different sizes (4, 5, and 6 letters). The user ought to be able to choose between which size to use, and how many words up to the max to place in the puzzle. Each word chosen from the list ought to also be random and the words should not be duplicated. Be cautious of how word size variably affects components of the program. A good way to prepare for thr this portion while developing the main program is to use symbolic constants.
**MAKE SURE YOU INCLUDE A LOT OF COMMENTS THROUGHOUT THE PROGRAM CODE.
Example Outputs:
The words in the puzzle are:
1. HOUR 2. TEST 3. LABS
4. UNIX 5. LOSE
Word Puzzle
R D T F U N I X V T S E T E K Y
F I T A G X D K M T A Y S V W B
R Q E Z R J T I M M P J S A J Y
K C Y S Z E D L Z F L R D I T W
A Z Y U I R C W F S G Z U P X E
S Y W R H O U R C B F B H Q V M
A Q I D P G X X Z B T G T Z G P
F O U R R F V J D S C H V J L E
C G Q E W Z H L H G K J I D P D
F V T Y B O J G I S L Q E X B I
Z H B D F C N S J B T C U B H K
F L O H Y M K O X A T X L J D I
K O L J T M M A Q L B S C V W W
Y S F I D W Q D K C U I V R T G
U E B S H K L W Y N M C H O X D
N X L V D H N G R Q C B N T U W
Want Clear Puzzle? Hit Enter
_ _ _ _ U N I X _ T S E T _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ H O U R _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ S _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ B _ _ _ _ _ _
_ L _ _ _ _ _ _ _ A _ _ _ _ _ _
_ O _ _ _ _ _ _ _ L _ _ _ _ _ _
_ S _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ E _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Below is a template to use when designing your program:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//Step 1
#define WORD_SIZE 4
#define NUM_WORDS 5
const char *WordPtr[NUM_WORDS] = { "HOUR", "TEST", "LABS", "FOUR", "UNIX" };
//if this method is chosen each index of WordPtr points to a different string and so the index can be increased by 1 in order to point to the next string
//or
const char Words[] = "HOURTESTLABSFOURUNIX";
//if this method is chosen a pointer will be needed that can be adjusted to point to the next word when appropriate
// Step 2
//if using single dimensional puzzle arrays, here are some helpful macro definitions
#define COL_SIZE 16
#define ROW_SIZE 16
#ifdef COL_SIZE
#ifdef ROW_SIZE
#define PUZ_SIZE COL_SIZE*ROW_SIZE
#endif
#endif
//Step 7
//Enum
enum Direction {RIGHT, LEFT, UP, DOWN};
//Prototypes
char randChar ();
int randDir ();
int randPos (int dir);
int isOverlap (int dir, int position, char *Puzzle );
void writeWord (int dir, int position, char *Puzzle, const char *Word );
//Given Definitions
char randChar () {
char c;
c = rand()%26 + 65;
return c;
}
int randDir () {
int dir;
dir = rand()%4;
return dir;
}
Explanation / Answer
Sorry but: Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well. Please post like this: Thank you for helping us helping you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.