+ 1

# C++

Write a program that can be used to express a fraction in its lowest form. Functions In order to complete this task, you are expected to complete the implementation of the three functions described below.  void displayFraction(int a, int b) Takes two integer numbers and display them in a fraction format such as a/b. Use default values for the parameters of this function so that if the function is called without parameters 0/1 is displayed and when called with one parameter (say x), then x/1 is displayed. Note that this function should simply display what it is given even if it is invalid.  int gcd(int a, int b) Takes two positive integers and returns the greatest common divisor of the two numbers. The greatest common divisor of any two numbers a and b is the largest positive integer c that is a divisor of both a and b. The number c is a divisor of b if the remainder after dividing b by c is zero. When passing 0 or a negative value as any one of these parameters, the function should return -1.  bool reduceFraction(int &num, int &denom) Takes two integers representing the numerator and denominator of a fraction. Reduces the fraction to its lowest form. For example, the result of reducing 20 4 is 5 1 . When passing 0 or a negative value as any one of these parameters, the function should return false, otherwise it should return true. Main program Write a program called References.cpp that uses the above functions. The program should prompt the user for a numerator and denominator. When given valid input, it should display the GCD of the two input values and then display the given fraction, the fraction in its lowest form as well as the fraction in decimal format. The following is a sample test run (user input is shown in bold): Fraction Reduction ------------------------------- Enter the numerator: 4 Enter the denominator: 20 The GCD of 4 and 20 is 4 The lowest form of 4/20 is 1/5 = 0.2 When the user enters 0 as the denominator the program should notify the user wi

8th Apr 2017, 1:46 PM
InsaneBeatmaker Sane