OOCP (CPP) : Example # 11 : Concatenate two string using class method join in C++
* Lets start learning CPP (C++) Using Example.
* Constructor Example using c++.
//Written by Latest Technology Guide
//Title : OOCP (CPP) : Example # 11 : Concatenate two string using class method join in C++
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
class String
{
private:
char *st;
int len;
public:
String()
{
cout << endl << "Simple Constructor called..." << endl;
}
String(char *s)
{
cout << endl << "1 Para Constructor called..." << endl;
strcpy(st,s);
len = strlen(st);
}
void join(String a, String b);
void display();
};
void String :: join(String a, String b)
{
strcat(a.st,b.st);
strcat(st,a.st);
len = strlen(st);
}
void String :: display()
{
cout << "String is : " << st << endl;
cout << "Lengt is : " << len << endl;
}
//=================================================
// Void Main
//=================================================
void main()
{
String S1("Abcd "),S2("Xyz "),S3("Pqr ");
cout << "String 1 is : " << endl;
S1.display();
cout << "String 2 is : " << endl;
S2.display();
cout << "String 3 is : " << endl;
S3.display();
cout << "S1.Join(2,3) is : " << endl;
S1.join(S2,S3);
S1.display();
getch();
}
Output:
* You will find output as combination of string1 and string2.
--------------------------------------------------------------------------------
OOCP (CPP) : Example # 11 : Concatenate two string using class method join in C++
* Example demonstrate how to concatenate two string using method in c++.
* String class contains two constructor and having two method named join and display.
* Join method of string class can be used to join two string.
* Display method can be used to display value from the private variable.
Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.
--------------------------------------------------------------------------------
OOCP (CPP) : Example # 11 : Concatenate two string using class method join in C++
* Example demonstrate how to concatenate two string using method in c++.
* Join method of string class can be used to join two string.
* Display method can be used to display value from the private variable.
Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.
thank you for sharing nice article in your blog
ReplyDeletevisit
web tutorial programming
https://www.welookups.com