Question

In: Computer Science

Function 6: Sorting string function name (str) a. This function receives an string. Your task is...

Function 6: Sorting string function name (str) a. This function receives an string. Your task is loop through the each character of the string and separate all digists/letters/special characters. Display all digits at the beginning, followed by letters then the special chars and display result in console. For example if following string is passed to this function “ha1m2i3:n)” Result should be: 123hamin:)

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================


#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

void sortingString(string s);
int main() {
   //Declaring variables
   string s="ha1m2i3:n)";
sortingString(s);
   return 0;
}
void sortingString(string s)
{
   string letters="",digits="",special="";
   string sortString="";
   char ch;
   for(int i=0;i<s.length();i++)
   {
       ch=s.at(i);
       if(isalpha(ch))
       {
           letters+=ch;
       }
       else if(isdigit(ch))
       {
           digits+=ch;
       }
       else
       {
           special+=ch;
       }
   }
   sortString+=digits;
   sortString+=letters;
   sortString+=special;
  
   cout<<sortString<<endl;
}

========================================

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

using java language only write a code Have the function StringChallenge(str) take the str string parameter...
using java language only write a code Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 ------- you have the following code edit it to get the result mport java.util.*; import java.io.*; class Main {   public static String StringChallenge(String str)...
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Creates a function called pick. The function receives a "string" representing one year (the variable with...
Creates a function called pick. The function receives a "string" representing one year (the variable with this "string" will be called uve) and a list containing "strings" representing bank accounts (call this bera list). <br> • Each account is represented by 8 characters. The format of each account number is "**-**-**", where asterisks are replaced by numeric characters. o For example, "59-04-23". • The two central characters of the "string" for each account represent the year the account was created....
Write a function that receives a StaticArray and sorts its content in non-descending order. Sorting must...
Write a function that receives a StaticArray and sorts its content in non-descending order. Sorting must be done ‘in place’, meaning the original input array will be modified. You may assume that the input array will contain at least one element and that values stored in the array are all of the same type (either all numbers, or strings, or custom objects, but never a mix of those). You do not need to write checks for these conditions. You can...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person’s contact information. If the person is not found, the function returns, “name not in contact”. Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples:               contacts = “Frank...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person’s contact information. If the person is not found, the function returns, “name not in contact”. Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples:               contacts = “Frank...
Python. Create a function that receives the name of an auto maker and returns a slice...
Python. Create a function that receives the name of an auto maker and returns a slice of the dataframe with the cars from that auto maker. For instance, it may receive 'ford' and return a slice with all the cars produced by 'ford' meaning they have 'ford' in their name. Call the function for 'ford' to see if it works properly. Hint: You may create a list comprehension producing a list of all the index labels that include the auto-maker's...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks...
Python 3.7.4 Costume = {'label': str, 'price': int, 'sizes': [str]} ''' C5. Define a function `most_expensive_costume`...
Python 3.7.4 Costume = {'label': str, 'price': int, 'sizes': [str]} ''' C5. Define a function `most_expensive_costume` that consumes a list of costumes and produces a string representing the label of the costume with the highest price. In the event of a tie, give the label of the item later in the list. If there are no costumes, return the special value None. ''' ''' C6. Define a function `find_last_medium` that consumes a list of costumes and produces the label of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT