Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to copy 'n' number of characters from one string to another at position 'p'

Posted By: Easy Tutor     Category: C++ Programming     Views: 4202

A C++ Program to copy 'n' number of characters from one string to another at position 'p'.

Code for Program to copy 'n' number of characters from one string to another at position 'p' in C++ Programming

 #include<iostream.h>
 #include<string.h>
 #include<stdio.h>
 #include<conio.h>


 /*************************************************************************///-------------------------  copy_string  -------------------------------///*************************************************************************/class copy_string
    {
      private:
        charstring[100];

      public:
        copy_string()  { strcpy(string,""); }
        void get_value();
        void show_value(copy_string,copy_string,int,int);
    };


 /*************************************************************************///---------------------------  get_value( )  ----------------------------///*************************************************************************/void copy_string::get_value()
    {
       cout<<"\n Enter the string :";
       gets(string);
    }

 /*************************************************************************///------------  show_value(copy_string,copy_string,int,int)  ------------///*************************************************************************/void copy_string::show_value(copy_string string_1,copy_string string_2,
                    int position,int number_of_char)
    {
       int count=position+number_of_char;

       for(int i=position,j=0;i<number_of_char,j<number_of_char;i++,j++)
      string_1.string[i]=string_2.string[j];

       cout<<"\n The resultant string is :";

       for(int k=0;k<count;k++)
      cout<<string_1.string[k];

       cout<<endl;
    }

 /*************************************************************************//*************************************************************************///-----------------------------  Main( )  -------------------------------///*************************************************************************//*************************************************************************/

 main( )
    {
       clrscr();

       copy_string s;
       copy_string ss;

       int po;
       int no;

       s.get_value();
       ss.get_value();

       cout<<"\n Enter the position number 'p' = ";
       cin>>po;

       cout<<" Enter the number of characters 'n' = ";
       cin>>no;

       s.show_value(s,ss,po,no);

       getch();
       return 0;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to copy 'n' number of characters from one string to another at position 'p' is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!