Question

Ask the user for a string with some uppercase letters and some lowercase letters. Write a...

Ask the user for a string with some uppercase letters and some lowercase letters. Write a function called ChangeCase that prints a new string in which the uppercase letters are changed to lowercase and lowercase to uppercase. in c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

void ChangeCase(string s) {
    char ch;
    for (int i = 0; i < s.size(); ++i) {
        ch = s[i];
        if (ch >= 'a' && ch <= 'z') {
            ch -= 32;
        } else if (ch >= 'A' && ch <= 'Z') {
            ch += 32;
        }
        cout << ch;
    }
    cout << endl;
}

int main() {
    string s;
    cout << "Enter a string:" << endl;
    getline(cin, s);
    ChangeCase(s);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Ask the user for a string with some uppercase letters and some lowercase letters. Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT