Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ assigment . Please help e to write the code for h11.cpp: Here is what I have for h11.h: #ifndef H11_H_ #define H11_H_ #include #include

C++ assigment. Please help e to write the code for h11.cpp:

Here is what I have for h11.h:

#ifndef H11_H_ #define H11_H_ #include #include /** * Opens a file and returns a vector containing words. * @param filename contains the path needed to open the file. * @return a vector of words. */ std::vector<:string> fileToWords(const std::string& filename); struct WORD { std::string word; std::vector positions; };

/** Reads any stream until end-of-file. Returns a vector of misspelled words, but not those words that have been excluded. @param in the stream to read from @param dictionary vector of string containing correct-spelled words. @param excluded vector of string containing words to ignore. @return a vector of misspelled words, along with their position in the original file. */ std::vector spellCheck(std::istream& in, const std::vector<:string>& dictionary, const std::vector<:string>& excluded);

#endif

Here is what I have to complete:

#include #include #include #include #include #include using namespace std;

string STUDENT = "WHO AM I?"; // Add your Canvas/occ-email ID

#include "h11.h"

// Complete these two functions vector fileToWords(const string& filename) { vector result; // . . . return result; }

/** Reads any stream until end-of-file. Returns a vector of misspelled words, but not those words that have been excluded. @param in the stream to read from @param dictionary vector of string containing correct-spelled words. @param excluded vector of string containing words to ignore. @return a vector of misspelled words, along with their position in the original file. */ vector spellCheck(istream& in, const vector& dictionary, const vector& excluded) { // 1. Create the empty results vector vector results // 2. Read through the input stream until end of file (while in) // 3. Consume any white space, so we are at the beginning of a word // 4. Find current position (in.tellg()->cast to unsigned long) // 5. If tellg() returns -1 then at end of file so exit the loop // 6. Read next word, convert to lowercase, remove punctuation

// 7. Search the list of misspelled words (results vector) // Found it? Append position to WORD where found, go to top of loop

// 8. Not found? Search the list of excluded words // Found it? Ignore and read the next word (top of loop)

// 9. Not found? Search the dictionary // -- Found it? Not misspelled. Ignore and read the next word // -- No found in the dictionary? The word is misspelled // + Add a new entry (WORD) to the results // containing the word and position where found

} // 10. After loop is over, return the vector // containing the misspelled words and their positions return result; }

/////////////// STUDENT TESTING //////////////////// int run() { cout Here is the prompt:

image text in transcribedimage text in transcribedimage text in transcribed

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 >> wordws) 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 willjump back to the top of the loop, much like break jumps out of a loop. You can use continue to avoid a series of if(! found) blocks in your code. The test program checks against some simple string streams. If you get stuck, then should ask questions on Piazza 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 >> wordws) 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 willjump back to the top of the loop, much like break jumps out of a loop. You can use continue to avoid a series of if(! found) blocks in your code. The test program checks against some simple string streams. If you get stuck, then should ask questions on Piazza

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

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago