Rational numbers (3)

Using the same definition of the rational numbers as in problem P85696, write the functions

    Rational sum(const Rational& a, const Rational& b);
    Rational substraction(const Rational& a, const Rational& b);
    Rational product(const Rational& a, const Rational& b);
    Rational division(const Rational& a, const Rational& b);

that returns respectively the sum, the substraction, the product and the division of two rational numbers given, “normalized” according to the same convention that in the exercise RACI1.

Write also the procedure

    void adds_one(Rational& r);

that adds an unit to the rational number @r@.

Precondition

The rational numbers @a@ and @b@ are correct and normalized. In the case of division, @b@ 0\neq 0.

Observation

You only need to submit the required classes; your main program will be ignored.

Strictly obey the type definitions of the statement.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:14:20.482Z

© Jutge.org, 2006–2026.
https://jutge.org