Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that implements a simple spell checker in C++. The spell checker

ID: 3531239 • Letter: W

Question

Write a program that implements a simple spell checker in C++. The spell checker should work as follows: prompt the user to enter a file name to spell check, and then the program will parse the file and check if there are any tokens that are not in the dictionary. Any words that are not found in the dictionary will be printed on the screen. Note that you do not need to worry about sorting words or prompting the user for corrections.


I cant use any advanced functions like arrays, user functions. This is what I have so far:


#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main()

{

string filename, temp;

string dictionary = "dict.txt";

ifstream bonk, dict;

dict.open(dictionary.c_str());

if (dict.fail())

{

cerr << dictionary << " could not be opened" << endl;

exit (1);

}

cout << "Please enter the filename: ";

cin >> filename;


bonk.open(filename.c_str());

if (bonk.fail())

{

cerr << filename << " could not be opened" << endl;

exit (1);

}

system ("pause");

return 0;

}

Explanation / Answer

// here is the code please rate me first:


#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

void makeLowerCase (char word[]);
void linearSearch (char dictionary[][30], int size, char word[][30]);

int main ()
{
String filename;
char temp[300][30];
char dictionary[300][30];
ifstream dict,bonk;

fin.open ("dictionary.txt");
if (dict.fail())
{
cout << "FILE NOT FOUND ";
exit (0);
}
for (int index=0; !dict.eof(); index++) //read in dictionary file one //word by word
{ //already alphabetized.
dict.getline (dictionary[index],30);
}
dict.close ();

cout << "Enter the file name: ";
cin >> filename;
bonk.open (filename);
if (bonk.fail())
{
cout << "FILE NOT FOUND ";
exit (0);
}
for (int index2=0; !bonk.eof(); index2++) //this is the file to be spell checked
{
bonk >> temp[index2]; //WHY WILL THIS NOT READ ANYTHING IN!?!?
makeLowerCase (temp[index2]); //to get all words to lower case
}
bonk.close ();

linearSearch (dictionary, 300, temp);
//just a simple linear search for now.


return 0;
}

void makeLowerCase (char temp[])
{
int length = strlen(temp);
for (int n=0; n < length; n++)
temp[n] = tolower(temp[n]);
}

void linearSearch (char dictionary[][30], int size, char temp[][30])
{
bool found = false;

for (int scan=0; scan < size; scan++)
{
for (int n=0; n < size && !found; n++)
{
if (strcmp(dictionary[n], temp[scan]) ==0)
found = true;
}
if (!found) //this section still needs work but ok for now
cout << endl << "Misspelled word list: " << temp[scan] << endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote