Problem 2: Microsoft word runs a grammar check on the words in which you write.
ID: 1938564 • Letter: P
Question
Problem 2:
Microsoft word runs a grammar check on the words in which you write. One of these grammar checks determines if you have properly capitalized the first letter of each sentence. Write a program to perform this check. If a sentence fails this check then print the sentence number that fails the check.
Make the following assumptions:
? The input shall be assumed to be one or many sentences stored into a single string using getline
? The end of a sentence shall be denoted by a period, question mark, or exclamation point
? The first letter of the paragraph will always be capitalized
? The only possible grammar error capitalization
? If a period is present, it will always denote the end of the sentence
Hint:
Use punctuation at the end of the sentence to determine the start of a new sentence. Be careful not to go outside the bounds of the string.
Explanation / Answer
grammar checker program in C
#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]<<" ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.