Code:
class Name
{
//make the friend functions public, not private
friend ostream &operator<<( ostream &, const Name &n );
//the insertion operator doesn't make much sense in context of
//the member variables.
friend istream &operator>>( istream &, Name &n );
public:
//include a default constructor and a copy constructor. Neither
//will be provided by default if you declare the following
//constructor
Name( char *, char * );
~Name();
bool operator==( const Name &n ) const;
const Name operator+=( const Name &n );
char first[ 26 ];
char last[ 26 ];
char total[ 52 ];
};
//need to name the variables sent as parameters here. see post
//by ninebit
Name::Name(char *, char * )
{
}
ostream &operator<<( ostream &output, const Name &n )
{
output << n.first << n.last; //or output << total;
return output;
}
istream &operator>>( istream &input, Name &n )
{
input >> setw( 26 ) >> n.first;
input >> setw( 26 ) >> n.last;
return input;
}
bool Name:perator==( const Name &n ) const
{
//sinc first and last are null terminated strings use strcmp() to
//compare them, not == or !=
if (n.first != n.last )
return false;
if ( n.first == n.last )
return true;
}
//nee to name the parameter sent in and use :: rather than :
Name:perator +=( char )
{
//since first and last are null terminated strings, use strcat()
//rather than += to concatenate them
Name&last += Name&first;
return &last;
}
char main()
{
Name name; //declaring instance of class using default
//constructor, of which there is none
cout << "Enter full name in the form of abcdefghijk abcdefghijk:\n";
/* use getline to enter string that includes whitespace. place
initially in total. then parse total into two names and then
stcpy the two names into first and last respectively or use two
separate input lines to place data into first and last and then
strcat() the two to get total id name declared with default constructor or use getline() to read string with whitespace into dummy buffer, parse into two strings and declare name using two parameter constructor passing the two strings you developed by parsing
*/
cin >> name;
cout << " The name entered was: " << name << endl;
return 0;
}