/*
j_3_4
Write a C++ program that overloads the + operator and appropriate (suitable) relational
operator to perform the following operations:
a) Concatenation of two strings.
b) Comparison of two strings.
*/
#include <iostream.h>
#include <conio.h>
#include <string.h>
class string
{
char str1[10];
public:
void get()
{
cout << "Enter string = ";
cin.getline(str1, 10);
}
string operator+(string s)
{
string obj;
strcat(str1,s.str1);
strcpy(obj.str1, str1);
return obj;
}
void display()
{
cout << "\n\t String :" << str1;
}
};
void main()
{
clrscr();
string obj1, obj2, obj3;
obj1.get();
obj2.get();
obj3 = obj1 + obj2;
obj3.display();
getch();
}
Comments
Post a Comment