Manipulation of strings

Thanks to it being the flu season, I missed my programming class today. Our teacher posted an assignment online that is due in the next 2 hours and I need help.

This is the assignment:

#include <iostream>
#include <string>
using namespace std;

// call the other 3 (or 4 if extra credit) funcs,
// so f( "CS 1505 Pierce College" ) returns
// "cs####pIERCEcOLLEGE" (full credit)
// "cs####pIERCEcOLEGE" (extra credit), or
// "cs#pIERCEcOLEGE" (extra credit)
string f(const string & s);
// e.g. removeSpaces( "The black dog" ) returns "Theblackdog"
string removeSpaces(const string & s);
// change case of letters, leave other chars unchanged
// e.g. changeCase( "Blah123" ) returns "bLAH123"
string changeCase(const string & s);
// replace digits with #'s
// e.g. redactDigits( "4 pizzas and 87 beers" )
// returns "# pizzas and ## beers"
string redactDigits(const string & s);

// extra credit
// replace consecutive occurrences of the same char
// with a single occurrence
// e.g. removeRepetitions( "Molly greeted 11112 guests" )
// returns "Moly greted 12 guests"
string removeRepetions(const string & s);


int main() {

}

I obviously don't want direct answered but I would LOVE some direction.

I understand that I need to refer to the string(whether its f, changecase, removeRepetions etc) in my main function and then I also need to do their declaration/definition after the main function. Where do I start?
1
2
3
4
5
6
7
string removeSpaces( const string & s ){
    string ret;
    for(  unsigned pos = 0;  pos < s.size();  pos++  )
        if( s[pos] != ' ' )
            ret += s[pos];
    return ret;
}



Would this work to read each unit?
1
2
3
4
5
6
7
8
9
10
11
string f(const string & s) {
	string ret1;
	for (unsigned pos = 0; pos < s.size(); pos++) {
		if (s[pos] >= 'a' || s[pos] <= 'z')
			ret1 += (s[pos] + 32);
		else if (s[pos] >= 'A' || s[pos] <= 'Z')
			ret1 += (s[pos] - 32);
		return ret1;
	}

}


Okay, I got the removeSpaces function to work but am having troubles with this one now. I can't seem to get it to read more than just 1 letter. Please someone help!
You have the return statement inside the loop so it only runs the first iteration of the loop.
Topic archived. No new replies allowed.