Write Menu Driven C++ Program to Convert String Cases
// Menu Driven CPP Program to Convert String Cases #include <iostream> using namespace std; int main() { char S[] = "Hello and Welcome to CodeCrucks", c; int n; do { cout << "\n\n1.Convert String to Upper Case"; cout << "\n2.Convert String to Lower Case"; cout << "\n3.Convert String to Toggle Case"; cout << "\n0.Exit"; cout << "\n\nEnter Your Choice :--> "; cin >> n; cout << "\nOriginal String :--> " << S; if(n == 1) { printf("\nUpper Case :--> "); int i = 0; while(S[i] != '\0') //TO CONVERT INTO THE UPPER CASE { if(S[i] >= 'a' && S[i] <= 'z') { c = S[i] - 32; cout << c; } else cout << S[i]; i++; } } else if(n == 2) { cout << "\nLower Case :--> "; int i = 0; while(S[i] != '\0') //TO CONVERT INTO THE LOWER CASE { if(S[i] >= 'A' && S[i] <= 'Z') { c = S[i] + 32; cout << c; } else cout << S[i]; i++; } } else if(n == 3) { cout << "\nToggle Case :--> "; int i = 0; while(S[i] != '\0') { if(S[i] >= 'a' && S[i] <= 'z') { c = S[i] - 32; cout << c; } else if (S[i] >= 'A' && S[i] <= 'Z') { c = S[i] + 32; cout << c; } else cout << S[i]; i++; } } else { if(n==0) { break; } cout << "\nPlease Enter a valid option\n"; } } while(n!=0); { cout << "Thank you very much.."; } return 0; }
Output:
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 1
Original String :--> Hello and Welcome to CodeCrucks
Upper Case :--> HELLO AND WELCOME TO CODECRUCKS
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 2
Original String :--> Hello and Welcome to CodeCrucks
Lower Case :--> hello and welcome to codecrucks
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 3
Original String :--> Hello and Welcome to CodeCrucks
Toggle Case :--> hELLO AND wELCOME TO cODEcRUCKS
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 0