Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++!! vector spellCheck(istream& in, const vector & dictionary, const vector & excluded) { ....... } Part 2 - spellcheckO Your function will return a vector

C++!!

image text in transcribed

vector spellCheck(istream& in, const vector<:string>& dictionary, const vector& excluded) { .......

}

Part 2 - spellcheckO Your function will return a vector of WORD structures, where each entry contains the misspelled word, along with a vector of the byte position in the file where the word was encountered. The WORD structure is defined in the header file. For instance, if the word "artcic" (a misspelling of arctic) was found three times in the input stream, there would be one entry in the returned vector, and it would contain data like this: word: artic pos: 7, 95, 89 Here's the pseudocode for your function which takes an istream& and two const vector& parameters (the dictionary and the ignored words): Create the empty results vector Read until end of file (while in) Save current position (in.tellg() ->cast to long Long) If tellg() returns -1 (at end of file) Then Exit the Loop Read next word (in > word >> ws) Convert to Lowercase, remove punctuation Search the List of misspelled words (results)-set found If found word Then Add position to results ElseIf not found If found word Then ElseIf not found If found word Then (Not misspelled) ElseIf not found Go to top of Loop Search the List of excLuded words ->found Go to top of Loop Search the dictionary->found Go to top of Loop Create a WORD, populate with word, position Add new WORD to results End Loop Return results (misspelled words and their positions) You can do this with a series of nested if else statements. However, the continue statement makes it quite a bit easier. The continue statement will jump back to the top of the loop, much like break jumps out of a loop. You can use continue to avoid a series ofif! found) blocks in uour code Part 2 - spellcheckO Your function will return a vector of WORD structures, where each entry contains the misspelled word, along with a vector of the byte position in the file where the word was encountered. The WORD structure is defined in the header file. For instance, if the word "artcic" (a misspelling of arctic) was found three times in the input stream, there would be one entry in the returned vector, and it would contain data like this: word: artic pos: 7, 95, 89 Here's the pseudocode for your function which takes an istream& and two const vector& parameters (the dictionary and the ignored words): Create the empty results vector Read until end of file (while in) Save current position (in.tellg() ->cast to long Long) If tellg() returns -1 (at end of file) Then Exit the Loop Read next word (in > word >> ws) Convert to Lowercase, remove punctuation Search the List of misspelled words (results)-set found If found word Then Add position to results ElseIf not found If found word Then ElseIf not found If found word Then (Not misspelled) ElseIf not found Go to top of Loop Search the List of excLuded words ->found Go to top of Loop Search the dictionary->found Go to top of Loop Create a WORD, populate with word, position Add new WORD to results End Loop Return results (misspelled words and their positions) You can do this with a series of nested if else statements. However, the continue statement makes it quite a bit easier. The continue statement will jump back to the top of the loop, much like break jumps out of a loop. You can use continue to avoid a series ofif! found) blocks in uour code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago