Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 program
should 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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote