String: " A combination of Characters is called String".
Program code:
{
char istring[30] , ostring[30] , redo ;
cout<<"**************************************************"<<endl;
cout<<" Conversion of String into Upper and Lower case "<<endl<<endl;
cout<<"**************************************************"<<endl<<endl;
do
{
cout<<"Enter String"<<endl<<endl;
cin>>istring;
cout<<endl<<endl;
strcpy(ostring,istring);
cout<<"String in lower Case :"<<endl<<endl;
cout<<strlwr(ostring);
cout<<endl<<endl;
cout<<"String in Upper Case :"<<endl<<endl;
cout<<strupr(ostring);
cout<<endl<<endl;
cout<<"**************************************************"<<endl;
cout<<" For more conversion enter y or Y = ";
cin>>redo;
cout<<endl<<endl;
}while(redo == 'y' || redo == 'Y');
getch();
}
Functions For Strings:
C++ supports wide variety of functions having different properties to deal with Strings.Some of them are given below.
Note: To use these functions don't forget to include library ==> #include<cstring> or #include<string.h>
- strcpy( str1,str2 ); ==> Copies string 2 to string 1.
- strlen(str1); ==> Gives the length of string 1.
- strcmp(str1,str2); ==> Do comparison. if equal result = 0 , if str2 is greater than str1 result > 0 , if str2 is smaller than str1 then result < 0
- strcat(str1,str2); ==> Concatenates string 1 and string 2.
If you don't about Strings ... read this article
Algorithm: Get string and copy it into another string and then convert it into upper and lower case by using this command
strupr(string_name) ==> for upper case
strlwr(string_name) ==> for lower case
Program code:
#include<iostream>#include<conio.h>#include<string.h>using namespace std;
int main(){
char istring[30] , ostring[30] , redo ;
cout<<"**************************************************"<<endl;
cout<<" Conversion of String into Upper and Lower case "<<endl<<endl;
cout<<"**************************************************"<<endl<<endl;
do
{
cout<<"Enter String"<<endl<<endl;
cin>>istring;
cout<<endl<<endl;
strcpy(ostring,istring);
cout<<"String in lower Case :"<<endl<<endl;
cout<<strlwr(ostring);
cout<<endl<<endl;
cout<<"String in Upper Case :"<<endl<<endl;
cout<<strupr(ostring);
cout<<endl<<endl;
cout<<"**************************************************"<<endl;
cout<<" For more conversion enter y or Y = ";
cin>>redo;
cout<<endl<<endl;
}while(redo == 'y' || redo == 'Y');
getch();
}
No comments:
Post a Comment