Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::istream& Rational::readFrom(std::istream& istrm) {
- char slash(0);
- int num(0), den(1);
- if (istrm.good()) {
- istrm >> num >> slash >> den;
- if (slash == '/') {
- if (den == 0) throw std::invalid_argument("Denominator cannot be equal to zero!");
- numerator = num;
- denominator = den;
- Simplify();
- }
- else {
- istrm.setstate(std::ios_base::failbit);
- }
- }
- return istrm;
- }
Advertisement
Add Comment
Please, Sign In to add comment