SOLUTION:
#include<iostream.h>
#include<conio.h>
#include<string.h>
{
int n, i,j, temp;
public:
void modify(char s[30]);
void alphasort(char s[30]);
};
void stringsort::modify(char s[30])
{
n=strlen(s);
while(s[n]!='\0')
{
n++;
}
cout<<"\nThe new modifed string is:";
for(i=0;i<n;i++)
{
if (i==2)
cout<<"x";
else
cout<<s[i];
}
}
void stringsort::alphasort(char s[30])
{
n=strlen(s);
while(s[n]!='\0')
{
n++;
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(s[j]>s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
cout<<"\nThe string in alphabetical order is:";
for(i=0;i<n;i++)
{
cout<<s[i];
}
}
void main()
{
char s[30];
stringsort s1;
clrscr();
cout<<"Enter the string:";
cin>>s;
s1.modify(s);
s1.alphasort(s);
}
OUTPUT:
No comments:
Post a Comment