Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class definition for a fraction class. That is, define your own class th

ID: 3547760 • Letter: W

Question

Write a class definition for a fraction class. That is, define your own class that will represent a fraction in your program. Each variable of type fraction represents a single fraction. That means that the class has two member variables that should be private: the numerator and the denominator of the fraction. The class also must have the following public member functions:

fraction(); // constructor that defines a default fraction of 0/1

fraction(int n, int d);  // constructor that defines a fraction n/d

fraction plus(fraction second); // adds second to the member fraction and returns the result in a new fraction

fraction minus(fraction second); // subtracts second from the member fraction and returns the result in a new fraction

fraction times(fraction second); // multiplies second and the member fraction and returns the result in a new fraction

fraction divides(fraction second); // divides the member fraction by second and returns the result in a new fraction

double toDecimal(); // returns the decimal value of the member fraction

void input(); // read a fraction of the form x/y from the user

void output(); // print the fraction in the form x/y to the screen

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

Explanation / Answer

#include 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
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote