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

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...
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
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...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
Write a program that encrypts and decrypts the user input. Note – Your input should be...
Write a program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x) given by...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation , all numbers must be between 0 and 100) 2) find the largest number 3) Find the Smallest Number 4) Find the Sum of all numbers in the Array Display: as per the user's section (menu using switch or if else ) Largest Number Smallest Number Sum of all numbers the original Array DO NOT USE METHODS OR FUNCTIONS Submit: Source code (C++) output...
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT