NDROID TECH
  • Home (current)
  • Blog
  • About
  • Categories
    Entertainment
    Technology
    Programming
    Android
    Web Development
    Games
    Ethical Hacking
    motivational
  • Contact
  • Privacy Policy
  • Terms of Use
  1. Home
  2. Blog
image not available
  • 2020-03-23
  • admin
  • c programming, c, string, c++;
  • 195

String Operations calculate length of string, reverse string Copy string, compare two strings concatenate using c++



Share :

Program Name : String Operations
(1.calculate length of string,
2.reverse string
3.Copy string
4.comapre two strings
5.concatenate

#include <iostream>
/*———————————————–

Program Name : String Operations
(1.calculate length of string,
2.reverse string
3.Copy string
4.comapre two strings
5. concatenate)

encoded by : Pravin Rasal && Sagar Vp
lan : c++
Hardware req. : Any CPU with Pentium Processor or similar, 256 MB RAM or more, 1 GB Hard Disk or more.
Software req. : 64 bit Linux/Windows Operating System, G++ compiler
Author URL : https://ndroid360.wordpress.com/author/
Program URL : https://ndroid360.wordpress.com/2018/09/20/string-operations-calculate-length-of-string-reverse-string-copy-string-compare-two-strings-concatenate-using-c++

Created Date : Thursday 6 September 2018 04∶30∶40 PM IST

———————————————– */
using namespace std;
/*class with functions*/
class srt
{
public :
int len(char [20]);
void rev(char [20]);
void cpy(char [20]);
void comp(char [20], char [20]);
void cont(char [20], char [20]);
};

/*lenght function defination*/

int srt :: len (char str1[20])
{
int i,len;

for (i=0; str1[i]!=’\0′;i++);
len=i;
return len;
}

/*reverse function defination*/
void srt::rev (char str1[20])
{
int i,len;

for (i=0; str1[i]!=’\0′;i++);
len=i;
for (i=len;i>=0;i–)
{
cout<<str1[i];
}
}

/*copy function defination*/
void srt::cpy(char str1[20])
{
char str2[20];
int i,len;
for (i=0; str1[i]!=’\0′;i++);
len=i;
for(i=0;i<len;i++)
{
str2[i]=str1[i];
}
cout<<str2;
}

/*compate function defination*/
void srt::comp(char str1[20], char str2[20])
{
int i,j,len1,len2,flag;

for (i=0; str1[i]!=’\0′;i++);
len1=i;
cout<<len1<<“\n”;

for (j=0; str2[j]!=’\0′;j++);
len2=j;
cout<<len2<<“\n”;

for(i=0,j=0; i<len1 && j<len2;i++,j++)
{
if(str1[i]!=str2[j])
{
break;
}
else
continue;
}
if(str1[i]==str2[j])
{
cout<<“both string are equal\n”;
}
else
{
cout<<“both strings are not equal\n”;
}
}

/*concatenate function defination*/
void srt::cont(char str1[20], char str2[20])

{
char str3[20];
int i,j,len1,len2,flag;

for (i=0; str1[i]!=’\0′;i++);
len1=i;
cout<<len1<<“\n”;

for (j=0; str2[j]!=’\0′;j++);
len2=j;
cout<<len2<<“\n”;

for(i=0;i<len1;i++)
{
str3[i]=str1[i];
}

for(i=len1,j=0;i<len1+len2,j<len2;i++,j++)
{
str3[i]=str2[j];
}
i=len1+len2;
str3[i]=’\0′;
cout<<str3<<“\n”;
}
/*main function*/

int main()
{
/*object s*/
srt s;
int len,i,ch,op;
char str1[20],str2[20];
do
{
/*Menu*/
cout<<“menu\n1.Lenght \n2.Array reverse\n3.copy of array\n4.array compare\n5.concantanate\n”;
cin>>ch;
switch (ch)
{
case 1: cout<<“Enter string 1\n”;
cin>>str1;
/*call to length function*/
len=s.len(str1);
cout<<“length is “<<len<<“\n”;
break;
case 2: cout<<“Enter string 1\n”;
cin>>str1;
cout<<“reverse string is\n”;
/*call to reverse function*/
s.rev(str1);
break;
case 3: cout<<“Enter string 1\n”;
cin>>str1;
cout<<“copy of “<<str1<<” is “;
/*call to copy function*/
s.cpy(str1);
break;
case 4: cout<<“Enter the str 1\n”;
cin>>str1;
cout<<“Enter srt2\n”;
cin>>str2;
/*call to compare function*/
s.comp(str1,str2);
break;
case 5: cout<<“Enter the str 1\n”;
cin>>str1;
cout<<“Enter srt2\n”;
cin>>str2;
/*call to concatenate function*/
s.cont(str1,str2);
break;
}
cout<<“\nDo u want to continue 1\n”;
cin>>op;
cout<<“————————————-\n”;
}
while(op==1);
cout<<“https://ndroid360.wordpress.com\n”;
}



Categories

  • Entertainment 3
  • Technology 14
  • Programming 9
  • Android 11
  • Web Development 5
  • Games 14
  • Ethical Hacking 3
  • motivational 2


Stay Connected

  • Twitter
  • Facebook
  • Dribble
  • Pinterest


Editor's Choice

fantastic cms
Now ट्रैक कर सकेंगे कोरोना वायरस की जानकारी !!!
2020-03-22
fantastic cms
Whatsapp यह है खास फीचर| यूजर्स मैसेज की कर पाएंगे जांच !!!!!
2020-03-23


fantastic cms
सोशल मीडिया प्लेटफॉर्म से इन्हें हटाने के निर्देश : IT मंत्रालय सख्त
2018-04-27
fantastic cms
Benefits of WhatsApp ????
2018-04-27


fantastic cms
The future of वेब डिजाइनिंग on earth
2018-04-27
fantastic cms
Computer Science Projects and ideas for Engineering students as well as interested students.
2018-04-27


NDROID TECH

This is a ndroid.tech is related to technology blog. since active from 2018

About Us

Popular Posts

fantastic cms
How Corona effected on technology ???
2020-03-21
fantastic cms
How to activate windows 10 using CMD or batch file
2020-06-01

Signup to our newsletter

We respect your privacy.No spam ever!

  • Facebook
  • Twitter
  • Google+
  • Pinterest

ndroid tech 2021 | Brought To You by ndroid.tech