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

I want a visual studio C++ programming code for the following task. Please give

ID: 3582682 • Letter: I

Question

I want a visual studio C++ programming code for the following task. Please give the working code for the complete task. I will be thankful.

You are expected to build a dictionary in a TRIE. Every TRIE node will hold pointers to some letters of the english alphabet and a flag that says whether that node stores a valid english word or not.
Your TRIE node structure should have the following members
1. An array of TRIE node pointers. In order the pointers should point to the following characters A B C I E F H O R S T only.

2. A flag that says if the node holds a valid english word

3. A char array that stores this english word.
Your dictionary should store the following words:
artist

art

artificial

effort

effect

torch

toss

test

torchere

horse

hobbit

has

bit

hot

habbit

bore

bare

bear

bar

barret

Your dictionary should support the following operations:

AddWord: This word should add a word to the TRIE. You can expect that all words added will be formed from the letters in your TRIE node list.

PrintWordSuggestions: This function should take a sub string as an argument and print a list of valid words from the dictionary that start with that substring. For Example if the user types ‘to’ the function PrintWordSuggestions when called with ‘to’ should print a list

toss

torch

torchere

Please note that the list of words are printed in order of word sizes with the smallest word first.
Your application should take input from the user in a dialogue box (which can be a simple rectangle) As the user is typing the string you should display a list of correct english word as suggestions for the same substring.
For example:


toss

torch

torchere


and later when the user adds an r to his substring the suggestion list should automatically change like such


torch

torchere.

to

Explanation / Answer

#include <stdio.h>
#include<iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include<dos.h>
#define LEFT 1
#define RIGHT 2

struct node
{
char word[20],meaning[100];
node *left,*right;
};

node *maketree(char[],char[]);

node* treefromfile();
void filefromtree(node*);
void addword(node*,char[],char[]);
void seperateword(char[],char[],char[]);
void displayall(node*);
node* bsearch(node*,char[]);
void showmenu();
FILE *file_ptr;

void prog()
{
clrscr();
char word[20],meaning[100];
int menuchoice;
node *temp;
temp=treefromfile();
if(temp==NULL)
{
printf("
File does not exist or dictionary is empty...");
getch();
}
while(1)
{
clrscr();
showmenu();
scanf("
%d",&menuchoice);
switch(menuchoice)
{
   case 1:printf("
Enter word to search : ");
      scanf("%s",word);
      printf("
Enter meaning of word : " );
      flushall();
      gets(meaning);
      if(temp==NULL)
       temp=maketree(word,meaning);
      else
       addword(temp,word,meaning);
      break;
   case 2:if(temp==NULL)
       printf("
The dictionary has no word ");
      else
      {
       printf("
Plz find meaning of : ");
       flushall();
       gets(word);
       node *t;
       t=bsearch(temp,word);
       if(t==NULL)
        printf("
Word not present in Dictionary");
       else
       {
        printf("

%s : ",t->word);
        puts(t->meaning);
       }
      }
      getch();
      break;
   case 3:if(temp==NULL)
       printf("
Dictionary is empty...");
      else
       displayall(temp);
      getch();
      break;
   case 4:filefromtree(temp);
      exit(1);
      break;
   default:cout<<"

Enter Again";
       delay(2000);
       prog();
       break;
}
}
}
void showmenu()
{
printf("
       MY VC DICTIONARY");
printf("
[1].   Add a word in Dic");
printf("
[2].   Find meaning in Dic");
printf("
[3].   Display all in Dic");
printf("
[4]. Save and Close in Dic

Enter Choice");
}
node* treefromfile()
{
node *ptree=NULL;
char word[20],meaning[100],str[120],*i;
int flags=0;
file_ptr=fopen("C:dict.anu","r");
if(file_ptr==NULL)
ptree=NULL;
else
{

while(!feof(file_ptr))
{
   i=fgets(str,120,file_ptr);
   if(i==NULL)
   break;
   seperateword(str,word,meaning);
   if(flags==0)
   {
   ptree=maketree(word,meaning);
   flags=1;
   }
   else
   addword(ptree,word,meaning);
}

fclose(file_ptr);
}
return ptree;
}
node* maketree(char w[],char m[])
{
node *p;
p=new node;
strcpy(p->word,w);
strcpy(p->meaning,m);
p->left=NULL;
p->right=NULL;
return p;
}
void seperateword(char str[],char w[],char m[])
{
int i,j;
for(i=0;str[i]!=' ';i++)
w[i]=str[i];
w[i++]=NULL;  
for(j=0;str[i]!='
';i++,j++)
{
m[j]=str[i];
}
m[j]=NULL;
}
void addword(node *tree,char word[],char meaning[])
{
node *p,*q;
p=q=tree;
while(strcmp(word,p->word)!=0 && p!=NULL)
{
q=p;
if(strcmp(word,p->word)<0)
   p=p->left;
else
   p=p->right;
}
if(strcmp(word,q->word)==0)
{
printf("
This word already exists...");
delay(1000);
}
else if(strcmp(word,q->word)<0)
q->left=maketree(word,meaning);
else
q->right=maketree(word,meaning);
}
node* bsearch(node *tree,char word[])
{
node *q;
q=tree;
while(q!=NULL)
{
if(strcmp(word,q->word)<0)
   q=q->left;
else if(strcmp(word,q->word)>0)
   q=q->right;
if(strcmp(word,q->word)==0)
   break;
}
return q;
}
void filefromtree(node *tree)
{
void travandwrite(node*);
file_ptr=fopen("C:dict.anu","w");
if(file_ptr==NULL)
{
printf("
Cannot open file for writing data...");
}
else //if(tree==NULL)
{
if(tree!=NULL)
{
   travandwrite(tree);
}
fclose(file_ptr); //Close the file
}
}
void travandwrite(node *tree)
{
if(tree!=NULL)
{
fprintf(file_ptr,"%s %s
",tree->word,tree->meaning);
travandwrite(tree->left);
travandwrite(tree->right);
}
}
void displayall(node *tree)
{
if(tree!=NULL)
{
displayall(tree->left);
printf("%s : %s
",tree->word,tree->meaning);
displayall(tree->right);
}
}

void intro()
{
int i;
clrscr();
gotoxy(20,20);
cout<<"DICTIONARY LOADING......";
for(i=0;i<50;i++)
{
gotoxy(15+i,21);
cout<<"???";
gotoxy(20,22);
cout<<2*i<<"% completed";
delay(150);
}
gotoxy(20,20);
cout<<"DICTIONARY LOADING COMPLETED.";
clrscr();
}
void main()
{
clrscr();
intro();
prog();
}

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