Followers

Thursday, January 5, 2012

CASE CONVERSION IN A STRING - USING LOGIC

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

char strng[50];
int len, n;

void cmpltcnvrsion(char strng[50])
{
  for(int i=0 ; i<len ; i++)
  {
    if((97<=int(strng[i]))&&(int(strng[i])<=122))
      cout<<char(int(strng[i])-32);

    else if((65<=int(strng[i]))&&(int(strng[i])<=90))
      cout<<char(int(strng[i])+32);

    else
      cout<<strng[i];
  }
}

void capital(char strng[50])
{
  for(int i=0 ; i<len ; i++)
  {
    if((97<=int(strng[i]))&&(int(strng[i])<=122))
      cout<<char(int(strng[i])-32);
    else
      cout<<strng[i];
  }
}

void small(char strng[50])
{
  for(int i=0 ; i<len ; i++)
  {
    if((65<=int(strng[i]))&&(int(strng[i])<=90))
      cout<<char(int(strng[i])+32);

    else
      cout<<strng[i];
  }

}

void main()
{
  clrscr();
  cout<<"Enter a string :\n";
  cin.getline(strng,50);
  len=strlen(strng);
  cout<<"\n\nChoose the type of conversion : \n 1>Complete conversion \n 2>ALL CAPITAL \n 3>all small \nEnter your choice : ";
  cin>>n;
  switch(n)
  {
    case 1  : cmpltcnvrsion(strng);
    break;
    case 2  : capital(strng);
    break;
    case 3  : small(strng);
    break;
  }
  getch();
}
.................................................................
OUTPUT: (click to enlarge the image)


No comments:

Post a Comment