Write a program that lets the user enter a string into a character array. The pr
ID: 3635813 • Letter: W
Question
Write a program that lets the user enter a string into a character array. The programshould then convert all the lowercase letters to uppercase. (If a character is already
uppercase, or is not a letter, it should be left alone.) Hint: Consult the ASCII chart in
Appendix A. Notice that the lowercase letters are represented by the ASCII codes 97
through 122. If you subtract 32 from any lowercase character’s ASCII code, it will
yield the ASCII code of the uppercase equivalent. we can't use the toupper or other library functions
Explanation / Answer
Here, compiled via VS 2010. The idea that we simply changing decreasing our character by 32 if it's from a to z, as every lowecase letter is +32 bigger then it's uppercase equivalent. U can see it from ASKII chart. Ask me if u have any question concerning it.
#include <iostream>
#include <string>
using namespace std;
void lowerToUpper(string str)
{
int size = str.size();
for (int i = 0; i < size; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] - 32;
}
cout << str;
}
int main()
{
string str;
cout << "Input string: ";
cin >> str;
lowerToUpper(str);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.