#include<iostream>
using namespace std;
void swap(int&,int&);
void swap(int [],int[],int);
void swap(char&,char&);
void swap(char[],char[]);
void printarr(const int[],int);
void printarr(const char[]);
int stringlength(char []);
bool searchsubstring(char[],char[]);
bool replacesubstring(char[],char[],char[]); //All green lines arfe function prototypes.
void main() //main starts here
{
char array1[100]={'\0'}; //here both arrayrs array1 & array2 are of size 100 & 10 ,respectively
char array2[10]={'\0'}; //and having value NULL on all of its locations
int a=4,b=32;
int a1[5],b1[5];
for(int i=0;i<5;i++)
{
a1[i]=i;
b1[i]=i+5;
}
char ch1,ch2;
ch1='A';
ch2='z';
char arr1[5]={'A','Z','r','Y'};
char arr2[5]={'b','E','i','s'};
cout<<"Without Swap int\n";
cout<<"a:"<<a<<" b:"<<b<<"\n";
swap(a,b);
cout<<"After Swap\n";
cout<<"a:"<<a<<" b:"<<b<<"\n";
cout<<"________________________________________________________\n";
cout<<"Without swap int[]\narr1:";
for(int i=0;i<5;i++)
cout<<a1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<b1[i]<<" ";
swap(a1,b1,5);
cout<<"\nAfter swap int[]\narr1:";
for(int i=0;i<5;i++)
cout<<a1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<b1[i]<<" ";
cout<<"\n________________________________________________________\n";
cout<<"Without swap char\nch1:";
cout<<ch1;
cout<<"\nch2:";
cout<<ch2;
cout<<"\nAfter swap char\nch1:";
swap(ch1,ch2);
cout<<ch1;
cout<<"\nch2:";
cout<<ch2;
cout<<"\n________________________________________________________\n";
cout<<"Without swap char[]\narr1:";
for(int i=0;i<5;i++)
cout<<arr1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<arr2[i]<<" ";
cout<<"\nAfter swap char[]\narr1:";
swap(arr1,arr2);
for(int i=0;i<5;i++)
cout<<arr1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<arr2[i]<<" ";
cout<<"\n________________________________________________________\n";
cout<<"print array 1 of int\n";
cout<<"arr1:";
printarr(a1,5);
cout<<"\n________________________________________________________\n";
cout<<"print array 1 of char\n";
cout<<"arr1:";
printarr(arr1);
cout<<"\n________________________________________________________\n";
cout<<"Enter String:";
cin.getline(array1,100,'\n');
cout<<"length on array1 is:"<<stringlength(array1);
cout<<"\n________________________________________________________\n";
cout<<"search substring in array 1 of char string\n";
cout<<"Enter Sub string:";
cin>>array2;
cout<<searchsubstring(array1,array2);
cout<<"\n________________________________________________________\n";
char array3[10];
cout<<"Search and Replace substring in array 1 of char string\n";
cout<<"Enter Sub string:";
cin>>array2;
cout<<"Enter String to Replace:";
cin>>array3;
replacesubstring(array1,array2,array3);
cout<<"\nReplaced array:";
cout<<array1;
cout<<"\n________________________________________________________\n";
}
void swap(int &a,int& b)
{
a=a+b;
b=a-b;
a=a-b;
}
void swap(int a[],int b[],int size)
{
int temp;
for(int i=0;i<size;i++)
{
temp=a[i];
a[i]=b[i];
b[i]=temp;
}
}
void swap(char& c1,char& c2)
{
char temp;
temp=c1;
c1=c2;
c2=temp;
}
void swap(char a[],char b[])
{
char temp;
for(int i=0;i<5;i++)
{
temp=a[i];
a[i]=b[i];
b[i]=temp;
}
}
void printarr(const int a[],int size)
{
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
}
void printarr(const char a[])
{
for(int i=0;i<5;i++)
cout<<a[i]<<" ";
}
int stringlength(char a[])
{
for(int i=0;i<100;i++)
{
if(a[i]=='\0')
return i;
}
return 0;
}
bool searchsubstring(char a[],char b[])
{
int y=strlen(b);
y--;
for(int i=0;i<100;i++)
{
if(a[i]==b[0])
{
for(int j=0;j<10;j++)
{
if(a[i]==b[j])
{
if(y==j)
{
return 1;
}
i++;
}
}
}
}
return 0;
}
bool replacesubstring(char a[],char b[],char c[])
{
int y=strlen(b);
y--;
for(int i=0;i<100;i++)
{
if(a[i]==b[0])
{
for(int j=0;j<10;j++)
{
if(a[i]==b[j])
{
a[i]=c[j];
if(y==j)
{
return 1;
}
i++;
}
}
}
}
return 0;
}
using namespace std;
void swap(int&,int&);
void swap(int [],int[],int);
void swap(char&,char&);
void swap(char[],char[]);
void printarr(const int[],int);
void printarr(const char[]);
int stringlength(char []);
bool searchsubstring(char[],char[]);
bool replacesubstring(char[],char[],char[]); //All green lines arfe function prototypes.
void main() //main starts here
{
char array1[100]={'\0'}; //here both arrayrs array1 & array2 are of size 100 & 10 ,respectively
char array2[10]={'\0'}; //and having value NULL on all of its locations
int a=4,b=32;
int a1[5],b1[5];
for(int i=0;i<5;i++)
{
a1[i]=i;
b1[i]=i+5;
}
char ch1,ch2;
ch1='A';
ch2='z';
char arr1[5]={'A','Z','r','Y'};
char arr2[5]={'b','E','i','s'};
cout<<"Without Swap int\n";
cout<<"a:"<<a<<" b:"<<b<<"\n";
swap(a,b);
cout<<"After Swap\n";
cout<<"a:"<<a<<" b:"<<b<<"\n";
cout<<"________________________________________________________\n";
cout<<"Without swap int[]\narr1:";
for(int i=0;i<5;i++)
cout<<a1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<b1[i]<<" ";
swap(a1,b1,5);
cout<<"\nAfter swap int[]\narr1:";
for(int i=0;i<5;i++)
cout<<a1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<b1[i]<<" ";
cout<<"\n________________________________________________________\n";
cout<<"Without swap char\nch1:";
cout<<ch1;
cout<<"\nch2:";
cout<<ch2;
cout<<"\nAfter swap char\nch1:";
swap(ch1,ch2);
cout<<ch1;
cout<<"\nch2:";
cout<<ch2;
cout<<"\n________________________________________________________\n";
cout<<"Without swap char[]\narr1:";
for(int i=0;i<5;i++)
cout<<arr1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<arr2[i]<<" ";
cout<<"\nAfter swap char[]\narr1:";
swap(arr1,arr2);
for(int i=0;i<5;i++)
cout<<arr1[i]<<" ";
cout<<"\narr2:";
for(int i=0;i<5;i++)
cout<<arr2[i]<<" ";
cout<<"\n________________________________________________________\n";
cout<<"print array 1 of int\n";
cout<<"arr1:";
printarr(a1,5);
cout<<"\n________________________________________________________\n";
cout<<"print array 1 of char\n";
cout<<"arr1:";
printarr(arr1);
cout<<"\n________________________________________________________\n";
cout<<"Enter String:";
cin.getline(array1,100,'\n');
cout<<"length on array1 is:"<<stringlength(array1);
cout<<"\n________________________________________________________\n";
cout<<"search substring in array 1 of char string\n";
cout<<"Enter Sub string:";
cin>>array2;
cout<<searchsubstring(array1,array2);
cout<<"\n________________________________________________________\n";
char array3[10];
cout<<"Search and Replace substring in array 1 of char string\n";
cout<<"Enter Sub string:";
cin>>array2;
cout<<"Enter String to Replace:";
cin>>array3;
replacesubstring(array1,array2,array3);
cout<<"\nReplaced array:";
cout<<array1;
cout<<"\n________________________________________________________\n";
}
void swap(int &a,int& b)
{
a=a+b;
b=a-b;
a=a-b;
}
void swap(int a[],int b[],int size)
{
int temp;
for(int i=0;i<size;i++)
{
temp=a[i];
a[i]=b[i];
b[i]=temp;
}
}
void swap(char& c1,char& c2)
{
char temp;
temp=c1;
c1=c2;
c2=temp;
}
void swap(char a[],char b[])
{
char temp;
for(int i=0;i<5;i++)
{
temp=a[i];
a[i]=b[i];
b[i]=temp;
}
}
void printarr(const int a[],int size)
{
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
}
void printarr(const char a[])
{
for(int i=0;i<5;i++)
cout<<a[i]<<" ";
}
int stringlength(char a[])
{
for(int i=0;i<100;i++)
{
if(a[i]=='\0')
return i;
}
return 0;
}
bool searchsubstring(char a[],char b[])
{
int y=strlen(b);
y--;
for(int i=0;i<100;i++)
{
if(a[i]==b[0])
{
for(int j=0;j<10;j++)
{
if(a[i]==b[j])
{
if(y==j)
{
return 1;
}
i++;
}
}
}
}
return 0;
}
bool replacesubstring(char a[],char b[],char c[])
{
int y=strlen(b);
y--;
for(int i=0;i<100;i++)
{
if(a[i]==b[0])
{
for(int j=0;j<10;j++)
{
if(a[i]==b[j])
{
a[i]=c[j];
if(y==j)
{
return 1;
}
i++;
}
}
}
}
return 0;
}
No comments:
Post a Comment