C++ LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART- B

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

old

PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 . . .

write a c++ program to concatenate two string using operator overloading

 
  #include< iostream >
#include< string.h >
using namespace std;

class String
{
        public:
                char str[20];
        public:
                void accept_string()
                {
                        cout << "\n Enter String  :   ";
                        cin >> str;
                }
                void display_string()
                {
                        cout << str;
                }
                String operator+(String x)  //Concatenating String
                {
                        String s;
                        strcat(str,x.str);
                        strcpy(s.str,str);
                        return s;
                }
};
int main()
{
        String str1, str2, str3;

        str1.accept_string();
        str2.accept_string();

        cout << "\n ----------------------------------------------";
        cout << "\n\n First String is           :  ";
        str1.display_string();   //Displaying First String

        cout << "\n\n Second String is          :  ";
        str2.display_string();  //Displaying Second String

        cout << "\n ----------------------------------------------";
        str3=str1+str2;  //String is concatenated. Overloaded '+' operator
        cout << "\n\n Concatenated String is    :  ";
        str3.display_string();

        return 0;
}