This lab requires a different set of instructions to obtain the lab,
but the process to submit it is the same (make submit from inside
your csci160/bonuslab directory).
The lab must be submitted by 5pm on Thursday Nov. 25th, and (since this lab is purely available as a bonus) absolutely no late submissions will be accepted. The "make submit" will cut off submissions at precisely the lab deadline. |
Monday lab groupcd ssh -x csci fork csci160-01/bonuslab csci160-01/$USER/bonuslab cd csci160 git clone csci:csci160-01/$USER/bonuslab |
Friday lab groupcd ssh -x csci fork csci160-02/bonuslab csci160-02/$USER/bonuslab cd csci160 git clone csci:csci160-02/$USER/bonuslab |
Welcome to the dictionary sorter! You will be asked to enter a list of dictionary words (the words that can appear in the user text to be entered later), and the program will read in those words. Afterwards, you'll be asked to enter the sequence of words to be sorted. The program will then display the text, but with the words re-arranged to match the order given in the dictionary. --- Please enter your dictionary words (all on one line, separated by spaces, for example: ok gang lets split up and look for clues I like my dictionary words list for now they are these wow Thank you, now please enter the text to be sorted, again separated by spaces and all on one line, and only using words from the dictionary. my words for now are like these I like my list my dictionary now my list for now The words from your text, rearranged in the given dictionary order, are: I like like my my my my dictionary words list list for for now now are these Thank you for using the dictionary sorter, bye! |
Note that when using getline to cin
to an array of chars the syntax is
char text[80]; cin.getline(text, 80); |
istringstream strm(str); // creating the readable stream from str do { strm >> word; // assuming word is a string var if (!strm.fail()) { // put the word in the dictionary array // (unless the array is already full) } } while (!strm.fail());Having read the words into the dictionary, you can apply a similar technique to read the words of text the user wants sorted. In generating the "sorted" output, we could use one loop going through each word in the dictionary, count how often that word appears in the main text, and display the word that many times:
// for each position, i, in the dictionary // lookup the word in position i // search the main text, counting the number of times that word appears // display the word that many timesAs always, I strongly recommend an incremental development approach.