Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ You should upload each .cpp and .h file separately. In this homework, youll get to write a spell checking program. This will serve as

C++ You should upload each .cpp and .h file separately.

In this homework, youll get to write a spell checking program. This will serve as a partial review of streams and some of the containers of the standard library. You should write a header file SpellCheck.h that declares all of the required functions with careful documentation based on the style demoed in the review lectures and a file SpellCheck.cpp that implements all of the required functions. You should also write main.cpp that contains a main routine that will allow the user to enter the name of a file local to the source code folder that will have its spelling checked, with asterisks surrounding each word that is found mispelled. In the hints section, the logical sequence of events, practically pseudo-code, are provided. You can also find dictionary.txt, containing the set of valid spellings (actually that file has a bunch of weird things I dont think are words but thats what happens when you download a random dictionary of words from the internet), and example.txt (the example text where a spell check is done as a test case).

The basic functionality is that...

the user is prompted for a file name to perform a spell check on. That file will be stored in the same folder as the source code.

for each word in that file, the spelling will be checked (this excludes any punctuation marks at the end and also converts a first-letter that is uppercase to a lowercase except for the word I).

the entire input file, with all of its whitespace preserved, will be printed to the console, with asterisks * surrounding words that have been mispelled.

we define the valid spelling of a word, other than I, as either the spelling beginning with a lowercase letter or the spelling beginning with an uppercase letter; for example, Rice and rice are both valid spellings, but rICe is not. You must...

use a std::unordered set, found in the header, to store the dictionary words (use it just like a std::set but it is more appropriate in this context, which well see in several weeks) and std::vector to store the strings that will be printed to the console;

write a helper function isWhiteSpace that accepts a char and returns a bool, true if the character is white space (a space, tab, new line) and otherwise false;

write a helper function dePunctuate, returning void, that accepts a string as an input, removes its terminating punctuation mark and makes the first letter lower case;

write a helper function isValidWord that accepts the collection of dictionary spellings and a depunctuated word to check, returning true if the word has a valid spelling and otherwise false; write a helper function finalPuncuation that returns a bool, true if the final character is a punctuation mark and otherwise false.

You may...

assume the dictionary file will always be called dictionary.txt and will be stored in the same folder as the source code;

assume the only possible punctuation marks that could appear are . , ! ? ; : with a - only appearing as part of a word;

assume that there are no ellipses ...; assume there are no or used as quotations;

assume there will never be two punctuation marks next to each other;

assume the file will never end in white space.

Be sure that you can read each word from the dictionary file, one word at a time. This will require working with file streams. Try reading each word from the file and printing it to the console (or maybe every 100th word given how many words there are!). 2. Read over the member functions of std::set (and std::unordered set behaves much the same). In particular, there is a find member function that returns an iterator and an insert function. Write code that can read every word from the dictionary file and store it in the multiset.

The practical implementation can be summarized by...

get a vector ready that can store the entire display as a collection of words and strings of white space

read as much white space as possible from the file that is being spell-checked, one char at a time, using peek, get (described below) and isWhiteSpace and store the overall white space as a string to be printed in the std::vector storing the final display;

at this point, there is a word and the word (including its punctuation mark if present) should be read from the stream, then check if that word has a valid spelling (by using dePunctuate and isValidWord) and if the spelling is valid, store it (including its punctuation mark if present) for printing in the std::vector and otherwise

check if the word ends with punctuation or not with finalPunctuation; depending on whether its final character is a punctuation mark, the word stored for printing should be formatted differently and stored in the std::vector. Note the asterisks should pad either side of the word if it is spelled incorrectly but not the punctuation mark at the end of the word if there is one.

repeat this until the stream is exhausted.

Then print all the std::strings from the vector. If c is a char, the following lines of code will convert c to lowercase if it is uppercase. This works because chars are internally stored as integer types. if ( (A

image text in transcribed

The desired output given example.txt with dictionary.txt is provided below Enter file to spell check: example.txt That Time I Tried Skateboarding *oNce* upon a time, I was at a *sleepover* at *rfriend's* *plce. we were evil *kds i and we made some prank callsandafterwards,my friend "uggestedI learn to skatebo ard. I was a little reluctant, but at 2 *a 1 didn't have the wisdom to "jsut" say no Things began all right: I could balance quite "welll when standing on the board as it rested on the grass And I could even balance a little on the board when it was rougly stationary on t he sidewalk. "Naturily, the next thing to try was a little skateboarding from the sidewalk onto the road Gracefully, I pushed myself and the skateboard forward, toawrds the road. Unbekno nst to me, however, was the fact that the curb was very, very steep: there was no gentle g radient but an abrupt drop of about a foot And so, I lost my balance and fe11 offf the b ard. The board glided smothleyinto the street and I, instinctively, flailed my arms bac kwards as I fel1 and managed to land perfectly on my left middle finger. ouch! I told myfrined" that my finger really hurt and he said, that it would be better in the morning. I agreed We went back in the house and eventually slept. It wasn't until the next day, after my parents picked me up, when my finger was "aabsolutelythrobbing that I suggested the p ssibility that my finger was broken A few hours later, after some x-rays indeed ny middle finger was broken. So I ha d to wear this claw-1ike cast on my hand fr about a month. And that was the first and las t time I tried to skatboard

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

Explain the five stages of the human information processing model.

Answered: 1 week ago