Rational numbers (1) P85696


Statement
 

pdf   zip   main.cc

thehtml

Using the definition

struct Rational { int num, den; };

write a function

Rational rational(int n, int d);

that returns an equivalent rational to n/d and “normalized” according to: if the numerator is 0, the denominator is 1; otherwise, the numerator and the denominator do not have any common factor, and the denominator is positive.

Precondition

d ≠ 0.

Observation You only need to submit the required classes; your main program will be ignored. Strictly obey the type definitions of the statement.

Information
Author
Salvador Roura
Language
English
Translator
Carlos Molina
Original language
Catalan
Other languages
Catalan
Official solutions
C++
User solutions
C++