Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 5: Reducing a fraction Write a program that can be used to express a fraction in its lowest form. Functions In order to complete

Task 5: Reducing a fraction 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 de- fault 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 num- bers. 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 5 the fraction to its lowest form. For example, the result of reducing 20 4 is 1 . When passing 0 or a negative value as any one of these parameters, the function should return false, otherwise it should return true. Create a header file called reduce.h that contains the definition of the functions and an im- plementation file called reduce.cpp that contains the implementation of the functions de- scribed above. Create a tarball containing only reduce.h. Upload this tarball using the upload slot called Prac 4 - Fraction header. You are given a makefile to compile and run a test program as well as the production pro- gram. The given test program is called test.cpp. Give the following command to use the test program to interactively test the implementation of your functions. make test

Main program Write a program called fractions.cpp that uses the above functions. The program should prompt the user for a numerator and denominator. When given valid input, it should dis- play 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. 9The 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 5 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 with a phrase containing division by zero instead of displaying the GCD and then exit. When negative values are entered, the program should deal with it as follows: To display the GCD, display the absolute values (positive equivalents) and their GCD. To display the given fraction, display negative values as given. To display the fraction in its lowest format, display the negative in the numerator if the fraction is negative and without signs when it is positive. Recall that a negative divided by a negative is positive. To display the fraction in decimal format, display it with a negative sign if the fraction is negative and without a sign when it is positive. Give the following command to verify that your program compiles and run as required when using the given makefile for compiling and running the production program. make run

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago