Prog 3: Typing

Create a typing tutor program that prompts for words to type, keeping track whether or not you spell them correctly, within a time limit.

For this program you can choose either to type commonly misspelled words, or to type randomly selected words from a large dictionary. The first time you use the large dictionary all the presented words are of length 5. Each time after that the word length goes up by one, unless reset. A score is calculated from the number of words correctly spelled and typed along with the length of time it takes.

Running the program can be seen in the output shown below, which for your convenience can be downloaded as a Google doc. Note that when run on your own machine, or interactively within Zybooks the output will likely be different, since the sequence of random numbers and/or the length of time for each move will be different. Running the test cases, however, should give you the same output every time. Be sure to read the notes given below the sample output, at the bottom of this page.

Prog 3 sample output

Notes:

  1. For this program you are not given starter code. You need to yourself think about the steps needed to write the program. I suggest you create an outline using comments, which you can then fill in gradually, step by step. (Remember how to eat a bicycle? One small piece at a time.) Don't try to just write the whole thing at once. The principal given in the syllabus to limit functions to ~50 lines is a good one, though if it makes a function more clear, it is ok to have 50-100 lines in a function.

  2. While you don't have starter code, you do have three sample programs (see links at the bottom of this page) illustrating areas of functionality that you will need for this program, along with two data files with lists of words. I recommend you explore (run, modify, and understand) these programs in detail before you launch into writing your program.

    1. randomNumberDemo.cpp Demonstrates how to get random numbers, including how to get random numbers within a particular range. It is very important that you call the random number generator the minimum number of times necessary in your program, otherwise your output will not match the test cases.

    2. readFromDictionary.cpp Illustrates how to read from a data file into a vector, and also shows how to compare two strings.

    3. timerDemo.cpp Shows how we can take time stamps and do a calculation to determine how many seconds have elapsed.

    4. dictionary.txt The dictionary of a few hundred thousand standard dictionary words, which you will read into a vector.

    5. misspelledWords.txt A list of a bit over a hundred commonly misspelled words. Each line has the commonly misspelled word, followed by the correct spelling. These should be read into separate vectors.

  3. The menu option to lookup a word from the large dictionary must use binary search and must display the word at the midpoint on each iteration.

  4. As mentioned above, it is critical that you follow the guidelines given here for getting random numbers, so that your sequence of random numbers matches those expected by the Zybooks test cases, as follows:

    1. Within main() in your program you should seed the random number generator with the value 1. The line of code to do this is: srand( 1); Only do this once, in main(), at the beginning of your program, outside of any loops and before you do anything with random numbers.

    2. You will need to use random numbers to select the index positions of random words to be used. You should call the random number generator the minimum number of times possible, otherwise your output will not match.

    3. When selecting the menu option 2 to "Quickly type some random words" you will use the large dictionary (dictionary.txt). The first time will only select words of length 5. After typing in that word list at that level, the next time the length should increase to 6, and so on, increasing by one each time this menu option is selected. To implement selecting words of a particular length you must use the vector of all the dictionary words and must select words within a loop. In the loop you should use rand() to generate an index value and then check to see if the word at that index position is the correct length using the string length() function. If it is the correct length you should store it for use, and if not continue back up to try again. This will end up calling the random number generator many times and will result in the selection of the required number of words, all of the correct length.

  5. Pay careful attention to spacing and spelling of output, so that your program's output will match what is expected.

  6. The score on each turn is calculated as follows:

    1. Going over or under time: Each "turn" takes 15 seconds. The bonus for finishing early is numberOfSecondsUnder15 * 2. The penalty for finishing late is numberOfSecondsOver15 * 3

    2. Number correct: Each correctly spelled word (numberOfPointsPerWord) earns 3 points when using the commonly misspelled words. When using the large dictionary, for each correctly spelled word the numberOfPointsPerWord is wordLength - 4.

    3. Number incorrect: Each incorrectly spelled word is assessed numberOfPointsPerWord * 2 where numberOfPointsPerWord is defined under the "Number correct" category immediately above.