Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Process a string variable, character by character. If the arg string named s,

ID: 3557517 • Letter: 3

Question

3.         Process a string variable, character by character. If the arg string named s, you may need a loop something like

            for( unsigned pos = 0; pos < s.size(); pos++ ){

                        ... fiddle around with s[pos], the current char of s ...

            }

A.         void stringA( const string & s );

Output the chars of s, one per line.

For example, if main says

            stringA( "Blah" );

then stringA will output

            B

            l

            a

            h

B.         bool stringB( char c, const string & s )

Returns whether the character c occurs in the string s.

For example,

            stringB( 'a', "Beeblebrox" )

returns false.

For another example,

            stringB( 'e', "Exceeded" )

returns true.

C.         unsigned stringC( char c, const string & s )

Similar to B, but now we're returning how many times the char c occurs in s.

For example,

            stringC( 'e', "Exceeded" )

returns 3, while

            stringC( 'a', "Beeblebrox" )

returns 0 (without complaint or death).

D.         bool stringD( const string & s )

Returns whether s contains any non-digit characters.

For example,

            stringD( "1234" )

returns false, while

            stringD( "12.34" )

return true;

E.         unsigned stringE( const string & s )

First, stringE calls stringD to figure out whether s has any non-digits; if it does, then stringE complains and dies.

Then, stringE figures out and returns the value of the number represented by s.

For example,

            stringE( "1234" )

returns the number 1234.

For another example,

            stringE( "12,34" )

complains and dies.

F.         string stringF( const string & s );

stringF returns the result of transforming the chars of s according the secret code:

non-letters of s are unchanged

lower-case letters of s are replaced with the next lower case letter, with 'z' replaced by 'a'.

upper-case letters of s are replaced with the previous upper-case letter, with 'A' replaced by 'Z'.

For example,

            stringF( "I have 17 cats!" )

returns the string

            "J gzud 17 bzsr!"

Explanation / Answer

//test file #include #include #include "iofunc.h" using namespace std; int main(){ string str1 = "joe bloggs joeblog@live.com 12345"; iofunc func; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote