Write function is decompose. First you reduce the fraction. Then you return a Fraction that is one of three things: A) If we're an improper fraction (like 10/3), return a Fraction with the largest whole number in the fraction, in this case 3 (so you return {3,1}). B) If we're a proper fraction with a numerator of 1, return our values (i.e. return {num,den}) C) If we're a proper fraction with a numerator not 1, return the largest fraction with a numerator of 1 smaller than our value. (For example, if our numerator is 4 and denominator is 6, then we would return {1,2}, since 1/2 is the largest fraction with a numerator of 1 smaller than 4/6.)     void reduce() {         //YOU: Fix this code so it actually reduces the fraction         //NOTE: The std::gcd() function might be useful         // num /= 1;         // den /= 1;         for(int i = num * den; i > 1; i--)         {             if((den % i == 0) && (num % i) == 0)             {                 den /= i;                 num /= i;             }         }     }     Fraction decompose() {         reduce();         //Code continue solution fraction decompose     } C++

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

Write function is decompose. First you reduce the fraction.
Then you return a Fraction that is one of three things:
A) If we're an improper fraction (like 10/3), return a Fraction with the
largest whole number in the fraction, in this case 3 (so you return {3,1}).
B) If we're a proper fraction with a numerator of 1, return our values (i.e.
return {num,den})
C) If we're a proper fraction with a numerator not 1, return the largest
fraction with a numerator of 1 smaller than our value. (For example, if our
numerator is 4 and denominator is 6, then we would return {1,2}, since 1/2 is
the largest fraction with a numerator of 1 smaller than 4/6.)

    void reduce() {
        //YOU: Fix this code so it actually reduces the fraction
        //NOTE: The std::gcd() function might be useful
        // num /= 1;
        // den /= 1;
        for(int i = num * den; i > 1; i--)
        {
            if((den % i == 0) && (num % i) == 0)
            {
                den /= i;
                num /= i;
            }
        }
    }

    Fraction decompose() {
        reduce();
        //Code continue solution fraction decompose
    }

C++

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning