Read a string from the user into a string named string1.

test it with the data: good morning

print the following heading and the data contained in string1:

exercise 1

good morning

exercise 1.2.2

create a new string named string2 containing the contents from string1.

append the following text to the end of string 2.

sleepy heads

(note that there is a space before sleepy.)

print the following heading and the data contained in string2:

exercise 2

good morning sleepy heads

exercise 1.2.3

create string3 with an initial value of:

bellow cello fellow hello mellow novello othello pillow rollo solo yellow

find the location of the first h in string3

print the following heading and the location found in string3:

exercise 3

20

exercise 1.2.4

create an empty string named string4.

copy string3 into string4.

using the location found in exercise 3,

change the first h into j

print the following heading and the data contained in string4:

exercise 4

bellow cello fellow jello mellow novello othello pillow rollo solo yellow

exercise 1.2.5

create a copy of string3 named string5.

use the find_last_of member function to find the position of the last l

print the following heading and the position of the last l

exercise 5

69

exercise 1.2.6

create a new string named string6 containing the contents from string3.

using the position of the last l found in exercise 5, erase all

characters from string6 following the last l

print the following heading and the data contained in string6:

exercise 6

bellow cello fellow hello mellow novello othello pillow rollo solo yell

Solved
Show answers

Ask an AI advisor a question