Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <iterator>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- string usrInput;
- //set up input string
- cout << "Input: ";
- cin >> usrInput;
- //initalise input stream
- stringstream currentstring(usrInput);
- int count = -1;
- string word[10];
- //repeatedly put words in arrays
- while (currentstring.good())
- {
- count = count + 1;
- currentstring >> word[count];
- }
- //defining persons,actions,position,pronoun, thing and value words.
- string per[] = { "Baxter", "Igor", "Shila", "end-of-array" };
- string act[] = { "recognise", "eat", "sees", "eat", "end-of-array" };
- string poss[] = { "left", "right", "forwards", "backwards", "end-of-array" };
- string pron[] = { "I", "you", "him","her", "end-of-array" };
- string thing[] = { "screwdriver", "diamond", "person", "end-of-array" };
- string val[] = { "cheap", "expensive","priceless", "end-of-array" };
- //person action thing
- string *perP = std::find(std::begin(per), std::end(per), word[0]);
- string *actP = std::find(std::begin(act), std::end(act), word[1]);
- string *thingP = std::find(std::begin(thing), std::end(thing), word[2]);
- //person action value thing
- string *PERavt = std::find(std::begin(per), std::end(per), word[0]);
- string *pACTvt = std::find(std::begin(act), std::end(act), word[1]);
- string *paVALt = std::find(std::begin(val), std::end(val), word[2]);
- string *pavTHING = std::find(std::begin(thing), std::end(thing), word[3]);
- //person action position
- string *PERap = std::find(std::begin(per), std::end(per), word[0]);
- string *pACTp = std::find(std::begin(act), std::end(act), word[1]);
- string *paPOSS = std::find(std::begin(poss), std::end(poss), word[2]);
- //pronoun action thing
- string *PRONat = std::find(std::begin(pron), std::end(pron), word[0]);
- string *pACTt = std::find(std::begin(act), std::end(act), word[1]);
- string *paTHING = std::find(std::begin(thing), std::end(thing), word[2]);
- //pronoun action position
- string *PRONap = std::find(std::begin(pron), std::end(pron), word[0]);
- string *prACTp = std::find(std::begin(act), std::end(act), word[1]);
- string *praPOSS = std::find(std::begin(poss), std::end(poss), word[2]);
- /*
- Nesting ifs to check for the conditions by using the pointers and the arrays above.
- */
- //person action thing if
- if (perP != std::end(per))
- {
- if (actP != std::end(act))
- {
- if (thingP != std::end(thing))
- {
- cout << "Your sentence is correct, following the rule: PERSON > ACTION > THING";
- }
- }
- }
- //person action value thing if
- else if (PERavt != std::end(per))
- {
- if (pACTvt != std::end(act)) {
- if (paVALt != std::end(val))
- {
- if (pavTHING != std::end(thing))
- {
- cout << "Your sentence is correct, following the rule: PERSON > ACTION > VALUE > THING";
- }
- }
- }
- }
- //person action position if
- else if(PERap != std::end(per))
- {
- if (pACTp != std::end(act))
- {
- if (paPOSS != std::end(poss))
- {
- cout << "Your sentence is correct, following the rule: PERSON > ACTION > POSITION";
- }
- }
- }
- //pronoun action thing if
- else if (PRONat != std::end(pron))
- {
- if (pACTt != std::end(act))
- {
- if (paTHING != std::end(thing))
- {
- cout << "Your sentence is correct, following the rule: PRONOUNS > ACTION > THING";
- }
- }
- }
- //pronoun action position if
- else if (PRONap != std::end(pron))
- {
- if (prACTp != std::end(act))
- {
- if (praPOSS != std::end(poss))
- {
- cout << "Your sentence is correct, following the rule: PRONOUNS > ACTION > POSITION";
- }
- }
- }
- else
- {
- cout << "Your sentence did not follow neither of the sentencing rules.";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment