C++ program to change every letter in a given string with the letter following it in the alphabet (ie. a becomes b, p becomes q, z becomes a).
Write a C++ program to change every letter in a given string with the letter following it in the alphabet (ie. a becomes b, p becomes q, z becomes a).
This is my first blog guys .Hope you all'll love this .๐๐Here is my code which I used to write this program :
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
cout<<" program to change every letter in a given string with the letter \nfollowing it in the alphabet"<<endl;
cout<<endl;
char change_letter[100];
int size;
cout<<"enter string"<<endl;
cin.get(change_letter,100);
size=strlen(change_letter);
{
int char_code;
for(int i=0;i<size;i++)
{
char_code=int(change_letter[i]);
if(char_code==122) //value of z
{
change_letter[i]=char(97); //mean z will be replaced by a whose value is a=97
}
else if(char_code==90) // value of Z
{
change_letter[i]=char(65); //Z will be replace by A
}
else if(char_code>=65 && char_code <=90 || char_code >=97 && char_code<=122)
{
change_letter[i]=char(char_code+1) ; //1 will be added in value of asc so that it will print next letter
}
}
}
cout<<"The Changed string is ="<<change_letter;
return 0;
}
And the output of my program is
Comments
Post a Comment