Write a program to sum a sequence of pairs of fractions. To practice top-down design, the program should be the result of completing the lines of code outlined below.
....
struct Rational {
int num; // numerator
int den; // denominator
};
//pre: ....
//post: ....
int gcd_euclides(...)
//pre:---
//post: returns r in simplified form
Rational simplify(Rational r)
//....
void write_rational(Rational r) {
if (r.num == 0) cout << "0";
else if (r.den == 1) cout << r.num;
else cout << r.num << "/" << r.den;
}
....
....
....
int main() {
Rational rat1, rat2, total={0,1};
while (read_pair_rationals(....)) {
Rational sum = sum_and_simp(....);
write_sum(....);
...
}
write_result(total);
}
Input consists of sequence of lines. Each line contains four integers representing fractions and . It holds and
Summation of the pairs of fractions (one per line) and the final sum of all of them at the end. The result fractions need to be simplified: numerator and denominator have no common factors, and the denominator is positive. If a fraction is you should write only . If the fraction is you should write only . Follow the format of examples below.
Author: Lluís Marquez
Generation: 2026-09-09T10:07:56.908Z
© Jutge.org, 2006–2026.
https://jutge.org