Math 3300 programming assignment create a class named


1. Create a class named fraction which will represent a new data type corresponding to fractions. Your class should create the following private members:

- Integers n and d corresponding to the numerator and denominator of the fraction

- A function gcd which returns the greatest common divisor of 2 integers (to help you reduce the fraction).

And the following public member functions:

- 3 constructors which will create any fraction when declared with 2 integers, will create a/1 when declared with 1 integer, and will create 0/1 when declared with no integers.

- num which returns the numerator of the fraction

- denom which returns the denominator of the fraction

- reduce which reduces the fraction to its lowest terms (using the gcd function above). This function changes the value of n and d appropriately.

- convert which returns a double representing the fraction (i.e. ¾ becomes 0.75)

You are to overload the following operators: +, -, ∗, /, + =, - =, ∗ =, / =, <, <=, >, >=, ==, ! = for use with fractions. For the operators +, -, ∗, /, + =, - =, ∗ =, / =, calculate the new fraction in lowest terms (like 3/4 instead of 6/8). Overload + and - for both unary and binary operations.

Also overload << and >> to accept and display fractions in the form a/b. A fraction like a/1 should be displayed as a. You can assume that a fraction will always be input in the form a/b.

Solution Preview :

Prepared by a verified Expert
Programming Languages: Math 3300 programming assignment create a class named
Reference No:- TGS01417631

Now Priced at $15 (50% Discount)

Recommended (99%)

Rated (4.3/5)