Functions with Arrays

SAMPLE DIALOGUE:

Type a string: abcde ojkl
Encrypted: *bcd# +jkl

Task is to replace all letter A with *,all letter E with #, and all letter O with + by using 2 functions. Help please.
If you're familiar with how arrays/vectors work, it'll be fairly simple. Something like

1
2
3
4
5
for( vector<string>::size_type looper = 0; looper < stringName.size(); ++looper)
{
    if( stringName[looper] == 'A') { stringName[looper] == '*'; }
    else if // etc...
}


If you wanted, you could even make it one function, unless your professor explicitly stated you need two functions. In that case, just pass your string into one, get the result of that, then pass it into the next function.
uhmm we did not discussed vectors yet. can you tell me the code without vectors? thanks.
What about arrays? Have you discussed arrays yet? Some professors talk about them in a similar fashion while others teach them as separate lessons/units. If all else fails, just go with your basic string class.

http://www.cplusplus.com/reference/string/string/?kw=string

Notice how the string class (yes, from #include<string>) has a size() function. It will be similar to the example function I wrote for you in the previous post, just without the vector<string>::size_type part. Replace that with unsigned int and you'll be fine.
Topic archived. No new replies allowed.