In: Computer Science
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:)
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