various operations on strings

QUE- WAP TO SHOW THE USE OF STRING FNs

insert

erase

substr

empty

size

length

getline

Answer-

#include<iostream.h>
#include<conio.h>
#include<string.h>
using std::string;
int main()
{
       string f,s2;
       char a[3];
       int c,n,l,q,w,e;
    cout << “Enter String: “;
       getline(cin,f);
     cout<< f <<endl;
     cout<<“\nEnter no. of character you want to skip: “;
     cin>>c;
     s2=f.substr(c);
     n=s2.empty();
    if(n==0)
    {
        cout<<s2;
         cout<<“\nSize of string after skipping chars:”<<s2.size();
         cout<<“\nLength of string :”<<f.length();
         cout<<“\nEnter 3 character to insert in s2:”;
         cin>>a;
        cout<<“\nEnter position from which you overwrite:”;
         cin>>l;
         cout<<“\nS2 after inserting at 2nd position:”<<s2.insert(l,a);
         cout<<“\nNo. of element you want to  delete:”;
         cin>>q;
         cout<<“\nPosition of element from where you want to  delete:”;
         cin>>w;
         cout<<“\nAfter <erase> fn.:”<<s2.erase(w,q);
        
    }
     cout<<“\n\nPROGRAMMING @C#ODE STUDIO”;
     getch();
}

STR_FN

STRING WITH SPACES;

QUESTION- HOW TO GETSTRING WITH GETLINE FN. AND PRINT

ANSWER-

#include<iostream.h>
#include<conio.h>
#include<string.h>
using std::string; //here we initialize the string std;
int main()
{
       string fullname; //initialization of string;
    cout << “Enter your first and last name: “;
       getline(cin, fullname); //taking input from user
     cout << “Hello ” << fullname <<endl;
     cout<<“\n\nPROGRAMMING @C#ODE STUDIO”;
     getch();
}

string_spc

POINTER(CALL BY REF)

QUE- HOW TO CALL A FUNC BY REFERENCE

ANS-

#include<iostream.h>
#include<conio.h>
void swaping(int &x, int &y);
int main()
{
int n1,n2;
cout<<“Enter first number n1 :”;
cin>>n1;
cout<<“\nEnter second number n2 :”;
cin>>n2;
cout<<“\nValues before swapping:”;
cout<<“\n n1=”<<n1<<” \n n2=”<<n2;
swaping(n1,n2);
cout<<“\nValues after swapping:”;
cout<<“\n n1=”<<n1<<” \n n2=”<<n2;
cout<<“\n\nPROGRAMMING @C#ODE STUDIO”;
getch();
return 0;
}
void swaping(int &x, int &y)
{
  int z;
  z=x;
  x=y;
  y=z;
}

point_add

Pointer (CALL BY address)

Question- Implement logic by using pointer call by address;

Answer-

#include<iostream.h>
#include<conio.h>
void swaping(int *x, int *y);
int main()
{
int n1,n2;
cout<<“Enter first number n1 :”;
cin>>n1;
cout<<“\nEnter second number n2 :”;
cin>>n2;
cout<<“\nValues before swapping:”;
cout<<“\n n1=”<<n1<<” \n n2=”<<n2;
swaping(&n1,&n2);
cout<<“\nValues after swapping:”;
cout<<“\n n1=”<<n1<<” \n n2=”<<n2;
cout<<“\n\nPROGRAMMING @C#ODE STUDIO”;
getch();
return 0;
}
void swaping(int *x, int *y)
{
  int z;
  z=*x;
  *x=*y;
  *y=z;
}

POINT_REF