#ifndef NAME_H
#define NAME_H
#include <iostream.h>
#include "FixedString.h"
class Name {
friend ostream & operator <<(ostream & oStream, const Name & thisName);
friend istream & operator >>(istream & iStream, Name & thisName);
public:
Name();
Name(const char * first, const char * last);
Name(const FixedString & first, const FixedString & last);
void SetFirst(const char * first);
void SetFirst(const FixedString & first);
void SetLast(const char * last);
void SetLast(const FixedString & last);
FixedString GetFirst() const;
FixedString GetLast() const;
private:
FixedString firstName;
FixedString lastName;
};
#endif
ostream & operator <<(ostream & oStream, const Name & thisName)
{
oStream << "First Name:" << thisName.firstName << endl;
oStream << "Last Name:" << thisName.lastName << endl;
return oStream;
}
istream & operator >>(istream & iStream, Name & thisName)
{
cout << "First Name:";
iStream >> thisName.firstName;
cout << "Last Name:";
iStream >> thisName.lastName;
return iStream;
}
Name::Name(const FixedString & first, const FixedString & last) :
firstName(first), lastName(last)
// POST: constructs new Name object with copies of last and first
{
// all work done in constructor initializer
}
- do the IO overloaded operators have to be friends
- rewrite the I/O so it is not a friend
- in the definition of >> what is the type of
thisName?
- What is teh type of thisName.firstName?
- What is the type of iStream
- change the input operator so that it does not prompt the
user
- change the output operator so that it prints the last
name followed by a comma and space and then the first
name with no other output
- if we changed the output type of SetFirst to FixedString,
what would happen with the following statement
myName.SetLast(myName.SetFirst("wild"));
- In the last constructor eliminate the constructor
initializer and change the defintion to accomplish the
same task