characterCases.cpp
{EAV_BLOG_VER:a6b6a0065a96b431}
The Problem
Think CS C++
7.14
As an exercise, character classification and conversion library to write functions named
apstringToUpperandapstringToLowerthat take a single apstring as a parameter, and that modify the string by converting all the letters to upper or lower case. The return type should bevoid.
The Code
/* For my benefit, given that my compiler does not have apstring.cpp,
I will be using an array of characters. */
#include <iostream>
#include <ctype.h>
using namespace std;
int index;
void stringToUpper(string s){
index = 0;
while (index <= s.length()){
if (isalpha(s[index])){
char l = toupper(s[index]);
cout<<l;
//cout<<toupper(s[index]);
}
else {
cout<<s[index];
}
index++;
}
cout<<"\n";
}
void stringToLower(string s){
index = 0;
while (index <= s.length()){
if (isalpha(s[index])){
char l = tolower(s[index]);
cout<<l;
//cout<<tolower(s[index]);
}
else {
cout<<s[index];
}
index++;
}
cout<<"\n";
}
int main()
{
// Test cases
string string1 = "somewhere";
string string2 = "SOMETIME";
string string3 = "someHOW386";
stringToUpper(string1);
stringToUpper(string2);
stringToUpper(string3);
stringToLower(string1);
stringToLower(string2);
stringToLower(string3);
return 0;
}
/* OK, I used string. When I tried using arrays, the compiler gives
me an error which I do not yet understand. */


SocialVibe