I don't know what I am doing....
Write two general functions to process strings.
The first function is named Compress. It takes two parameters. The first is the string to be compressed. The second parameter is the character that is to be removed from the string, for instance a space (but it would not need to be a space: it could be any character)
The second function is named Replace. It takes three parameters. The first is the string to be considered. The second is the character to be found in the string. The third is the character to replace the found character with.
You need to be much more specific as to what you need help with. Give a detailed explanation on what you don't understand about the assignment or what you need help doing. Just posting what your assignment says doesn't give us any idea as to where you are struggling with it.
Here is a basic framework for your assignment to work off of. Use it to get as far as you can to completing the assignment then ask for help on the specific things you don't understand.
// I went for returning a compressed string but you can also use references to alter one directly.
// I also used std::string instead of c strings but you might be required to use
// c strings so change as you need to.
std::string Compress(const std::string& stringToCompress, constchar charToRemove)
{
// First you need to create a std::string that will hold the compressed string.
std::string compressedString = stringToCompress;
// Now we need to go through compressedString and remove every
// occurance of charToRemove from it.
// You might do this by just a simple for loop that loops through each
// character of the string and test it is equal to charToRemove and then
// use std::string::erase() to remove it.
// Or if you professor allows it you can even use std::string::find_first_of()
// After you have removed everything return the compressed string.
return compressedString;
}
Your second function should be easy after you figure out the first one. All you need to do is instead of using std::string::erase() to erase the character you call std::string::replace() instead.