Sunday, February 7, 2010

CS201 GDB

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

// temp object

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

}

No comments:

Post a Comment

 

best kindle covers | ambien sleeping pills