Extend the following class definition so it overloads the input and output operators.

```
class Vect {
public:
Vect () {}
Vect ( double, double );
private:
double r; // magnitude
double theta; // direction (radians)
};
//
// Constructor 2: Initializes all components
//
Vect :: Vect( double vectMag, double vectDir )
{
r = vectMag;
theta = vectDir;
}
```

```
class Vect {
public:
Vect () {}
Vect ( double, double );
private:
double r; // magnitude
double theta; // direction (radians)
friend istream& operator>> ( istream&, Vect& );
friend ostream& operator<< ( ostream&, const Vect& );
};
//
// Constructor 2: Initializes all components
//
Vect :: Vect( double vectMag, double vectDir )
{
r = vectMag;
theta = vectDir;
}
//
// Input a Vect object
//
istream& operator>> ( istream& in, Vect& v )
{
in >> v.r >> v.theta;
return in;
}
//
// Display a Vect object
//
ostream& operator<< ( ostream& out, const Vect& v )
{
out << "radius = " << v.r << ", theta = " << v.theta;
return out;
}
```

Computer Science & Information Technology

You might also like to view...

Displayed values often do not match the ________ values viewed in the formula bar

Fill in the blank(s) with correct word

Computer Science & Information Technology

When the first ________ diagram is made, inputs and outputs are specified and these remain constant throughout all of the following diagrams.

A) concept B) user interface C) design D) context

Computer Science & Information Technology