He's cheating. He's also just playing with semantics. Rather than getting an entire string at a time, he's just getting one character at a time.
Whether or not the characters are stored in an array doesn't mean he's not doing string operations.
For example, for the Caesar cipher, he:
1. gets a character from the user
2. if it is a newline, exit the loop
3. caesar-shift the character and print it out
4. loop (goto 1)
That is exactly the same process used on an array of characters (a "string"). The only difference is where the characters come from and go to. It is still a string operation.
Here is the
caesarShift() function:
1 2 3 4 5 6 7 8 9 10 11
|
char caesarShift( signed char shift, char c )
{
if (isalpha( c )) // only shift alphabetic characters
{
c += shift;
if (!isalpha( c )) // The result must be a letter, so wrap around if needed
c -= 26; // (for example 'Z'+3 --> 'C'; 'Y'+3 --> 'B'; etc)
}
else // everything else remains unchanged
return c;
}
|
You can do the same sort of thing for
flipCase(). Go ahead and write your own version of the function.
Now for the tricky one:
reverseLine(). He has used a little misdirection on you by giving it an argument and a result. Both are strictly
not necessary, but you can do it that way anyway.
The function should be recursive. Think about it a bit and try to write your own. You might find it helpful to first write a reverse function with the following prototype:
void reverseLine();
and in the
main() function, change the line
cout.put(reverseLine(getc(stdin)));
to
reverseLine();
Once you have that working, kick it up a notch and rewrite it using the following prototype:
char reverseLine( char c );
Hint: the function is recursive, and it should return its argument unchanged.
I don't think it will cause you a problem, but if it does you'll want to change that line I indicated in
main() to read:
cout.put(reverseLine(cin.get()));
Have fun!