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++

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education