Reference no: EM13166835
Define a class for a type called Fraction. This class is used to represent a ratio of two
integers. Include mutator functions that allow the user to set the numerator and the
denominator. Also include a member function that returns the value of numerator /
denominator as a double (precision set to 5). Include an additional member function
that outputs the value of the fraction reduced to lowest terms, e.g. instead of
outputting 20/60 the method should output 1/3. This will require finding the greatest
common divisor for the numerator and denominator, and then dividing both by that
number. Embed your class in a test C++ program. Example input/output is shown
below. (25 Points)
Input:
20 60
Output:
0.33333 1/3
4. Write a C++ program that would take two 3x3 matrix and outputs the results of
addition, subtraction, and multiplication. Create a class that can internally store two
3x3 matrices and has three member functions: one that performs addition, one that
performs subtraction, and one that performs multiplication. Use this class in your
program. Example input/output is shown below. (25 Points)
Input:
1 1 1
2 2 2
3 3 3
1 2 3
1 2 3
1 2 3
Output:
2 3 4
3 4 5
4 5 6
0 -1 -2
1 0 -1
2 1 0
3 6 9
6 12 18
9 18 27