Question

create a C++ implementation of a speller application called my dictionary which can help a user...

create a C++ implementation of a speller application called my dictionary which can help a user look up English words in a dictionary. We need to create the program using lists and arrays. The program should take in its command line the name of the dictionary to be used as a parameter. Then the user should enquire about specific words. your program should provide three functionalities:

-tell whether a user provided word is included in the dictionary used

-list all the words of the dictionary that commence with a user provided prefix.

-list all the words of the dictionary that match the input up to one character

we need to read the strings from the while and add them to a vector though a for loop.

then we can use binary search because the data is already sorted.

your program should determine the precise number of words in the dictionary at run-time

Overall, the program should check from complete words, prefixes and words that match the input up to one character

when searching for the full word, the program should specify if the word was found and the number of word comparisons your program performed.

The prefix search is enabled through the wildcard *, for example, search for explo*, the dictionary should give us:

-the number of words in the dictionary that match the non-empty prefix, a list of these words, length is specified in the command line of mydictionary. the number of comparisons it took to reach the first match found in the dictionary.

-the third type of input is a word with exactly one character, at position 2 or later replaced by the wildcard ?. ex search for explo?e, the outcome could be:

explode

explore

your search should clearly avoid searching the entire dictionary for each query. you should try to come up with a better solution than storing the words in a linked list.

your application should be invoked as follows:

my machine-prompt>> ./mydictionary -d <dictionaryfile> -l <numofwordsinoutput> where the flag -d indicates that the lexeme that follows is the file name of the dictionary to be used and the -l flag indicates that the number that follows is the maximum number of results to be printed on the output.

once the program starts, it presents the user with a prompt. Every time the user types in a query, your program generates and prints out the results and give the prompt again to indicate that it expects the next query. your program should terminate once the user types exits.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Spell Checker.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <stdio.h>

#include <string>

#include <stdlib.h>

#include <fstream>

#include <iostream>

using namespace std;

#pragma warning(disable : 4996)

int k;

char output[100][100];

//char **output;

int factorial(int n)

{

if (n<=1){

return 1;

}

else

return n*factorial(n-1);

}

/*

void print(char *v, const int n){

//sprintf(output[k++],"%s",v);

//strcpy(output[k],v);

//k++;

}

*/

void permute(char *v, const int start, const int n)

{  

if (start == n-1) {

//print(v,n);

sprintf(output[k++],"%s",v);

  

}

else {

for (int i = start; i < n; i++) {

int tmp = v[i];

  

v[i] = v[start];

v[start] = tmp;

permute(v, start+1, n);

v[start] = v[i];

v[i] = tmp;

}

}

}

void dictionary(int m)

{

ifstream infile("dictionary.txt");

string *list= new string[267751];

//char list[267751][5];

//string list[267751];

if (infile.is_open()){

for (int i=0; i <267751; i++)

{

//infile>>list[i];

getline(infile, list[i]);

//cout<<list[i]<<endl;

}

}

infile.close();

for (int i=0; i<267751; i++)

{

for (int j=0; j<m; j++)

{

if(output[j]==list[i])

{

printf("Spelling suggestions: %s \n", list[i]);

}

}

}

}

int main()

{

//read in word

char word[100];

printf ("Enter a word: ");

scanf("%s",word);

int n=strlen(word);

int i,m=factorial(n);

for(int j=0; j<n; j++)

{

word[j]=toupper(word[j]);

}

//generate permutations of the word

//char** output=(char**)malloc(m*sizeof(char*));

//for (i=0; i<m; i++){

//output[i]=(char*)malloc((n+2)*sizeof(char));

//}

k=0;

permute(word,0,n);

for (i=0; i<m; i++){

printf("%d %s\n",i,output[i]);

}

//for each word in the permutation list, search it in the dictionary. if match, store in an output array

dictionary(m);

//give names for output

system("pause");

}

spell checker.cpp

#ifndef spellerShortH
#define spellerShortH
#include <iostream>
#include "QuadraticProbing.h"

class Speller
{
public:
Speller(char *dictionary[], int dictSize);
void check(char *document[], int docSize, int misspelled[], int *misspelledCount){}

private:
QuadraticHashTable <char*> *hashTable;
}; // class Speller
#endif

--------------------------

spell checker.h

#include "speller.h"

Speller::Speller(char *dictionary[], int dictSize)
{
hashTable = (QuadraticHashTable<char *> *) new2(QuadraticHashTable<char *> ('-1', dictSize*2);
for (int i=0; i<dictSize; i++)
hashTable.insert(dictionary[i]);
}

void Speller:: check (char *document[], int docSize, int misspelled[], int *misspelledCount )
{
for(int i=0; i<docSize; i++)
{
bool check;
check= (hashTable[i]==document[i])
if(check==FALSE)
{
misspelledCount++;
misspelled[misspelledCount]=hashTable[i];
}


}

Add a comment
Know the answer?
Add Answer to:
create a C++ implementation of a speller application called my dictionary which can help a user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT