Monday, 22 December 2014

Write a program which will read a string object and a. rewrite it in the alphabetical order. For example, the word “string” should be written as “ginrst”. Write a member function which Modify the third character in input string by “X”.

SOLUTION:

#include<iostream.h>
#include<conio.h>
#include<string.h>

class stringsort
{
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);
getch();
}

OUTPUT:








No comments:

Post a Comment