Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program The Question is: Write one program containing all these string exercises. Exercise 1.2.1 Read a string from the user into a string named

C++ program
The Question is:
Write one program containing all these string exercises.
Exercise 1.2.1
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
The first h is at column (put the column number here)
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 a 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 y
Print the following heading and the position of the last y
Exercise 5
(put the column number of the last y here)
Exercise 1.2.6
Create a new string named string6 containing the contents from string3.
Using the position of the last y found in exercise 5, erase all
characters from string6 following the last y
Print the following heading and the data contained in string6:
Exercise 6
bellow cello fellow hello mellow Novello Othello pillow Rollo solo y
My program is:
#include
#include
using namespace std;
int main()
{
string string1, string2, string3, string4, string5, string6;
getline(cin, string1);
cout << "Exercise 1" << endl;
cout << string1 << endl;
string2 += string1;
string2 += " sleepy heads";
cout << "Exercise 2" << endl;
cout << string2 << endl;
string3 = "bellow cello fellow hello mellow Novello Othello pillow Rollo solo yellow";
cout << "Exercise 3" << endl;
cout << string3.find('h') << endl;
string4.empty();
string4 += string3;
cout << "Exercise 4" << endl;
cout << string4.replace(20, 1, "J") << endl;
string5 = string3;
cout << "Exercise 5" << endl;
cout << string5.find_last_of('y') << endl;
string6 += string3;
cout << "Exercise 6" << endl;
cout << string6.erase(68,5) << endl;
return 0;
}
My question is if I need the prompt for input , I need to add what in program, and I need to add at which line

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions