Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I will upvote for a good implementation Using a C++ language I need a program that takes a numerator and a denominator as a user

I will upvote for a good implementation

Using a C++ language I need a program that takes a numerator and a denominator as a user input and reduces the fraction to its lowest terms. You need to do error handling for the input, which means that it should not accept float number or any char inputs, however it can accept negative whole numbers. Denominator cannot be zero and if there is any "bad" input program should reprompt a user. At the very end a program should ask a user if they want to do another conversion. The very important thing is that you need to get all user inputs as strings:

Consider using

if (cin.fail()) {

cin.ignore(256, );

cin.clear();

}

Finally, there are 2 functions that are required to use:

1) bool to_lowest_terms(int &numerator, int &denominator); This function returns false if denominator is 0, true in any other cases and at the same time reduces both numerator and denominator to lowest terms inside the function. // Idk why, but we have to use pass by reference here

2) int GCD(int num1, int num2); - This function finds the greatest common divisor (gcd) for the numerator and denominator. Please note that this must be a recursive function (calling itself)

You also can create as many other functions as you want, however the functions should not be longer than 15 lines (including main() ). Please make sure to use pass by reference, not pass by value. Many thanks in advance. Here is an example run:

Please enter your numerator: hello123

Invalid input, enter your input once again:

Please enter your numerator: 1.1

Invalid input, enter your input once again:

Please enter your numerator: 10

Please enter your denominator: -20

The lowest terms of your fraction is -1/2

Do you want to run a program again (0-no, 1-yes) ?

0

//program ends

Please do not use libraries i.e. , but use only , , , .

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

4. How can speakers manage speaking anxiety?

Answered: 1 week ago