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 an error-free Java program to do the following things. Prompt the user to input a...
Write an error-free Java program to do the following things. Prompt the user to input a set of numbers. The numbers represent hourly wages so they will be between 7.25 (peon) and 50 (big boss). The user should be able to input up to 35 numbers but if the user enters 0 then the data input ceases. All of the data that the user enters should be stored in a single array. You do not need to check the input...
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 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...
Write a Python function that will do the following:1. Ask the user to input an integer...
Write a Python function that will do the following:1. Ask the user to input an integer which will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers).2. Determine whether each element is an even number or an odd number3. Return a list of five-string elements "odd" and "even" that map the indexes of the elements of the input list,...
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...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT