Register number

Ex No: / String concatenation using dynamic memory allocation concept.
Date :

Aim:

Algorithm:

Program:

#include<iostream.h>

#include<conio.h>

#include<string.h>

class string

{

protected:

char *s1,*s2,*s3;

int len1,len2;

public:

string();

string(char *ts1,char *ts3);

void concatenate();

~string();

};

string::string()

{len1=0;len2=0;s1=0;s2=0;s3=0;}

string::string(char *t1,char * t3)

{

len1=strlen(t1);

len2=strlen(t3);

s1=new char[len1+len2];

s3=new char[len2];

strcpy(s1,t1);

strcpy(s3,t3);

}

void string::concatenate()

{

s2=new char[len2];

strcpy(s2,s3);

cout<"\nString 1: "<s1;

cout<"\nString 2: "<s2;

strcat(s1,s2);

cout<"\nThe Result is : "<s1;

}

string::~string()

{

delete []s1;

delete[]s2;

delete[]s3;

}

void main()

{

char *p1,*p2;

cout<"enter two strings";

cin>p1>p2;

clrscr();

string s(p1,p2);

s.concatenate();

getch();

}

Output:

Performance / 25
Record / 15
Viva Voice / 10
Total / 50

Result:

Thus the program for String concatenation using dynamic memory allocation concept was implemented using C++ successfully.

OBJECT ORIENTED PROGRAMMING LAB