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.
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started