MATH 173: Object Oriented Programming & Design XXXXXXXXXX Programming Project 4: 1960s Spell Checker Define a class SpellCheck with public members void load_dictionary(istream&); bool find(const...

Write c++ program from file


MATH 173: Object Oriented Programming & Design 2020-12-04 Programming Project 4: 1960s Spell Checker Define a class SpellCheck with public members void load_dictionary(istream&); bool find(const string&) const; vector suggest(const string&, size_t n) const; which is used to check the spelling of words and suggest corrections for misspelled words based on the Levenshtein distance (explained below). Member load_dictionary() copies words from an input stream into a SpellCheck’s storage (which could be a vector of strings). Member find() returns true if its input is in the dictionary, and false otherwise. Member suggest() returns a vector of words from the dictionary which might contain the ”correct” spelling of a word. The SpellCheck class might be used as follows. // open the dictionary file std::ifstream infile("words.txt"); if (!infile.is_open()) throw std::exception(); // store words in the dictionary SpellCheck my_check; my_check.load_dictionary(infile); infile.close(); // Find 3 suggestions for the misspelled word "buble" if (!my_check.find("buble") { std::vector suggestions = my_check.suggest("buble",3); for (string s: suggestions) std::cout < s="">< std::endl;="" "bible"="" "bubble"="" (depends="" on="" the="" dictionary)="" "bugle"="" }="" }="" levenshtein="" distance="" mathematician="" vladimir="" levenshtein="" created="" a="" ”distance”="" function="" for="" strings="" around="" 1965which="" youwill="" use="" to="" correctmisspelledwords.="" this="" ”levenshtein="" distance”="" between="" two="" words="" is,="" roughly,="" the="" minimal="" number="" of="" character="" changes,="" insertions,="" or="" deletions="" required="" to="" transformoneword="" to="" another.="" for="" example,="" the="" levenshtein="" distance="" between="" ”bible”="" and="" ”bubble”="" is="" 2="" because="" the="" trnasformation="" ”bible”="" →="" ”buble”="" →="" ”bubble”="" requires="" (1)="" converting="" the="" ”i”="" in="" ”bible”="" to="" ”u”,="" and="" then="" (2)="" inserting="" a="" ”b”="" before="" the="" ”l”="" in="" ”buble”,="" and="" this="" is="" the="" minimal="" number="" of="" such="" moves="" for="" the="" conversion="" (which="" is="" not="" hard="" to="" prove).="" member="" function="" suggest()="" must="" compute="" the="" levenshtein="" distance="" between="" the="" given="" word="" and="" all="" the="" words="" in="" the="" dictionary="" (or="" a="" subset="" of="" words="" with="" nearly="" the="" same="" number="" of="" letters).="" then="" suggest()="" must="" return="" a="" vector="" of="" words="" with="" minimal="" leven-="" shtein="" distance="" among="" all="" words="" in="" the="" dictionary.="" the="" number="" of="" words="" returned="" is="" the="" second="" argument="" to="" suggest().="" note:="" if="" there="" are="" numerous="" ties="" for="" minimal="" distance,="" just="" use="" the="" ones="" which="" appear="" earlier="" in="" the="" dictionary.="" (really="" i="" don’t="" have="" a="" preference="" here.="" if="" there="" are="" 50="" words="" in="" the="" dictionary="" with="" levenshtein="" distance="" 1="" to="" the="" misspelled="" word,="" and="" you="" have="" to="" choose="" only="" 3,="" i="" don’t="" care="" how="" you="" choose="" them.="" just="" do="" what="" is="" easiest.)="" storage="" you="" can="" use="" std::set="" from="" library=""> for storing the dictionary. The set should be private in the SpellCheck class. (Give it any name you like.) The set class represents a collection of objects, like vector, but the objects in a set are automatically sorted and unique. Memebers insert() and find() can be used as their names describe. However, find() either returns an iterator1 to themember it finds, or returns an iterator to a sentinel not in the set, if nothing is found. Member function end() returns this special object. For example, std::set my_set; // A set of strings my_set.insert("banana"); my_set.insert("apple"); my_set.insert("pear"); // my_set is now {"apple","banana","pear"} if (my_set.find("tomato")) ... // error, find() doesn’t return a bool if (my_set.find("tomato") == my_set.end()) std::cout < "not="" found.";="" else="" std::cout="">< "i found tomato!"; so to check if a object is in a set, you can check if (my_set.find("target object") != my_set.end()) and to check if an object is not in a set, you check if (my_set.find("target object") == my_set.end()) or anything equivalent to this. important • the name of the class must be spellcheck (case sensitive). the member functions must be named exactly as given above. • define the class in a file named spellcheck.h and implement its member functions in a file named spellcheck.cpp. these names are case sensitive. • please begin by writing spellcheck.h and verifying its correctness with the instructor. then start implementing the functions in spellcheck.cpp. 1 an iterator is a generalized pointer. references 1. levenshtein distance on wikipedia: https://en.wikipedia.org/wiki/levenshtein_distance (viewed on 2020-12-03) 2. std::set https://en.cppreference.com/w/cpp/container/set "i="" found="" tomato!";="" so="" to="" check="" if="" a="" object="" is="" in="" a="" set,="" you="" can="" check="" if="" (my_set.find("target="" object")="" !="my_set.end())" and="" to="" check="" if="" an="" object="" is="" not="" in="" a="" set,="" you="" check="" if="" (my_set.find("target="" object")="=" my_set.end())="" or="" anything="" equivalent="" to="" this.="" important="" •="" the="" name="" of="" the="" class="" must="" be="" spellcheck="" (case="" sensitive).="" the="" member="" functions="" must="" be="" named="" exactly="" as="" given="" above.="" •="" define="" the="" class="" in="" a="" file="" named="" spellcheck.h="" and="" implement="" its="" member="" functions="" in="" a="" file="" named="" spellcheck.cpp.="" these="" names="" are="" case="" sensitive.="" •="" please="" begin="" by="" writing="" spellcheck.h="" and="" verifying="" its="" correctness="" with="" the="" instructor.="" then="" start="" implementing="" the="" functions="" in="" spellcheck.cpp.="" 1="" an="" iterator="" is="" a="" generalized="" pointer.="" references="" 1.="" levenshtein="" distance="" on="" wikipedia:="" https://en.wikipedia.org/wiki/levenshtein_distance="" (viewed="" on="" 2020-12-03)="" 2.="" std::set="">
Dec 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here