Implements a class string that implements dynamic and deep
copy constructor. Also write member function to a rewrite a string object in
the alphabetical order. For example, the word” string” should be written as
“ginrst”.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
char c;
public:
string()
{
cout<<"constructor without arguments"<<endl;
}
string(int s)
{
c= (char) s;
cout<<"symbol of entered ASCII value in parameterized constructor:"<<c<<endl;
}
string(string &j)
{
c=j.c;
cout<<"ASCII value of entered character in copy constructor: "<<(int)c<<endl;
}
void alphasort(char s[30]);
};
void string::alphasort(char s[30])
{
int n, i, j, temp;
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<<"The string in alphabetical order is:";
for(i=0;i<n;i++)
{
cout<<s[i];
}
}
void main()
{
char s[30];
clrscr();
string s1;
string s2(88);
string s3(s2);
cout<<"Enter the string to be sorted in alphabetical order:";
cin>>s;
s1.alphasort(s);
getch();
}
OUTPUT:
No comments:
Post a Comment