Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The istream operator here is being overloaded and im not sure what the TODO mean. I looked up what peek does but i dont know

The istream operator here is being overloaded and im not sure what the TODO mean. I looked up what peek does but i dont know how to use it in this situation. Please help

// TODO: Make this read integer values if no '/' is given as a separator. // You may assume that there is no space between the numerator and the // slash. Hint, find and read the reference documentation for istream::peek(). std::istream& operator>>(std::istream& is, Rational& r) { int p, q; char c; is >> p >> c >> q; if (!is) return is;

// Require that the divider to be a '/'. if (c != '/') { is.setstate(std::ios::failbit); return is; }

// Make sure that we didn't read p/0. if (q == 0) { is.setstate(std::ios::failbit); return is; }

r = Rational(p, q); return is; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions