Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with

Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character.

Here is an example input:

I am an input string a b 

The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and b is the character that will replace a in the final output.

The output of the program for the above example is

No space output: Iamaninputstring Searching for a Found a at index 2 Found a at index 5 Replace finished, resulting string: I bm bn input string 

The first step is to make a new string, then use this string to store the input string, but without spaces Then print this string in the format:

No space output: [no space string here] 

Secondly, print "Searching for [char]" where [char] is the character that needs to be located within the input string. Then, using the original input string with spaces, for each match, output "Found [char] at index [index]" where [index] is the index that the character has been found at within the input string. Then replace that character within the string (b in the above example input). After all the replacements are finished, output

Replace finished, resulting string: [modified string here] 

However, if no matches are found, instead of outputting the replaced results, output:

[char] was not found 

Here is an example input and output with no matches input:

I am an input string z b 

output

No space output: Iamaninputstring Searching for z z was not found

#include #include

using namespace std;

int main() { string str; string str_no_space = ""; char to_find; char to_replace;

return 0; }

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

Step: 3

blur-text-image

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 Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

Conduct an effective performance feedback session. page 360

Answered: 1 week ago