Introduction to C - Programming Assignment #6

Note: To be completed in C

Due Date: Consult WebCourses, NO LATE ASSIGNMENTS ACCEPTED!!!

Objective

1. To learn how to utilize structs in a C program.

2. Following given design specifications.

Problem: Jumble (jumble.c)

Jumble is a fun game that frequents newspapers. The basic goal is that an arrangement of letters is presented, such as

NTGAY

Your goal is to rearrange the letters to form a word. In this case the solution is

TANGY

When the game is presented in the newspaper, only arrangements of letters that have one unique solution are used.

But, for this problem, you may be given arrangements of letters that have zero or multiple solutions. In all cases, you must simply print out all solutions.

To clearly specify your task and how it is to be solved for this assignment (there are other ways to solve it), you will be given input from two files and asked to produce output to the screen in a very specific format. PLEASE FOLLOW THESE DIRECTIONS EXACTLY. YOUR GRADE DEPENDS ON IT.In addition, you will be given a struct you must use, as well as a method of solution you must use. Please follow these directions.

Constants and Struct to Use, Variable to Use in main

Please define the following constants and struct:

#define MAX_WORD_LEN 6

#define MAX_NUM_WORDS 30000

typedef struct {

char word[MAX_WORD_LEN+1];

char sort[MAX_WORD_LEN+1];

} jumble_type;

In your main function, declare the following variable, which will store the dictionary of words:

jumble_type list[MAX_NUM_WORDS];

Algorithm to Solve the Problem

Please solve the problem in the following manner:

When you read in each word from the dictionary file, store in each jumble_type variable the word itself in the component variable word.

After reading each one of these, copy these contents into the component variable sort.

Then, sort the letters in sort, in alphabetical order. Thus, if our dictionary consisted of the words apple, banana, caper, and donut, then we would store the following:

The sort function should have the following prototype (though you can give it a different name):

void bubblesort(char letters[], int length);

Once the dictionary is stored, to determine which words match to a jumbled set of letters, do the following:

1) sort the jumbled set of letters

2) For each jumble_type item in the array list,

a) Check to see if the sorted set of jumbed letters equals the component sort.

b) if so, output the corresponding original word in the word component of this struct.

3) If no words are outputted, then there are no solutions. In this case a different message can be printed by keeping track of how many solutions were previously printed out.

Dictionary Input File Format (jumbledct.txt)

The first line of this input file, jumbledct.txt, will contain a single positive integer, n, which is 30000 or less. The next n lines will contain 1 word each, with only 5 or 6 lowercase letters. (This file has been especially culled for the Jumble game for adults, which only features 5 and 6 letter words.) Each of these lines contains one word for the dictionary. The words will be sorted in alphabetical order.

Input File Format (jumble.txt)

The other input file, jumble.txt, will have all the jumbles to solve. The first line of this file will contain a single positive integer, k (k < 100), representing the number of jumbled words to solve. The following k lines will contain 1 arrangement of 5 or 6 lowercase letters each, to “unjumble.”

Output Format (output to screen)

For each input case, create a header with the following format:

JUMBLE PUZZLE #m: W

where m is the input case number, starting at 1 and W is the jumbled input word (in lowercase letters).

If there are no solutions for this puzzle, output the following single line:

Sorry, this puzzle has no solutions.

Alternatively, output each solution to the puzzle, with one word of output per line.

Separate input cases with one blank line.

Sample Input File (jumble.txt)

6

hactb

aihkk

bircaf

heelax

pmrtay

toersc

Sample Output

JUMBLE PUZZLE #1: hactb

batch

JUMBLE PUZZLE #2: aihkk

khaki

JUMBLE PUZZLE #3: bircaf

fabric

JUMBLE PUZZLE #4: heelax

exhale

JUMBLE PUZZLE #5: pmrtay

Sorry, this puzzle has no solutions.

JUMBLE PUZZLE #6: toersc

corset

coster

escort

rectos

scoter

sector

Deliverables

You must submit your solution to this problem, jumble.c, over WebCourses. THERE WILL BE NO LATE ASSIGNMENTS ACCEPTED!!! PERIOD.

Restrictions

Although you may use other compilers, your program must compile and run using gcc. Please use Code::Blocks to develop your program. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include ample comments throughout your code describing the major steps in solving the problem.

Grading Details

Your program will be graded upon the following criteria:

1) Following required design specifications (20%)

2) Whether or not the program compiles in gcc on Code:: Blocks (20% ALL OR NOTHING)

3) Execution points (60% - 60 input cases will each be worth 1 pt. You must get an input case completely correct to earn the point for that case.)