CS368 Homework 6
Check here periodically.
Jumble™ is a word puzzle, often found in newspapers, where a person is presented with four "common" words whose letters have been scrambled. The goal is to unscramble the words and find the solution for a quip presented along with a cartoon (which typically involves a play on words).
For this homework you will write an interactive MATLAB program that lets a user get practice solving 6-letter words jumbles.
This homework will give you experience writing code with more complicated control flow, writing and using functions, and validating user input.
The program has been broken up into several pieces, some of which are provided for you. These pieces are:
The steps below lead you through the implementation of the Jumble Generator program.
The getNumJumbles function (6 points)
The getNumJumbles function takes no arguments and returns a positive scalar integer value representing the number of jumbles the user wishes to attempt. The getNumJumbles function should ask the user for the number of jumbles they wish to attempt and then check if the value entered by the user is a valid (i.e., a positive scalar integer value). If the value is not valid, it should also display a message indicating why the value is not valid and the user should be asked to enter another value; if that value is not valid, it should display a message and the user should be asked again to enter another value; and so on. A value is not valid if
The function should continue to ask the user for a value until the user enters a valid value. For example, getNumJumbles() should result in the following in the Command Window if the same sequence of values is entered by the user (user-entered values are have been put in bold green to make it easier to distinguish user input from what the program is causing to be displayed):
Number of jumbles to attempt: [1 2] Number must be a scalar Try again: -8 Number must be positive Try again: 2.3 Number must be an integer Try again: 7
The value returned by getNumJumbles() in the example above is 7.
Complete the getNumJumbles function. Start with this getNumJumbles.m file and modify it.
Test your getNumJumbles function thoroughly. Make sure to try values so that each of the messages gets displayed. Also, make sure to check boundary conditions. Note: you do not need to check for (or worry about) the user entering a single character.
The checkGuess function
The checkGuess function takes two arguments (the guess and the correct word) and returns true (1) or false (0) depending on whether the guess and the correct word are the same (ignoring differences in case).
The checkGuess function has already been written and is provided in the checkGuess.m file. You should not change the checkGuess function.
The solveOneJumble function (8 points)
The solveOneJumble function takes one argument (the word the user is to guess) and does the following:
Note: the sovleOneJumble function should be case insensitive, i.e., it shouldn't matter if the user enters text as lower-case, upper-case, or a mixture of both.
Complete the solveOneJumble function. The file solveOneJumble.m has been provided as a starting point. To receive full credit, you must call the checkGuess function within your solveOneJumble function. See the sample run below for the user prompt and output displayed by calls to solveOneJumble.
The jumbleGenerator script (6 points)
We can now put all the pieces together. The main script should do the following:
The file jumbleGenerator.m contains an outline for the Jumble Generator program as well as the code that reads in the list of 6-letter words. Use it as a starting point. Note that jumbleGenerator is a script, not a function. To play the game, you just run the jumbleGenerator script.
Below is sample run of the program (as before, user-entered values are shown in bold green).
Number of jumbles to attempt: 5 oeshwd Enter guess or Q to quit: showed Correct btbari Enter guess or Q to quit: rabbit Correct uraseq Enter guess or Q to quit: quasar guess does not contain the correct letters uraseq Enter guess or Q to quit: square Correct ignact Enter guess or Q to quit: intact guess does not contain the correct letters ignact Enter guess or Q to quit: ACTING Correct ylmpsi Enter guess or Q to quit: smily guess is not the correct length ylmpsi Enter guess or Q to quit: simple guess does not contain the correct letters ylmpsi Enter guess or Q to quit: limpsy ylmpsi Enter guess or Q to quit: q The word was: simply # jumbles attempted: 5 # jumbles solved: 4
Tips and hints:
Upload your m-files to your Dropbox in Learn@UW. See these instructions for uploading files to a Learn@UW Dropbox. The files you should upload are:
In order for your work to be considered to have been turned in on-time, you must upload your files to your Learn@UW Dropbox by 11:59 pm Friday, April 22.
|Last Updated: 4/11/2016 © 2016 Beck Hasti, email@example.com|