|
#ifndef _PhoneNumber_h_
#define _PhoneNumber_h_
// INCLUDES
#include<iostream.h>
// NAME: PhoneNumber - TYPE: C++ CLASS
//
// SYNOPSIS:
// DESCRIPTION:
// parses phone numbers of type (0800) 555-1212
// into objects of type PhoneNumber
// EXAMPLES: see driver
// BUGS:
// SEE ALSO:
////////////////////////////////////////////
class PhoneNumber
{
public:
// LIFECYCLE
// PhoneNumber();
// constructor`
// PhoneNumber(const PhoneNumber&);
// copy constructor
// ~PhoneNumber();
// destructor
// OPERATORS
friend ostream& operator<<(ostream&,
const PhoneNumber&);
friend istream& operator>>(istream&,
PhoneNumber&);
// PhoneNumber& operator=(PhoneNumber&);
// assignment operator
// OPERATIONS
// ACCESS
// INQUIRY
protected:
private:
char areaCode[4]; // 3digit area code and NULL
char exchange[4]; // 3 digit exchange and NULL
char line[5]; // 4 digit line number and NULL
};
// overloaded stream insertion operator (cannot
be a member function)
ostream& operator<<(ostream& output,
const PhoneNumber& num)
{
output << "(" << num.areaCode
<< ")"
<< num.exchange << "-"
<< num.line;
return output; // enables cout << a
<< b << c;
}
// overloaded stream extraction operator
// (cannot be a member function)
istream& operator>>(istream& input,
PhoneNumber& num)
{
input.ignore(); // skip(
input.getline(num.areaCode, 4); // input area
code
input.ignore(2); // skip) and space
input.getline(num.exchange, 4); // input exchange
code
input.ignore(); // skip dash (-)
input.getline(num.line, 5); // input line
return input; // enables cin >> a >>
b >> c;
}
#endif // _PhoneNumber_h_
|