Question
Array Processing - Dictionary Program NOTE: Review the parallel array example from class Another method of...
Array Processing - Dictionary Program NOTE: Review the parallel array example from class Another method of "Sequentially Searching an Array" is covered in the book in Chapter 8. Using Notepad, write psuedocode ONLY for the following situation. Create and load an array with the following 7 values. Add one more word (of your own choosing) for a total of 8 words. biff comely fez mottle peruke bedraggled quisling Create a second array (parallel array). To hold the defintions to these words. You will need to look up the definitions. - Be sure to use lowercase, as shown above. This will make the processing easier. - Use an external .TXT file to load the words and the definitions into the arrays ( words.txt and definitions.txt). Ask the user to enter a word - Search through this array until you find a match with the word the user entered. - Once you find a match, output "Yes, that word is in the dictionary" and output the definition. - If you get to the end of the array and do NOT find a match, output "No, that word is not in the dictionary". - The program should work with any set of words and definition in the arrays. If I were to change the words and definitions in the arrays, it should still work.
Answers
Psuedocode:
START // initialising arrays wordsArray and defArray with size 8 len = 8 // length of array wordsArray[len] defArray[len] // open words.txt file and write each line to wordsArray array wFile = open "words.txt" i = 0 // maintains index of array for each line in wFile: wordsArray[i] = line i++ // open definitions file and write each line to defArray array defFile = open "definitions" j = 0 // maintains index of array for each line in defFile: defArray[j] = line j++ // take input a word to search from user searchWord = input from user // boolean flag to check word found in array or not found = false // iterate on the array of wordsArray for k = 0 to (len - 1): // if search word matches with the current word in the array at index k // print definition of this word stored at kth index in defArray array if wordsArray[k] == searchWord: print "Yes, that word is in the dictionary" print defArray[k] break // break the loop if search successfull // if search is unsuccessfull if found == false: "No, that word is not in the dictionary" END
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 START // initialising arrays wordsArray and defArray with size 8 len = 8 // length of array wordsArray[len] defArray[len] // open words.txt file and write each line to wordsArray array wFile = open "words.txt" i = 0 // maintains index of array for each line in wFile: wordsArray[i] = line i++ // open definitions file and write each line to defArray array defFile = open "definitions" j = 0 // maintains index of array for each line in defFile: defArray[j] = line j++ // take input a word to search from user searchword = input from user // boolean flag to check word found in array or not found = false // iterate on the array of wordsArray for k = 0 to (len - 1): // if search word matches with the current word in the array at index k // print definition of this word stored at kth index in defArray array if wordsArray[k] == searchword: print "Yes, that word is in the dictionary" print defArray[k] break // break the loop if search successfull // if search is unsuccessfull if found == false: "No, that word is not in the dictionary" END 27 28 29 30 31 32