Show how to overload the operators << and >> to create stream output for this class. Make these functions friends of the class Pair. The expected form of a pair is (2,3) for both input and output. To make this problem manageable, you should only provide to accept and discard the parentheses and comma, but you should not check that these particular characters were typed. Output should be the expected form.

```
class IntPair
{
int first;
int second;
public:
IntPair(int firstValue, int secondValue);

int getFirst( ) const; int getSecond( ) const; };
```


```
#include
using namespace std; //Class with friend declarations: class IntPair { int first;
int second;
public:
IntPair(int firstValue, int secondValue);
friend int operator>>(int,IntPair);

friend istream& operator>>(istream& intStr,
IntPair& pair); friend ostream& operator<<(ostream& outStr,
const IntPair& pair); int getFirst( ) const; int getSecond( ) const; };

//Definitions
istream& operator>>(istream& inStr,IntPair& pair)
{
// only vestigial checking. Expect the form (1,2) char ignore; // for ( , and ). inStr >> ignore >> pair.first >> ignore >> pair.second >> ignore;
return inStr;
}
ostream& operator<<(ostream& outStr,const IntPair& pair)
{
outStr << "(" << pair.first << ", "
<< pair.second << ")";
return outStr;
}
```

The IntPair parameter for this operator<< is constant call-by-
reference because output routines do not change the caller’s argument. On the other hand, the purpose of an input routine is to change the caller’s argument, so there we use call-by-reference.

Computer Science & Information Technology

You might also like to view...

Select all that apply. Which of the following are constructors of the BorderPane class?

a. BorderPane() b. BorderPane(top, bottom) c. BorderPane(center) d. BorderPane(left, right) e. BorderPane(center, top, right, bottom, left)

Computer Science & Information Technology

By default a background image moves along with the element content as a user scrolls through the page.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Any type of RAM will work in your computer

Indicate whether the statement is true or false

Computer Science & Information Technology

To format a date, click the Date option in the ____________________ tab in the Format Cells dialog box.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology