I need some help on the void plusEquals/minusEquals and etc function
I'm not sure how to start it
Please can anyone help me do the plusEquals function so I know what I'm suppose to do or maybe some guides on how to approach it
Below the problem is my current progress code on the problem
Thank You!!
The Problem:
Write a class definition for a fraction class. Each variable of type fraction represents a single fraction. The class has two member variables that should be private: the numerator and the denominator of the fraction. The class has the following public member functions:
1. void plusEquals(fraction second); // adds second to the member fraction and stores the result in the member fraction
2. void minusEquals(fraction second); // substracts second from the member fraction and stores the result in the member fraction
3. void timesEquals(fraction second); // multiplies second and the member fraction and stores the result in the member fraction
4. void dividesEquals(fraction second); // divides the member fraction by second and stores the result in the member fraction
5. double toDecimal(); // returns the decimal value of the member fraction
6. void input(); // read a fraction of the form x/y from the user
7. void output(); // print the fraction in the form x/y to the screen
8. fraction(); // constructor that defines a default fraction of 0/1
9. fraction(int n, int d); // constructor that defines a fraction n/d
The class should also define one private member function:
1. void reduce(); // reduce the member fraction to simplest terms, which should be done automatically any time that the value of the member fraction changes
Note that the reduce function should use Euclid’s method (as we did in Lab 7) to find the greatest common divisor of the numerator and denominator. You may do that directly in the reduce function, or you may add another private member function to the class just to calculate the GCD. You will also have to write a driver program to test the fraction class. Be sure that you test all the member functions for correctness.
#include <iostream>
using namespace std;
class fraction
{
public:
void plus_equals()
{
}
void minus_equals()
{
}
void times_equals()
{
}
void divide_equals()
{
}
double to_decimal()
{
}
void input()
{
cin >> numerator >> denominator;
}
void output()
{
cout << numerator << "/" << denominator << endl;
}
private:
void reduce()
{
}
int numerator;
int denominator;
};
int main()
{
fraction a, b;
cout << "Enter a fraction: ";
a.input();
a.output();
cout << "Enter a fraction: ";
b.input();
b.output();
return 0;
}