Question: // Fig. 10.4: PhoneNumber . cpp // Overloaded stream insertion and stream extraction operators // for class PhoneNumber. #include 10 0 NOUAWN- #include PhoneNumber.h using

// Fig. 10.4: PhoneNumber . cpp // Overloaded// Fig. 10.4: PhoneNumber . cpp // Overloaded
// Fig. 10.4: PhoneNumber . cpp // Overloaded stream insertion and stream extraction operators // for class PhoneNumber. #include 10 0 NOUAWN- #include "PhoneNumber.h" using namespace std; // overloaded stream insertion operator; cannot be a member function // if we would like to invoke it with cout > somePhoneNumber; 20 istream& operator>>(istream& input, PhoneNumber& number) { 21 input . ignore(); // skip ( 22 input >> setw(3) >> number . areaCode; // input area code 23 input . ignore(2); // skip ) and space 24 input >> setw(3) >> number . exchange; // input exchange 25 input. ignore(); // skip dash (-) 26 input >> setw(4) >> number. line; // input line 27 return input; // enables cin > > a >> b >> c; 28 Fig. 10.4 Overloaded stream insertion and stream extraction operators for class PhoneNumber . // Fig. 10.5: fig10_05. cpp // Demonstrating class PhoneNumber's overloaded stream insertion // and stream extraction operators. #include #include "PhoneNumber.h" using namespace std; int main() { PhoneNumber phone; // create object phone cout > phone invokes operator>> by implicitly issuing 14 the non-member function call operator>>(cin, phone) 15 cin >> phone; 16 17 cout > and the stream insertion operator #include class PhoneNumber { 10 friend std: :ostream& operator> (std: : istream&, PhoneNumber&) ; 12 private: 13 std: : string areaCode; // 3-digit area code 14 std: : string exchange; // 3-digit exchange 15 std: : string line; // 4-digit line 16 17 18 #endif Fig. 10.3 PhoneNumber class with overloaded stream insertion and stream ex- traction operators as friend functions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!