14279 - Fraction Calculator   

Description

Your task is to create a basic fraction calculator that can handle both addition and multiplication of fractions.

Since you should perform multiplication operations before addition, in the provided code, you are advised to use a structure called "FractionList", which functions similarly to a linked list. When performing an addition, add the new fraction to the end of the list. For multiplication, simply multiply the new fraction with the last one already in the list.

This is a partial judge problem. You need to implement 11 class methods. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details.

Important: Please select C++17 to submit your solution.

 

Input

The input consists of multiple lines, where each line represents a test case.
Each test case contains a sequence of fractions and operations formatted as follows:

<fraction_1> +/* <fraction_2> +/* ... +/* <fraction_n> = ?  (1 < n ≤ 10)

Each fraction is written in the format <numerator>/<denominator>, where both numerator and denominator, as well as all numbers involved in calculations, fit within the range of a long long data type. The operations between fractions are either addition (+) or multiplication (*).

>>> Notice. Please note that the number of test cases in this problem is not specified. The program should continue reading input until no more input is available. When implementing the extraction operator (>>) for Fraction class, handle the situation where there is no input by simply returning the "istream".

Output

(This part is already implemented) For each test case, you should provide the result in two formats. First, output the result as a simplified fraction, where the fraction is reduced to its lowest terms. Second, present the result as a decimal number, cutting off the output after 20 decimal places without rounding up or down.

Special conditions for output formatting:

  • If the result is 0, output should be formatted as: 0/1 0.00000000000000000000
  • If the result is an integer (e.g., 3), output should be formatted as: 3/1 3.00000000000000000000

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

14279.cpp

Partial Judge Header

14279.h

Tags




Discuss