Question

In: Computer Science

Write a program that will read user input, and do the following: 1. The user can...

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

Solutions

Expert Solution


#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;
}


Related Solutions

2. Write a program to do the following: • ask the user to input the size...
2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array
Write a program that read the input from user and convert it to binary and hex...
Write a program that read the input from user and convert it to binary and hex in C language.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
Write an assembly language program to input a string from the user. Your program should do...
Write an assembly language program to input a string from the user. Your program should do these two things: ***** I AM POSTING THIS QUESTION FOR THE THIRD TIME NOW,I WANT IT DONE USING INCLUDE IRVINE32.INC***** 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be:...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT