Write a C++ program to change the case (lower to upper and upper to lower cases) of each character of a given string
-
2021-05-13
- | MarwaMohammed
- | م189
Write a C++ program to change the case (lower to upper and upper to lower cases) of each character of a given string
Sample Output:
Original string: Python, After changing cases-> pYTHON Original string: w3resource, After changing cases-> W3RESOURCE Original string: AbcdEFH Bkiuer, After changing cases-> aBCDefh bKIUER
الأجوبة
ابحث عن مسائل برمجة سي بلس بلس | C++ programming بالانجليزي
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string change_Case(string text) {
for (int x = 0; x < text.length(); x++)
{
if (isupper(text[x]))
{
text[x] = tolower(text[x]);
}
else
{
text[x] = toupper(text[x]);
}
}
return text;
}
int main() {
cout << "Original string: Python, After changing cases-> "<< change_Case("Python") << endl;
cout << "Original string: w3resource, After changing cases-> "<< change_Case("w3resource") << endl;
cout << "Original string: AbcdEFH Bkiuer, After changing cases-> "<< change_Case(" AbcdEFH Bkiuer") << endl;
return 0;
}
-
2021-05-13
- | MarwaMohammed
- | إبلاغ عن إساءة
أسئلة مشابهة