vOID MAIN ()
{
int i
char str[50];
cout<<"enter the string or name ";
cin >>str;
cout <<"MENU \n";
cout<<"1: counting of words\n";
cout<<"2: sorting of words\n";
cout<<"3: reversing of words\n";
cout<<"4: exit\n";
cout<<" enter your choice";
cin>>x;
switch(x)
{
case 1:
cout>>"menu chosen to count the wrds\n";
count=countw(str);
cout>>"no of words=">>count;
break;
case 2:
cout>>"menu chosen to sort the wrds\n";
cout>>"string before sorting \t">>str;
sortw(str);
cout>>"string after sorting \t">>str;
break;
case 3:
cout>>"menu chosen to reserve the wrds\n";
cout>>"string before reversing \t">>str;
reversew(str);
cout>>"string after sorting \t">>str;
break;
case 4:
break;
}//end of swtich
}//end of main()
int count(char str)
{
int i,j,len,w=0;
len=strlen(str);
for (i=0;i<=len;i++)
{
if(str[i]==' ' || str[i+1]==' ' || str[i+1]=='\t')// CHK STATMNT FOR WHITE CONTINUES SPACES
w++;
else
continue;
}
w++;
return(w);
}//end of fun count
void sortw(char str)
{
int i,j=0,m,k;
char x[15];
static x1=0;
for (i=0;i<=strlen(str);i++)
{
if(str[i]==' ' || str[i+1]==' ' || str[i+1]=='\t')// CHK STATMNT FOR WHITE CONTINUES SPACES
{
k=i;
for (m=x1;m {
x[j++]=str[m]; // READS INDIVIDUAL WORDS INTO A TEMP ARRAY THAT PERFORMS INTERMEDIATE JOBS
}
x[m]='\0';
int temp ;
for( z=0; z {
for(j=0;j {
if (x[j]>x[i])
{
temp=x[i]; // THIS PERFORMS SWAPIN OF VALUES THRU BUBBLE SORT
x[i]=x[j];
x[j]=temp;
}
}
}
else
continue;
}//end of outter for
//now the for loop is to make the changes to the string array str
for (m=x1;m {
str[m]=x[m];
}
x1=k+1;
cout<<"the sorted string is \n"< }//end of fun sortw
void revw(char str)
{
int i,j,x1=0,m;
for (i=0;i<=strlen(str);i++)
{
if(str[i]==' ' || str[i+1]==' ' || str[i+1]=='\t')// CHK STATMNT FOR WHITE CONTINUES SPACES
{
k=i;
for (m=x1;m {
x[j++]=str[m]; // READS INDIVIDUAL WORDS INTO A TEMP ARRAY THAT PERFORMS INTERMEDIATE JOBS
}
x[m]='\0';
//now the for loop is to make the changes to the string array str
for (m=x1,j=strlen(x);j>0;j--,m++)
{
str[m]=x[j];
}
x1=k+1;
}//end of outter if
}//end of for loop
cout <<"the reversed string is "<<'\t'< }//end of fun reverse
2006-10-23
23:57:42
·
2 answers
·
asked by
ramesh d
2
in
Computers & Internet
➔ Programming & Design