C++ - Write a program that initializes an array of characters with the phrase, “
ID: 3891331 • Letter: C
Question
C++ - 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.
Hints:
*cptr >= ‘a’ && *cptr <= ‘z’
Assuming the ASCII value for ‘a’ is greater than ‘A’, how could you use an expression like, (‘a’ – ‘A’) to convert to upper case?
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
char a[]="Take me to Clearwater Beach!";
int i=0;
while (*(a+i)!='')
{
if (*(a+i)>='a' && *(a+i)<='z')
*(a+i)=*(a+i)-32;
i++;
}
i=0;
while (*(a+i)!='')
{
cout<<*(a+i)<<" ";
i++;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.