Question

In: Computer Science

Takes a string and removes all spaces and special characters, and converts // to upper case,...

Takes a string and removes all spaces and special characters, and converts
// to upper case, returning the result
// Pre: inString contains a string
// Post: Returns a string with all spaces and special characters removed and
// converted to upper case

in c++ please

Solutions

Expert Solution

#include <iostream>
#include <iomanip>
using namespace std;
string convertString(string s){
string t = "";
for(int i=0; i<s.length(); i++){
if(s[i] >= 'a' && s[i]<= 'z'){
t = t + (char)(s[i]-32);
}
else if(s[i] >= 'A' && s[i]<= 'Z'){
t = t + s[i];
}
else if(s[i] >= '0' && s[i]<= '9'){
t = t + s[i];
}
}
return t;
}

int main()
{
  
string s;
cout<<"Enter the string: ";
getline(cin , s);
cout<<"New string is: "<<convertString(s)<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the string: suresh murApaka cse12!@ hi how Are y123                                                                                                                                                                                                              

New string is: SURESHMURAPAKACSE12HIHOWAREY123


Related Solutions

Write a program that takes a string from the user, identifies and counts all unique characters...
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions. For character identification Develop a program that takes a string argument, and returns an array containing all unique characters. For character counting Develop a program that takes an array returned from above function as an...
Write a program that takes a string from the user, identifies and counts all unique characters...
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions. For character identification Develop a program that takes a string argument, and returns an array containing all unique characters. For character counting Develop a program that takes an array returned from above function as an...
Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
Java- creat a method that takes two char parameters. Return a String containing all characters, in...
Java- creat a method that takes two char parameters. Return a String containing all characters, in order, from the first char parameter (inclusive) to the last (inclusive). For instance, input('a', 'e'), and return "abcde".
/**    * Returns the string formed by alternating the case of the characters in   ...
/**    * Returns the string formed by alternating the case of the characters in    * the specified string. The first character in the returned string is in    * lowercase, the second character is in uppercase, the third character is    * in lowercase, the fourth character is in uppercase, and so on.    * Examples:    *    * <ul>    * <li><code>alternatingCaps("a")</code> returns <code>"a"</code>    * <li><code>alternatingCaps("ab")</code> returns <code>"aB"</code>    * <li><code>alternatingCaps("abc")</code> returns <code>"aBc"</code>    *...
This function takes in a string as a parameter and prints the average number of characters...
This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per word for each sentence with 1 decimal precision (see test cases below). Assume a sentence always ends with a period (.) or when the string ends. Assume there is always a blank space character (" ") between each word. Do not count the blank spaces between words or the periods...
Write a C function str_to_float() that takes a numeric string as input and converts it to...
Write a C function str_to_float() that takes a numeric string as input and converts it to a floating point number. The function should return the floating point number by reference. If the conversion is successful, the function should return 0, and -1 otherwise (e.g. the string does not contain a valid number). The prototype of the function is given below int str_to_float(char * str, float * number);
In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
If a clothing store customer takes a pair of pants from the rack, removes all of...
If a clothing store customer takes a pair of pants from the rack, removes all of the external sales tags, and then approaches the sales clerk for a refund, what crime may be charged? Theft Criminal mischief Embezzlement None of the above
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT