PROGRAMMING:Overload of fractional addition
I believe students are quite familiar with the overloading of complex operators. Today, let's see how to deal with fractions? We define a fractional class FS, which has a private member molecule FZ and a denominator FM. In addition, the public member function FS operator + (const FS & F) overloads the operator "+" to add two fractions. First of all, we give an integer number n, followed by 2n lines of input, such as 3z4m, which means that the numerator is 3 and the denominator is 4. Where the denominator is not 0, the input denominator can be negative, but the output denominator must be positive.
It is required to sum the scores and simplify them( Note: when the score is 0, it is expressed as 0z1m. If the result is negative, the numerator is negative and the denominator is positive.)
Examples are as follows:
Input:
three
4z9m
2z9m
4z5m
5z4m
2z-5m
1z-5m
Output:
2z3m
41z20m
-3z5m
answer:If there is no answer, please comment
It is required to sum the scores and simplify them( Note: when the score is 0, it is expressed as 0z1m. If the result is negative, the numerator is negative and the denominator is positive.)
Examples are as follows:
Input:
three
4z9m
2z9m
4z5m
5z4m
2z-5m
1z-5m
Output:
2z3m
41z20m
-3z5m
answer:If there is no answer, please comment