Question
dev c+

Write the function called simplicity, which makes the denominator and denominator values of the simple fraction sent to it as
Write the function called simplicity, which makes the denominator and denominator values of the simple fraction sent to it as
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <iostream>
#include <iomanip>
#include <string>


using namespace std;

int simplicity(int &numerator,int &denominator);
int main()
{
int numerator,denominator;
  
   cout<<"Enter numerator and denominator :";
   cin>>numerator>>denominator;
  
   cout<<"---------------------------------"<<endl;
   cout<<"Prevoius value :"<<numerator<<"/"<<denominator<<endl;
   int res=simplicity(numerator,denominator);
if(res==1)
{
   cout<<"Simplified :"<<numerator<<"/"<<denominator<<endl;
   }
   else
   {
       cout<<"Fraction :"<<numerator<<"/"<<denominator<<endl;
   }

   return 0;
}
int simplicity(int &numerator,int &denominator)
{
   int a,b,gcd;
   a=numerator;
   b=denominator;
  
   int divi = (a > b ? a : b);
int div = (a < b ? a : b);
int rem = divi % div;
while (rem != 0)
{
divi = div;
div = rem;
rem = divi % div;
}
  
gcd=div;
//Dividing the Fraction class Numerator and Denominator with GCD to reduce to lowest terms
if (gcd != 0) {
numerator /= gcd;
denominator /= gcd;
return 1;
}
return 0;

  

}

===========================================

Output:

============================Thank You

Add a comment
Know the answer?
Add Answer to:
dev c+ Write the function called simplicity, which makes the denominator and denominator values of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ 1) Write a function that receives the numerator and denominator of a fraction and...

    Using C++ 1) Write a function that receives the numerator and denominator of a fraction and returns its corresponding value as a double precision real number. The function also receives the number of digits that the value must be rounded to before returned. To test it, you must implement the algorithm provided below. Note: You must define the most appropriate type of function, the parameter list (using the most appropriate parameters), and the body of the function to be implemented....

  • C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use...

    C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use functions. Use a custom library and namespace. Use reference variables as parameters to return values from functions. Create a robust user interface with input error checking. Use exceptions to indicate errors. Resources kishio.h kishio.cpp Assignment requirements You will need eight methods (including main). One is given to you. Their requirements are specified below: menu: The menu function takes no arguments, but returns a char...

  • C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers...

    C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers using Euclid’s algorithm (also known as the Euclidean algorithm). Write a main () function that requests two integers from the user, calls your function to compute the GCD, and outputs the return value of the function (all user input and output should be done in main ()). In particular, you will find this pseudocode for calculating the GCD, which should be useful to you:...

  • Must write in Java - ignore the Junit tests Write a program that works with fractions....

    Must write in Java - ignore the Junit tests Write a program that works with fractions. You are first to implement three methods, each to perform a different calculation on a pair of fractions: subtract, multiply, and divide. For each of these methods, you are supplied two fractions as arguments, each a two-element array (the numerator is at index 0, the denominator is at index 1), and you are to return a resulting, simplified fraction as a new two-element array...

  • Write a template for a function called total. The function should keep running total of values...

    Write a template for a function called total. The function should keep running total of values entered by the user, then return the total. The argument sent into the function should be the number of values the function is to read. Test the template in a simple driver program that sends values of various types as arguments and displays the results. How many integer values do you wish to total? Enter a value: 5 1 Enter a value: 2 Enter...

  • C++ 29.5 Lab 29: Pointers Exercise: Before the main function, declare a struct called Movie which...

    C++ 29.5 Lab 29: Pointers Exercise: Before the main function, declare a struct called Movie which has title as a string and year as the integer as the member variables. Also before the main function, instantiate an object of Movie called m with initial value "Avengers" as title and year as 2019. Note m is the global variable and A in the title is uppercase. Also before the main function, declare another global variable which is a pointer to the...

  • (Rational class) Create a class called Rational for performing arithmetic with fractions. Write a program to...

    (Rational class) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integers variables to represent the private data of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case are no initializers are provided and should store the fraction in reduced form. For example, the fraction 3/6 would be...

  • Need help with Java for Fraction exercise

    Add another public method called add to your Fraction class. This method adds another fraction to the ‘calling object’. Thus, the method will take a Fraction class object as a parameter, add this parameter fraction to the calling object (fraction), and return a Fraction object as a result. HINT: We can use cross multiplication to determine the numerator of the resultant Fraction. The denominator of the resultant Fraction is simply the multiplication of the denominators of the two other Fractions.Add...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • using c++ Write a C++ program which reads three values of types char, int, double and...

    using c++ Write a C++ program which reads three values of types char, int, double and string from the keyboard and primis, appropriately formatted, assigned values and variable types. For example, if letter, number, and real are variables of type char, int and double respectively, and if the values assigned to them using cin function are: a, 1, and 3.1415, then the output should be: a is a character 1 is an integen 3.1415 is a real number

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT