Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


#include <iostream.h>
#include <string.h>

class String
      {
        private :
                char string [ 30 ] ;
        public :
               String ( )
                      {
                      strcpy ( string , "" ) ;
                      }
               void GetString( )
                    {
                    cout"Enter the String : " ;
                    cin>>string ;
                    }
               void Display( )
                    {
                    cout "The String Is : " string endl ;
                    }
                    // Declaration (prototype) of overloaded sum operator
                    String operator + ( String & s ) ;
                    String operator += ( String & s ) ;
                    };
 
               String String :: operator + ( String &s )
                      {
                      String temp; // Declared object temp of String type
                      strcpy ( temp.string , "" ); // Initialized the temp with empty string   
                      strcat ( temp.string , string ); // Concatenated the driving object’s string to
                      // temp object
                      strcat ( temp.string , s.string ); // Concatenated the argument’s string to the
                      return temp; // Returned the temp object
                      }
                                            
                String String :: operator += ( String &s )
                       {
                       String temp; // Declared object temp of String type
                       strcpy ( temp.string , "" ); // Initialized the temp with empty string
                       strcat ( temp.string , string ); // Concatenated the driving object’s string to
                       // temp object
                       temp=temp+s;
 
                       return temp; // Returned the temp object
                       }

int main()
    {
     String string1, string2;
     string1.GetString();
     string2.GetString();
     //String hold = string1 + string2;
     //hold.Display();
     String hold = string1 += string2;
     hold.Display();
     system("PAUSE");
     return 0;
     }

Views: 99

Looking For Something? Search Below

VIP Member Badge & Others

How to Get This Badge at Your Profile DP

------------------------------------

Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service