Question: 1. Write C++ statements: write a statement for each of the following: a. Print 200 with and without a sign. 2. Write a program in

1. Write C++ statements: write a statement for each of the following:

a. Print 200 with and without a sign.

2. Write a program in c++ that accomplishes each of the following:

a. Create a user-defined class Point that contains the private integer data members xCoordinate and yCoordinate and declares stream insertion (>) over-loaded operator functions as friends of the class.

b. Define the stream insertion and stream extraction operator functions. The stream extraction operator function should determine whether the data entered is valid, and, if not, it should set the failbit to indicate improper input.

input.setstate(std::ios::failbit);

The stream insertion operator should not be able to display the point after an input error occurred.

c. Write a main function that tests input and output of user-defined class Point, using the overloaded stream extraction and stream insertion operators.

d. See Fig 10.3 to Fig 10.5 for examples, page 456-457 of the C++ book.

1. Write C++ statements: write a statement for each of the following:

05 overloading the Binary Stream Insert Operator Overloading: Class string Insertion and Stream Extraction Operators 455 Chapter 10 457 roaded stream extraction operator; cannot be a member function ratorss (istrean& input, PhoneNunberk number) t setw(3) >number.areaCode: // input area code setw) nunber.exchange // input exchange nunber.line; / input Tine to outpur them in the format ovr would ike to invoke it with cinsomePhoneNumber: 18 Area code: 555 Exchange: 555 Line: 5555 (555) 555-5555 input >> input.ignor// skip and munber.exchange: /! input exchange r corer 24 nput.ignoreo: // skip dash () Theprogamasume rdu sset return int enab les cin a > b I I Fig. 10.3: PhoneNumber.h 2 /PhoneNumber class definition 3 #ifndef PHONENUMBER H 4 Overloaded streamm insertion and stream extraction operators for class PhoneNurber 4 #define PHONENUMBERH 6 include (std: :istreame, PhoneNumber&) td: :ostreams operator(cin, phane) Fig. 10.3 | Phonelumber class with overloaded steam insertion and stream extraction 15 cin phone 16 operators as friend functions. "nThe phone nunber entered was: " 18 9 // cout 5 #include"PhoneNumber "h" 6 using namespace std; stream insertion and stream extraction operators Enter phone number in the forn (555) 555-5555: (800) 555-1212 8 11 overloaded stream insertion operator; cannot be a member function 9 I if we would Tike to invoke it with cout ) Operator return output; // enables cout

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 Databases Questions!