Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

After completing this assignment, you will have demonstrated the ability to: 1. Edit, compile, and run C++ programs. 2. Declare , create , initialize, assign

After completing this assignment, you will have demonstrated the ability to: 1. Edit, compile, and run C++ programs. 2. Declare, create, initialize, assign values to, and pass class objects to functions. 3. Declare and use .h and .cpp files to declare and define classes. 4. Use constructors, destructors to properly initialize and perform cleanup routines on class objects in memory. 5. Use C++ streams (cout) to perform basic output in C++ using the ostream cout. Include comments at the beginning of the program as shown below: /* program: assignment1.cpp section: prg355 a/b/c (your lab section) author: first and last name student #: 123456789 date: date submitted purpose: solution to prg355 assignment #1 */ The Mississauga Institute of Technology (M.I.T.) would like you to demonstrate your knowledge of C++ to help them rewrite the robotics software that was originally written in FORTRAN. They would like you to write the code for a class named "Command" that 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). A "Command" object has the following public features 

void init(const char data[ ]) This function is passed a 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 "data" string might be: "turn;left;right;east;west;back" |__| |1_| |_2_| |3_| |4_| |5_| | |_ _ _|_ _ |_ _ | _ _|_ _ series of 5 modifiers (note the order). | keyword Another example of the "data" string is: "turn;left" |__| |1_| | |_ _ 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, 5, or MORE modifiers. void init( ) This function initializes the object's keyword to "go", and its modifiers to "north", "south", "east", "west", and "start" in this order respectively. int modifierCount( ) This function returns the number of modifiers contained in the command. int validCommand(const char phrase[ ]) This function will determine if any keyword or keyword-modifier combination is present in the string "phrase". 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 go back" |__| |__| |__| |_ _| |__| ignored _ _ _| | | |_ __ _ _ _ _ _ _| modifier | | | | | ignored | | modifiers | | | |_ _ 1st valid modifier found | (index=3, value=4) | keyword (value=1) returns a value of 5 (1 + 4). 0 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 to be used. 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 0 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 (""). Constructors Your program MUST also include 2 constructors (a default constructor and a constructor that acepts a constant string) which each call the init functions accordingly. A main program, a1main.cpp, will be released shortly before the due date. It will assume that your "command" class is declared in a file named "command.h", and should be compiled and linked with the code for the "command" class (which presumably will be in "command.cpp"), and will test your class to see if it works properly. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions