Monday, 10 June 2013

C++ Program to Concatenate two strings

/*WAP that has a class with character array as its data member.
One object should contain "Computer Scientists are" and another
should contain " creators of logic". Member function join() should
concatanate two strings by passing two objects as arguments. Display
the concatanated string through a member function. Use constructor
to allocate and intialize the data member. Make one function for
concatanation of two strings.*/

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

class concatanate{
char string[50];
    static count =1;
      concatanate(){ //constructor
      if (count == 1){
          strcpy(string, "Computer Scientists are");
          strcpy(string, " creators of logic.");
      //function to concatanate strings
      void join(concatanate a, concatanate b){
      concatanate merged;
         strcat(a.string , b.string);//concatanate a and b strings
         strcpy(merged.string, a.string);
      //function to display concatanated string
      void display(concatanate a){
      cout<<"Concatanated String is:"<<endl<<endl;

void main(){
   concatanate a,b;

No comments:

Post a Comment

Was this post helpful? Ask any questions you have, I will try to answer them for you.

Follow by Email