Guest User

Untitled

a guest
Jan 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <iterator>
  5. #include <vector>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. string usrInput;
  12. //set up input string
  13. cout << "Input: ";
  14. cin >> usrInput;
  15.  
  16.  
  17. //initalise input stream
  18. stringstream currentstring(usrInput);
  19. int count = -1;
  20. string word[10];
  21.  
  22. //repeatedly put words in arrays
  23. while (currentstring.good())
  24. {
  25. count = count + 1;
  26. currentstring >> word[count];
  27. }
  28.  
  29. //defining persons,actions,position,pronoun, thing and value words.
  30. string per[] = { "Baxter", "Igor", "Shila", "end-of-array" };
  31. string act[] = { "recognise", "eat", "sees", "eat", "end-of-array" };
  32. string poss[] = { "left", "right", "forwards", "backwards", "end-of-array" };
  33. string pron[] = { "I", "you", "him","her", "end-of-array" };
  34. string thing[] = { "screwdriver", "diamond", "person", "end-of-array" };
  35. string val[] = { "cheap", "expensive","priceless", "end-of-array" };
  36.  
  37. //person action thing
  38. string *perP = std::find(std::begin(per), std::end(per), word[0]);
  39. string *actP = std::find(std::begin(act), std::end(act), word[1]);
  40. string *thingP = std::find(std::begin(thing), std::end(thing), word[2]);
  41.  
  42. //person action value thing
  43. string *PERavt = std::find(std::begin(per), std::end(per), word[0]);
  44. string *pACTvt = std::find(std::begin(act), std::end(act), word[1]);
  45. string *paVALt = std::find(std::begin(val), std::end(val), word[2]);
  46. string *pavTHING = std::find(std::begin(thing), std::end(thing), word[3]);
  47.  
  48. //person action position
  49. string *PERap = std::find(std::begin(per), std::end(per), word[0]);
  50. string *pACTp = std::find(std::begin(act), std::end(act), word[1]);
  51. string *paPOSS = std::find(std::begin(poss), std::end(poss), word[2]);
  52.  
  53. //pronoun action thing
  54. string *PRONat = std::find(std::begin(pron), std::end(pron), word[0]);
  55. string *pACTt = std::find(std::begin(act), std::end(act), word[1]);
  56. string *paTHING = std::find(std::begin(thing), std::end(thing), word[2]);
  57.  
  58. //pronoun action position
  59. string *PRONap = std::find(std::begin(pron), std::end(pron), word[0]);
  60. string *prACTp = std::find(std::begin(act), std::end(act), word[1]);
  61. string *praPOSS = std::find(std::begin(poss), std::end(poss), word[2]);
  62.  
  63. /*
  64. Nesting ifs to check for the conditions by using the pointers and the arrays above.
  65. */
  66. //person action thing if
  67. if (perP != std::end(per))
  68. {
  69. if (actP != std::end(act))
  70. {
  71. if (thingP != std::end(thing))
  72. {
  73. cout << "Your sentence is correct, following the rule: PERSON > ACTION > THING";
  74. }
  75. }
  76. }
  77. //person action value thing if
  78. else if (PERavt != std::end(per))
  79. {
  80. if (pACTvt != std::end(act)) {
  81. if (paVALt != std::end(val))
  82. {
  83. if (pavTHING != std::end(thing))
  84. {
  85. cout << "Your sentence is correct, following the rule: PERSON > ACTION > VALUE > THING";
  86. }
  87. }
  88. }
  89. }
  90. //person action position if
  91. else if(PERap != std::end(per))
  92. {
  93. if (pACTp != std::end(act))
  94. {
  95. if (paPOSS != std::end(poss))
  96. {
  97. cout << "Your sentence is correct, following the rule: PERSON > ACTION > POSITION";
  98. }
  99. }
  100. }
  101. //pronoun action thing if
  102. else if (PRONat != std::end(pron))
  103. {
  104. if (pACTt != std::end(act))
  105. {
  106. if (paTHING != std::end(thing))
  107. {
  108. cout << "Your sentence is correct, following the rule: PRONOUNS > ACTION > THING";
  109. }
  110. }
  111. }
  112. //pronoun action position if
  113. else if (PRONap != std::end(pron))
  114. {
  115. if (prACTp != std::end(act))
  116. {
  117. if (praPOSS != std::end(poss))
  118. {
  119. cout << "Your sentence is correct, following the rule: PRONOUNS > ACTION > POSITION";
  120. }
  121. }
  122. }
  123. else
  124. {
  125. cout << "Your sentence did not follow neither of the sentencing rules.";
  126. }
  127. return 0;
  128. }
Add Comment
Please, Sign In to add comment