A Spelling Checker-II NEEDS TO BE WRITTEN IN REGULAR C++ CODE!! Using spell chec
ID: 668454 • Letter: A
Question
A Spelling Checker-II
NEEDS TO BE WRITTEN IN REGULAR C++ CODE!!
Using spell checker developed in OLA2, spell check the document file “document.txt”
The documents to be spell checked are just regular text files (i.e., sequences of characters). The spelling checker reads in the file to be spell checked and extracts all of the words from the file. Each word in the file is checked against the words in the currently loaded dictionaries in order to detect misspelled words. If a word is not found in the currently loaded dictionaries, it is considered to be misspelled. Extracts the words in the file checks to see if they're in the dictionary.
How does the program find the words in the document file? Words are defined as sequences of letters that areseparated by characters that are not letters. The characters that you need to check for are numbers, white space (spaces, tabs, new lines, etc.), periods, commas, colons, semi-colons, parentheses, apostrophes, hyphens, equals, pluses, percents, slashes, quotes, asterisks, square braces, curly braces, less than, greater than, question marks, exclamation marks, ampersands, vertical bars and underscores. (a literal list of these non-letter characters/delimiters).
numbers
white space (tabs, newlines, spaces, and formfeeds)
.
,
:
;
(
)
'
-
=
+
%
/
"
*
[
]
{
}
<
>
?
!
&
|
_
Note that this list contains a hyphen AND an underscore.
input:
document.txt cp $PUB/document.txt .
output:
The output of the spelling checker is a sorted list of misspelled words (all lower case), one word per line.
Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
map<string,int> my_map;
bool check(string s){
if (my_map.find(s) == my_map.end()) return true;
return false;
}
int main(){
string ch = ".,:;()'-=+/*[]{}<>?!&|_";
ifstream infile;
infile.open("document.txt");
char c;
string temp = "";
cout << "The output of the spelling checker is a sorted list of misspelled words (all lower case), one word per line. " << endl << endl;
while (infile.get(c)){
if (ch.contains(c) == true || c-37 == 0 || c-47 == 0){
if (check(temp) == false)
cout << temp << endl;
temp = "";
}
else
temp += c;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.