In: Computer Science
Write a program that will read user input, and do the
following:
1. The user can input letters [A-Z] as much as he wants (ignore
case).
2. If the user input other than letters or two characters, stop the
input process and start to print
unduplicated sorted pairs such as the below examples:
User input: A a e b d d D E a B 1
Output: AB AD AE BD BE DE
User Input: a q w e dd
Output: AE AQ AW EQ EW QW
#include<iostream>
using namespace std;
void convertOpposite(string &str)
{
int ln = str.length();
// Conversion according to ASCII values
for (int i=0; i<ln; i++)
{
if (str[i]>='a' &&
str[i]<='z')
//Convert lowercase to
uppercase
str[i] = str[i]
- 32;
else if(str[i]>='A' &&
str[i]<='Z')
str[i] = str[i]
+ 32;
}
}
// Driver function
int main()
{
string str = "A a e b d d D E a B 1";
// Calling the Function
convertOpposite(str);
cout << str;
return 0;
}
---------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
void Count(string str)
{
int upper = 0, lower = 0, number = 0, special =
0;
for (int i = 0; i < str.length(); i++)
{
if (str[i] >= 'A' &&
str[i] <= 'Z')
upper++;
else if (str[i] >= 'a'
&& str[i] <= 'z')
lower++;
else if (str[i]>= '0' &&
str[i]<= '9')
number++;
else
special++;
}
cout << "Upper case letters: " << upper
<< endl;
cout << "Lower case letters : " << lower
<< endl;
cout << "Number : " << number <<
endl;
cout << "Special characters : " << special
<< endl;
}
// Driver function
int main()
{
string str = "A a e b d d D E a B 1";
Count(str);
return 0;
}