WRITE A PROGRAM IN JAVA OR C++ Define a class called Fraction. This class is use
ID: 3619229 • Letter: W
Question
WRITE A PROGRAM IN JAVA OR C++Define a class called Fraction. This class is used torepresent a ration of two integers. Please define at least the following methods: 1. a mutator function for user to set the numerator. 2. a mutator function for user to set the denominator. 3. a function to calculate the value of the fraction(numerator / denominator ) and return it as type of double. 4. a function to output the value of the fraction reduced tolowest 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 anddenominator, then dividing both by that number WRITE A PROGRAM IN JAVA OR C++
Define a class called Fraction. This class is used torepresent a ration of two integers. Please define at least the following methods: 1. a mutator function for user to set the numerator. 2. a mutator function for user to set the denominator. 3. a function to calculate the value of the fraction(numerator / denominator ) and return it as type of double. 4. a function to output the value of the fraction reduced tolowest 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 anddenominator, then dividing both by that number
Explanation / Answer
please rate - thanks #include using namespace std; class Fraction {public: Fraction(); int Fraction::getnum(); int Fraction::getden(); void Fraction::setnum(); void Fraction::setden(); double Fraction::getvalue(); int Fraction:: gcd(); void Fraction::reduce(); private: int num,den; }; Fraction::Fraction() {num=0; den=0; } double Fraction::getvalue() {return (double)num/den; } int Fraction::getnum() {return num; } int Fraction::getden() {return den; } void Fraction::setnum() {coutnum; } void Fraction::setden() {coutden; while(den==0) {coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.