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

Write a program that uses a hash table in C++ or Java (Use the HashMap class in

ID: 3576068 • Letter: W

Question

Write a program that uses a hash table in C++ or Java (Use the HashMap class in Java and the map class in C++) to solve the following problem:

Summary: write a simple grammar checker, one that given some vocabulary words and rules, can verify whether a sentence is valid or not. Input Format: Output Format: 1. The words that are valid for each category 1. The output should be either true or false will be given, followed by a parse rule, then on a single line indicating whether the a candidate sentence. candidate sentence is valid or not. 2. Aword category will be defined by a single 2. The evaluation process should be case. letter followed by the number of elements insensitive. You may assume that words in the category. Then each word in that will be separated by a single space. category will appear on a separate line. words will consist of only letters. The last 3. The program should output the word word category will have 0 words in it. "done" when the program terminates 3. After the last word category, one grammar rule will be given followed by one candidate sentence. 4. You are guaranteed that grammar rules will consist only of letters that represent categories previously defined for that grammar. 5. Words in the candidate sentences will be separated by single spaces. 6. The program should continue evaluating problems until it encounters a problem where the first word category has 0 entries.

Explanation / Answer

include<iostream.h>
include<conio.h>
include<string.h>
include<graphics.h>
include<process.h>
include<dos.h>
int j=0,s1,s2,k,i,f;
int gdriver = EGA,gmode = DETECT;
char t[10][10] = {''},tp,al,cha={''};
void choice();
void text();
void present();
void past();
void future();
void background();
void main()
{
clrscr();
choice();
getch();
}
void background()
{
clrscr();
initgraph(&gdriver,&gmode,"");
setbkcolor(15);
}
void choice()
{
int n;
clrscr();
gotoxy(30,8);
cout<<"1:Present";
gotoxy(30,11);
cout<<"2:Past";
gotoxy(30,14);
cout<<"3:Future";
gotoxy(30,17);
cout<<"4:Exit";
n=getch();
switch(n)
{
case '1':
clrscr();
text();
present();
break;
case '2':
clrscr();
text();
past();
break;
case '3':
clrscr();
text();
future();
break;
case '4':
exit(0);
default:
cout<<"WRONG INPUT";
choice();
}
}
void present()
{
int c;
char pr[5][5]={"is","are","have","has","am"};
f=1;
for(k=0;k<5;k++)
{
c=strcmpi(t[1],pr[k]);
if(c==0)
f=0;
}
if(f==0)
cout<<" It is a Present Tense ";
else
cout<<" Wrong ";
al=getch();
if(al==' ')
choice();
}
void past()
{
char d[3]={''},d1[3]={"ed"};
char pa[10][5]={"was","went","were","had","ate","did"};
int c1,c2=1;
f=1;
for(int kl=0;kl<10;kl++)
{
if(t[1][kl]=='')
break;
}
if(t[1][kl]=='')
{
d[0]=t[1][kl-2];
d[1]=t[1][kl-1];
}
c2=strcmpi(d,d1);
if(c2==0)
cout<<" It is a past sentence ";
else
{
for(k=0;k<6;k++)
{
c1=strcmpi(t[1],pa[k]);
if(c1==0)
f=0;
}
if(f==0)
cout<<" It is a past tense ";
else
cout<<" Wrong ";
}
al=getch();
if(al==' ')
choice();
else
choice();
}
void future()
{
char fu[5][7]={"will","shall","would","should"};
int c2;
f=1;
for(k=0;k<5;k++)
{
c2=strcmpi(t[1],fu[k]);
if(c2==0)
f=0;
}
if(f==0)
cout<<" It is future Sentence ";
else
cout<<" Wrong ";
al=getch();
if(al==' ')
choice();
else
choice();
}
void text()
{
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
t[i][j]=cha;
}
}
cout<<" Enter the Text: ";
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
tp=getche();
if(tp==' ')
goto s1;
if(tp==' ')
{
goto s2;
}
t[i][j]=tp;
}
s2:
break;
s1:
}
for(int il=0;il<=i;il++)
{
cout<<t[il]<<" ";
}
}

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