hello again..

H

hkhellhkhell

hello again..
i want to design a program which takes in a string and replaces all 's'
characters with 'sh'. how do i do it? thanks a lot!
 
D

Daniel T.

hello again..
i want to design a program which takes in a string and replaces all 's'
characters with 'sh'. how do i do it? thanks a lot!

#include <cassert>
#include <string>

void replace( string& line, const string& from, const string& to )
{
// insert code here.
}

int main()
{
string myString = "s";
replace( myString, "s", "sh" );
assert( myString == "sh" );
}

Insert code at the spot that says "insert code here" until the program
exists without the assert aborting it.
 
P

Phlip

Daniel said:
#include <cassert>
#include <string>

void replace( string& line, const string& from, const string& to )
{
// insert code here.
}

int main()
{
string myString = "s";
replace( myString, "s", "sh" );
assert( myString == "sh" );
}

Insert code at the spot that says "insert code here" until the program
exists without the assert aborting it.

Then add these lines to main():

string myString = "is";
replace( myString, "s", "sh" );
assert( myString == "ish" );

And add more code, until this test passes too. Repeat until the tests cover
a sample of all permutations, such as "nada", "sis", "its", and so on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

advanced string manipulation 4
Hello Everybody 0
Hello!! 0
Hello! 2
Hello World 2
Hello from beginner with some questions! 3
Hello 0
Hello and Help please :-) 1

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top