69.1k views
1 vote
2. Write a program that initializes an array of characters with the phrase, "Take me to Clearwater Beach!". Using pointers, scan the array to make each character upper case. The catch: you may NOT use the isupper(), islower(), toupper(), or tolower() functions. You must calculate whether a character is upper or lower case, and use the same logic to convert to upper case where applicable

1 Answer

1 vote

Answer:

Written in C++

#include<iostream>

using namespace std;

int main() {

char myword[] = {'T','a','k','e',' ','m','e',' ','t','o',' ','C','l','e','a','r','w','a','t','e','r',' ','B','e','a','c','h','!', '\0'};

for (char *i = myword; *i != '\0'; ++i){

if( *i >= 'a' && *i <= 'z'){

*i -= 'a' - 'A';

}

}

cout<<myword;

return 0;

}

Step-by-step explanation:

This line initializes the string to a char array

char myword[] = {'T','a','k','e',' ','m','e',' ','t','o',' ','C','l','e','a','r','w','a','t','e','r',' ','B','e','a','c','h','!', '\0'};

This iterates through the char array

for (char *i = myword; *i != '\0'; ++i){

This checks for uppercase or lowercase

if( *i >= 'a' && *i <= 'z'){

This converts to lowercase

*i -= 'a' - 'A';

}

}

This prints the new string in all uppercase

cout<<myword;

User Dineshkashera
by
5.6k points