Question: 8. [20 marks] (Replace strings) Write the following function that replaces the occurrence of a substring old_substring with a new substring new_substring in the string
8. [20 marks] (Replace strings) Write the following function that replaces the
occurrence of a substring old_substring with a new substring
new_substring in the string s. The function returns true if string s is changed,
and otherwise, it returns false.
bool replace_strings(string& s,
const string& old_string,
const string& new_string)
Write a test program that prompts the user to enter three strings, i.e., s,
old_string, and new_string, and display the replaced string.
You can put the replace_strings function prototype, main() function, and the
implementation of replace_strings function in the single file a2q8.cpp. That
is, there will be two files need to be submitted for this program question. 1)
a2q8.cpp, 2) a script file a2q8result containing result.
Here are the sample runs:
Enter the string s: This is a string
Enter the old substring old_string: is
Enter the new substring new_string: ab
The replaced string is: Thaa aa a string
Enter the string s: This is a string
Enter the old substring old_string: it
Enter the new substring new_string: ab
No matches
write the code in c++ language please
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
