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 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...
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 C++ program that does the following: Read and input file containing the following PersonAName,...
Write a C++ program that does the following: Read and input file containing the following PersonAName, PersonBName, XA,YA, XB, YB where the coordinates of PersonA in a 100 by 100 room is XA, YA and the coordinates of PersonB is XB, YB. Use square root function in cmath sqrt() to calculate the shortest distance between two points. A file will be uploaded in this assignment that will list coordinates of two people. The program should use a function call that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT