Question: Note: Please do this in one single program! Design and implement a C/C++ Program that reads a string (expected to have multiple tokens) from the

Note: Please do this in one single program!

Design and implement a C/C++ Program that reads a string (expected to have multiple tokens) from the user and does the following:

First: splits the line into tokens based on spaces and (or escape sequences) and stores the tokens in a string vector(myStringTokens) such that each token is stored in a different element. See the examples below:

Command prompt> We call this * a star

myStringTokens

We

Call

this

*

a

star

Command prompt> history | grep report > out.txt

myStringTokens

history

|

grep

report

>

out.txt

Second: copy the tokens from the vector into a C_String array. (Do some research and ask me if you need assistance). The c-string array must be terminated by NULL. That is, after copying the tokens to the c_string array, make sure that the last element in the c_array contains NULL.

Ex:

char* cmd1[Length+1]; // c_string array declaration

cmd1[length]=NULL;

We

Call

this

*

a

star

NULL

Tips: You need to make sure that the string variables are converted to a c_string when copying them to the c_string array. Read about the method c_str() that is part of the class string in C++ used to converts a CPP string to a c-style string (null-terminated). You also need to read about the explicit char* casting.

Example:

C_stringVariable= (char*) cppStr.c_str(); // string to c_string

Third: implement a boolean function that takes a string variable and your string vector (or another string variable) as arguments and returns true if the string n the first parameter is found in the vector (or the second string variable). The function returns false otherwise.

Note: the function needs to be overloaded (read about that) so that the caller can send one of the following forms:

foo(String, string)

foo(String, string vector)

Design and implement a C/C++ Program that reads a string (expected to have multiple tokens) from the user and does the following:

First: splits the line into tokens based on spaces and (or escape sequences) and stores the tokens in a string vector(myStringTokens) such that each token is stored in a different element. See the examples below:

Command prompt> We call this * a star

myStringTokens

We

Call

this

*

a

star

Command prompt> history | grep report > out.txt

myStringTokens

history

|

grep

report

>

out.txt

Second: copy the tokens from the vector into a C_String array. (Do some research and ask me if you need assistance). The c-string array must be terminated by NULL. That is, after copying the tokens to the c_string array, make sure that the last element in the c_array contains NULL.

Ex:

char* cmd1[Length+1]; // c_string array declaration

cmd1[length]=NULL;

We

Call

this

*

a

star

NULL

Tips: You need to make sure that the string variables are converted to a c_string when copying them to the c_string array. Read about the method c_str() that is part of the class string in C++ used to converts a CPP string to a c-style string (null-terminated). You also need to read about the explicit char* casting.

Example:

C_stringVariable= (char*) cppStr.c_str(); // string to c_string

Third: implement a boolean function that takes a string variable and your string vector (or another string variable) as arguments and returns true if the string n the first parameter is found in the vector (or the second string variable). The function returns false otherwise.

Note: the function needs to be overloaded (read about that) so that the caller can send one of the following forms:

foo(String, string)

foo(String, string vector)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!