In C++ Determine if a word entered by the user is spelled correctly. A word is c
ID: 3575676 • Letter: I
Question
In C++ Determine if a word entered by the user is spelled correctly. A word is considered correct if it's found in dict.txt (see required output to get file).
Output:
Standard input intrest anchor fake hax wut what 36 exit Required output Enter word to spellcheck (or exit to end) Vn intrest is not spelled correctly. Enter word to spellcheck (or exit to end anchor is spelled correctly. Enter word to spellcheck (or exit to end)An fake is spelled correctly.An Enter word to spellcheck (or exit to end)An hax is not spelled correctly.An Enter word to spellcheck (or exit to end)An Wut is not spelled correctly. n Enter word to spell check (or exit to end n n What is spelled correctly. Enter word to spell check (or exit to end)Nn 36 is not spelled correctly. Anl Enter word to spellcheck (or exit to end)An Ending program ..An Files in the same directory dict txt Your Program's output Enter word to spellcheck (or exit to end)An intrest is not spelled correctly. An Enter word to spellcheck (or exit to end) Mn anchor is not spelled correctly. An Enter word to spellcheck (or exit to end)An fake is not spelled correctly. An Enter word to spell check (or exit to end)And hax is not spelled correctly. And Enter word to spellcheck (or exit to end) An Wut is not spelled correctly. An Enter word to spellcheck (or exit to end) n what is not spelled correctly. Mn Enter word to spellcheck (or exit to end)An 36 is not spelled correctly An Enter word to spell check (or exit to end n Ending program ..AnExplanation / Answer
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
using namespace std;
int k;
char output[150][150];
int factorial(int m)
{
if (m<=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 m)
{
if (start == m-1) {
//print(v,m);
sprintf(output[k++],"%s",v);
}
else
{
for (int i = start; i < m; i++) {
int tmp = v[i];
v[i] = v[start];
v[start] = tmp;
permute(v, start+1, m);
v[start] = v[i];
v[i] = tmp;
}
}
}
void dictionary(int n)
{
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 ", 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]);
}
}
k=0;
permute(word,0,n);
for (i=0; i<m; i++){
printf("%d %s ",i,output[i]);
}
dictionary(m);
system("pause");
}