OOPC Practical 15


Practical : 15
Subject : Object Oriented Programming with C++

Aim : C++ program to concat two string using operator overloading


Source Code :
#include<conio.h>
#include<string.h>
#include<iostream.h>
class string
{
charstr[100];
public:
void input();
void output();
string operator+(string s);
};
void string::input()
{
cout<<"enter the string\n";
cin>>str;
}
string string::operator+(string s)
{
string temp;
strcpy(temp.str,str);
strcat(temp.str,s.str);
return(temp);
}
void string::output()
{
cout<<"the string is\n";
cout<<str;
}
void main()
{
string s1,s2,s3;
clrscr();
s1.input();
s2.input();
s3=s1+s2;
s3.output();
getch();
}

Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment