ECS 40 Program #8

ECS 40 Program #8 (50 points, 1.5 hours ) Spring 2016
Due : Wednesday, May 25th at 11:59 in p8 of cs40a.
New concepts: map, set, algorithm. File named: authors.csv, scrabble.cpp
You are to write a program that will read a file of scrambled 7-letter strings, and then prints out the highest valued legal Scrabble word(s) of each string. Before reading the file, your program will store a list of words read from the file words.txt. That file contains both legal and illegal words. Scrabble words are up to seven letters long, and are only composed of lowercase alphabetic characters. Your program will have to avoid storing the illegal words.
Your program should have an STL map that has strings that are mapped to ints, of type WordMap. The strings will be the legal scrabble words found in words.txt, and the ints will be Scrabble value of the word.
You must create a map of letters to values name letterMap, and use the map in determining the value of a word. The values, from ‘a’ to ‘z’ are 1, 3, 3, 2, 1, 4, 2, 4, 2, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, and 10. I initialized an array of ints, named letterValues with these values, and then inserted into the map.
The toughest part of this program is designing an algorithm to test all of the permutations of the file string and its substrings. You must use rotate and/or next_permutation to help in this task. Besides p. 878 in the text, you will find more information on the web by searching for “STL rotate”, or “next_permutation”.
You are not allowed to use any arrays or pointers in this program, other than letterValues. There may be only two sets of “[]” in your entire program: 1) The initialization statement for letterValues, and 2) Inside the for-loop that inserts into letterMap. I used an STL set to hold the best words for a given word, but you are welcome to try something else. Your program must compile without warnings when compiled with –Wall –ansi. Your output must match mine exactly! You will find words.txt, File1.txt, File2.txt and my scrabble.out in ~ssdavis/40/p8.
[ssdavis@lect1 p8]$ cat File1.txt
abcdefg
ableujk
ttabeed
olbisha
abjects
ytvxyzk
[ssdavis@lect1 p8]$
[ssdavis@lect1 p8]$ scrabble.out File1.txt
9 abcdefg: badge cafe face
15 ableujk: jake juke
10 ttabeed: abetted
13 olbisha: abolish
17 abjects: abject
0 ytvxyzk: No words found.
[ssdavis@lect1 p8]$
[ssdavis@lect1 p8]$ cat File2.txt
b glefh
rot tes
qui bbb
abc def
[ssdavis@lect1 p8]$
[ssdavis@lect1 p8]$
13 b glefh: behalf
6 rot tes: protest rosette
13 qui bbb: quid quip quit quiz
11 abc def: deface facade
[ssdavis@lect1 p8]$
scrabble.out File2.txt