Question: Help needed creating the code for these public functions to create the following output without modifying the main: SPECIFICATIONS: The Mississauga Institute of Technology (M.I.T.)








![class Command { private: char keyword [41]; char modifiers[5][21]; int wordCount, modNum;](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f12f2887538_28066f12f2817b83.jpg)


Help needed creating the code for these public functions 
to create the following output without modifying the main:

SPECIFICATIONS: The Mississauga Institute of Technology (M.I.T.) would like you to demonstrate your knowledge of C++ to help them rewrite their robotics software that was originally written in FORTRAN. They would like you to write the code for a class called "Command" which will be used to encapsulate a keyword (a string no longer than 40 characters) and a series of modifiers (an array of 5 strings, each being no longer than 20 characters). // class declaration: class Command { private: char keyword [41]; char modifiers[5][21]; int wordCount, modNum; public: int words (const char *sentence); int match(const char *str, const char *sentence, int wordNum); Command(); Command(const char *data); int modifierCount(); int validCommand (const char *phrase); void getKeyword(char *s); void getModifier(char *s, int pos); A "Command" has the following publicly accessible characteristics (member functions): int words (const char *sentence) which returns the number of words in the string "sentence". For the purpose of this assignment, a "word" is defined to be a sequence of non-null, non-whitespace characters, separated from other words by whitespace. (Recall that whitespace is any sequence of one or more spaces, tabs and newlines). For example, words ("Welcome to the in \t\t\t robotics department") returns the value 5, and words(" \t \t It ") returns 0. Command(const char *data) This function is passed a constant string "data" which contains one (1) keyword and may contain a series of up to five (5) modifiers, each separated by the ';' semi-colon character. This function initializes the object's keyword and its modifiers to the values passed. If more than 5 modifiers are given, only the first 5 are used. An example of the constant string "data" might be: "turn;left;right;east;west;back" -1 |1_| _2_1 13_1 14_1 15_1 IL-LL-T-I series of 5 modifiers (note the order). keyword Another example of "data" might be: "turn;left" L_1 11_1 I - only 1 modifier keyword NOTE: You may assume that the array "data" will ALWAYS contain a keyword, however it may contain 0, 1, 2, 3, 4, or 5 modifiers. int modifierCount() This function returns the number of modifiers that have been properly initialized in the Command object. int match(const char *str, const char *sentence, int wordNum) which returns a true value if the string "str" matches the part of the string "sentence" starting at word number "wordNum" of "sentence", and a false value otherwise. Special rules for determining a match are as follows: (1) the match is case insensitive. For example, 'A' matches both 'a' and 'A'. (2) if there are any embedded whitespace characters in "str", then those exact whitespace characters must appear in the corresponding positions of "sentence". (One implication of this is that if "str" begins with whitespace, it will not match anything). (3) the end of "str" must not fall in the middle of a word in "sentence", for it to be considered a match. (4) The word number in "wordNum" is a value starting at 1, so that 1 refers to the first word, 2 refers to the second word, and so on. If "wordNum" is less than 0 or greater than the number in "sentence", then no match will be found. turn left", 7) For example, match("left", "Proceed three units forward and returns a true value, while match("left", "Proceed three units forward and returns false. Similarly, turn left", 3) match("*r2-d2*", "Good morning \t *R2 - D2* & C3-00 ", 3) returns true, and match("*r2-d2* & C3-PO", "Good morning \t *R2-D2* & 3 - p ", 3) also returns true. However, match("robot", "Welcome to the \t\t\t robotics department", 4) returns false, since "robot" ends in the middle of the word "robotics", and match("H.A.L. 9000", "Hello H.A.L. 9000", 2) also returns false, but only because there are too many spaces between "H.A.L." and "9000" in the second parameter. Command() This function initializes the object's keyword to "go", and its modifiers to "north", "south", "east", "west", and "start" in this order respectively. int validCommand(const char *phrase) This function will determine if any keyword or keyword-modifier combination is present in the string "phrase". HINT: You can use the match() function written earlier to help complete this function. The function returns the following integer values: return combination: value: 1 Only the keyword is present in "phrase" and no modifiers follow it. NOTE: modifiers may precede the keyword, but are considered meaningless and do not impact the result. (e.g.) keyword: "turn" modifers: "left", "right", "east", "west", "back" Then a phrase of: "do not turn here", would return a value of 1. 2 - 6 The keyword AND a modifier are present in "phrase". The return value here will depend on what position in the array the modifier is located. A value of 2 will be returned when the keyword and the first (1st) modifier are present. A value of 3 is returned when the keyword is followed the second (2nd) modifer, etc. NOTE: Modifiers preceding the keyword, or following the first valid modifier are to be ignored and will not impact the result. (e.g.) A phrase of: "turn left here" | modifier (index=0, value=1) keyword (value=1) returns a value of 2 (1 + 1). (e.g.) A phrase of: "left turn to the west then right then back" I ignored I modifier ignored modifiers 1st valid modifier found (index=3, value=4) keyword (value=1) returns a value of 5 (1 + 4). No keyword is present in the string "phrase". Modifiers by themselves without a keyword are considered meaningless. NOTE: The string "phrase" can be of any size and may contain any number of words. If more than one (1) modifier follows the keyword, only the first modifier encountered is used. NOTE: You are expected to use the match() and words() functions you wrote for assignment #1. void getKeyword(char s[]) Fills "s" with the object's keyword. You may assume that the array "s" will be large enough to hold the keyword. void getModifier(char s[], int pos) Fills "s" with the object's modifier at number "pos" (where a "pos" of O is the first modifier, 1 is the second modifier, and so on). You may assume that the array "s" will be large enough to hold the modifier. If "pos" is not the number of one of the object's modifiers, then s will be filled with an empty string(""). // You must not modify this file! // 1/ // // Your solution may ONLY use functions from the following // included C and C++ library header files. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
