Appendix A. Rational and Complex Numbers

This Appendix defines the Rational and Complex classes from the Converters section in the previous chapter.

Rational numbers

A rational number can be expressed as a fraction of two integers, called the numerator and denominator.

Rational.h

namespace SmallWindows { 
  class NotaRationalNumber : public exception { 
    public: 
      NotaRationalNumber() {/* Empty. */} 
  }; 

The default constructor initializes the numerator and denominator to 0 and 1, respectively. The second constructor takes a string and throws a NotaRationalNumber exception if the string does not hold a valid rational number. The copy constructor and the assignment operator take another rational number. The String conversion operator returns the rational ...

Get C++ Windows Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.