0

i have this program but it doenst work could you help me plz.
you just enter in sentence like: I like the cat. or The cat sees the rat. The cat likes me. then it will say the string is correct. but if you enter in I sees the cat. The cat like me. then it will say that the string is wrong. plz help me. ty
I'm using c++ 2005

#include <iostream>
 using namespace std;
#include <string.h>
#include <string>
#include <queue>
typedef queue<char*> CHARQUEUE;   
const int MyArray = 100;  
void InputFunction(char []); 
void lex(char *);      
void syntax();         
CHARQUEUE Subject; 
CHARQUEUE Verb;    
CHARQUEUE Object;  
void main()   
{
  char UserInput[MyArray];
  cout <<"Enter the sentence"<<endl <<"(E) to exit" << endl;
  cin.getline(UserInput, MyArray); 
  InputFunction(UserInput);  
  syntax();
  if (!Subject.empty())
  {
  cout << Verb.front() << endl;
  Verb.pop();
  }
  main();
}
void InputFunction(char mySentence[]) 
{
 char *tokenPtr, *nullPtr = NULL;
 tokenPtr = strtok(mySentence, " ");
 while (tokenPtr != NULL)
 {   
        lex(tokenPtr);    
  tokenPtr = strtok(nullPtr, " ");
 }
}  
 
void lex(char *str)
{
   if ((strcmp(str, "A") ==0)  || (strcmp(str, "The")==0))
   {
    Subject.push(str);
   }
   else if ((strcmp(str,"cat") == 0) || (strcmp(str,"rat")== 0) || (strcmp(str,"mat")== 0))
   { 
      cout <<strcmp(str,"cat") << endl;
      Subject.push(str); 
   }
   else if (strcmp(str, "I")==0)
   {
      Subject.push(str);
      Subject.push("firstperson");
   }      
   else if (strcmp(str,"like")==0 || strcmp(str, "am")==0 || strcmp(str,"see")==0)
   {
      Verb.push(str);
      Verb.push("firstperson");
   }
   else if (strcmp(str,"likes")==0 || strcmp(str,"is")==0 || strcmp(str, "sees")==0)
   {
   Verb.push(str);
   Verb.push("thirdperson");
   }      
   else if (strcmp(str,"a")==0 || strcmp(str, "the")==0)
   {
      Object.push(str);
   }
   else if (strcmp(str,"cat")==0 || strcmp(str,"rat")==0 || strcmp(str,"mat")==0)
   {
 
    if (strcmp(Object.back(), "a")==0 || strcmp(Object.back(), "the")==0)
   {
       Object.push(str);  
   }
   }
   else if (strcmp(str, "me")==0)
   {
      Object.push(str);
   }
   else 
   {
      cout << "String is not accepted." <<endl;
   exit(0);
   }
 }
void syntax()
{
 if (!Subject.empty() && !Verb.empty())
 if(strcmp(Verb.back(),Subject.back())==0)
 {
  cout <<"String is correct" <<endl;
 }
 else 
  cout <<"String is not accepted." <<endl;
}
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by ~s.o.s~
0

When you say, it doest work, it is very vague. Sifting through someone else's code is really difficult. Since your program is written in modular way, say which parts work properly and which dont.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.