Purchase Solution

Define a class called fraction, embed class in a test program.

Not what you're looking for?

Ask Custom Question

Define a class called Fraction, used to represent a ratio of two integers.
1. Include mutator functions that allow the user to set the numerator and the denominator.
2. Also include a METHOD that displays the fraction on the screen as a ratio (e.g., 5/9). This method does not need to reduce the fraction to lowest terms.
3. Include an additional METHOD, "equals", that takes as input another Fraction and returns true if the two fractions are identical and false if they are not. This method should treat the fractions reduced to lowest terms; that is, if one fraction is 20/60 and the other is 1/3, then the method should return true.
4. Embed the class in a TEST PROGRAM that allows a user to create a fraction.

NOTES:
1. The objective is to compare before "dividing" to avoid any loss in resolution. Accordingly, just need to unify either the denominators or the numerators of both fractions. Do not have to "reduce" the fractions. Do "unification" WITHOUT using loops, for example:
a). n1/n2 and m1/m2 can be unified to: (n1*m2)/(n2*m2) and (m1*n2)/(m2*n2), then just compare the numerators.
b). Alternatively, unify the numerators as: (n1*m1)/(n2*m1) and (m1*n1)/(m2*n1), then just compare the denominators.
2. Embed class in a test program. Test the code with some hard-coded values. Use good descriptive comments throughout.

I have made several attempts at the solution, my logic is lame and so is my code. I have stripped down (see file). Need some assistance with unification part and completion to review and study working solution.

Thank you for your assistance,

J.R.

Purchase this Solution

Solution Summary

The expert defines a class called fraction which is embed class in a test program.

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.