Write a fraction class whose objects will represent fractions. You should provid
ID: 3539771 • Letter: W
Question
Write a fraction class whose objects will represent fractions. You should provide the following member functions:
Two constructors, a default constructor which assigns the value 0 to the fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the fraction, and the second parameter will represent the initial denominator of the fraction.
Arithmetic operations that add, subtract, multiply, and divide fractions. These should be implemented as value returning functions that return a fraction object. They should be named AddedTo, Subtract, MultipliedBy, and DividedBy.
A boolean operation named isEqualTo that compares two fraction objects for equality.
An output operation named print that displays the value of a fraction object on the screen in the form numerator/denominator.
Your class should have exactly two data members, one to represent the numerator of the fraction being represented, and one to represent the denominator of the fraction being represented.
When adding or subtracting fractions, remember that you must first find the common denominator. The easy way to do this is to multiply the denominators together and use that product as the common denominator.
You must create your own algorithm for reducing fractions. Don't look up an already existing algorithm for reducing fractions or finding GCF. The point here is to have you practice solving the problem on your own. In particular, don't use Euclid's algorithm. Don't worry too much about efficiency, just create something of your own that works correctly on ANY fraction.
HAVE TO USE THIS:
Here is the client program.
This client should produce the output shown here:
Explanation / Answer
Hi just now saw your question... Will give you .cpp part shortly if no one has given answer earlier.. that's the .h part of class
#ifndef FRACTION_H
class Fraction
{
private:
int numberator;
int denominator;
public:
Fraction():numberator(0), denominator(0)
{
}
Fraction(int numberator1 , int denominator1)
{
numberator = numberator1;
denominator = denominator1;
}
Fraction AddedTo(Fraction &f1);
Fraction Subtract(Fraction &f1);
Fraction MultipliedBy(Fraction &f1);
Fraction DividedBy(Fraction &f1);
bool isEqualTo (Fraction &f1 , Fraction &f2);
void print();
};
#define FRACTION_H
#endif // FRACTION_H
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.