what doesnt work? plz help guys

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 2
Reputation: dummies2 is an unknown quantity at this point 
Solved Threads: 0
dummies2 dummies2 is offline Offline
Newbie Poster

what doesnt work? plz help guys

 
0
  #1
Oct 30th, 2006
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
  1. #include <iostream>
  2. using namespace std;
  3. #include <string.h>
  4. #include <string>
  5. #include <queue>
  6. typedef queue<char*> CHARQUEUE;
  7. const int MyArray = 100;
  8. void InputFunction(char []);
  9. void lex(char *);
  10. void syntax();
  11. CHARQUEUE Subject;
  12. CHARQUEUE Verb;
  13. CHARQUEUE Object;
  14. void main()
  15. {
  16. char UserInput[MyArray];
  17. cout <<"Enter the sentence"<<endl <<"(E) to exit" << endl;
  18. cin.getline(UserInput, MyArray);
  19. InputFunction(UserInput);
  20. syntax();
  21. if (!Subject.empty())
  22. {
  23. cout << Verb.front() << endl;
  24. Verb.pop();
  25. }
  26. main();
  27. }
  28. void InputFunction(char mySentence[])
  29. {
  30. char *tokenPtr, *nullPtr = NULL;
  31. tokenPtr = strtok(mySentence, " ");
  32. while (tokenPtr != NULL)
  33. {
  34. lex(tokenPtr);
  35. tokenPtr = strtok(nullPtr, " ");
  36. }
  37. }
  38.  
  39. void lex(char *str)
  40. {
  41. if ((strcmp(str, "A") ==0) || (strcmp(str, "The")==0))
  42. {
  43. Subject.push(str);
  44. }
  45. else if ((strcmp(str,"cat") == 0) || (strcmp(str,"rat")== 0) || (strcmp(str,"mat")== 0))
  46. {
  47. cout <<strcmp(str,"cat") << endl;
  48. Subject.push(str);
  49. }
  50. else if (strcmp(str, "I")==0)
  51. {
  52. Subject.push(str);
  53. Subject.push("firstperson");
  54. }
  55. else if (strcmp(str,"like")==0 || strcmp(str, "am")==0 || strcmp(str,"see")==0)
  56. {
  57. Verb.push(str);
  58. Verb.push("firstperson");
  59. }
  60. else if (strcmp(str,"likes")==0 || strcmp(str,"is")==0 || strcmp(str, "sees")==0)
  61. {
  62. Verb.push(str);
  63. Verb.push("thirdperson");
  64. }
  65. else if (strcmp(str,"a")==0 || strcmp(str, "the")==0)
  66. {
  67. Object.push(str);
  68. }
  69. else if (strcmp(str,"cat")==0 || strcmp(str,"rat")==0 || strcmp(str,"mat")==0)
  70. {
  71.  
  72. if (strcmp(Object.back(), "a")==0 || strcmp(Object.back(), "the")==0)
  73. {
  74. Object.push(str);
  75. }
  76. }
  77. else if (strcmp(str, "me")==0)
  78. {
  79. Object.push(str);
  80. }
  81. else
  82. {
  83. cout << "String is not accepted." <<endl;
  84. exit(0);
  85. }
  86. }
  87. void syntax()
  88. {
  89. if (!Subject.empty() && !Verb.empty())
  90. if(strcmp(Verb.back(),Subject.back())==0)
  91. {
  92. cout <<"String is correct" <<endl;
  93. }
  94. else
  95. cout <<"String is not accepted." <<endl;
  96. }
Last edited by dummies2; Oct 30th, 2006 at 11:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: what doesnt work? plz help guys

 
0
  #2
Oct 31st, 2006
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC