hi, i have everything working in this program expect when i made my fraction simplifying function, the multiplication of the two fractions all of a sudden do not appear.
Can you help??
Code:#include "Rational.h" #include "math.h" #include <iostream> using namespace std; Rational::Rational(int N, int D) //gets num and den { numerator = N; denominator = D; } int Rational::num() {return numerator;} int Rational::den() {return denominator;} int Rational::add(Rational f2) //adds the two fractions {int temp = num()*f2.den(); int temp2 = (den()*f2.num()); //num times by the den of the second and adds it to the den of the first times with the num of the second int fnum= temp+temp2; int fden = den()*f2.den(); //den of first times den of second Rational rational(fnum,fden); //gets final num and den cout <<"Added: "; simplify(rational); //simplifies the final num and den } int Rational::subtract(Rational f2) //subtracts the two fractions {int temp = num()*f2.den(); int temp2 =den()*f2.num(); //num times second den subtracted by the den of the first and the num of the second int fnum= temp+temp2; int fden = den()*f2.den(); //den of the first and den of the second Rational rational(fnum,fden); //gets final num and den cout<< "Subtracted: "; simplify(rational); //simplifies the final num and den } int Rational::times(Rational f2) //times the two fractions { int fnum =num()*f2.num(); //num of the first times the num of the second int fden =den()*f2.den(); //den of the first times den of the second Rational rational(fnum,fden); //gets the final num and den cout << "Timed: "; simplify(rational); //simplifies the final num and den } int Rational::divide(Rational f2) //divides the two fractions { int fnum =num()*f2.den(); //num times den of second int fden =den()*f2.num(); //den of first times num of second Rational rational(fnum,fden); //gets final num and den cout << "Divided: "; simplify(rational); //simplifies the final num and den } void Rational::simplify(Rational rational) { int num1=rational.num(); // takes the final num and den int num2=rational.den(); for(int x = 1; x <= num1; ++x){ //for loop, increments until the number is greater than the numerator of the fraction if(num1 % x == 0 && num2 % x == 0){ //checks if each number is divisible;) while((num1 % x == 0 && num2 % x == 0) && x != 1){ //Incase it isn't in lowest terms int fnum =(num1 /= x); //Does the dividing int fden= (num2 /= x); //This is for the denomenator Rational end (fnum,fden); show (end); //shows the final ans } } } } void Rational::show(Rational end) //shows the fractions { int fnum=end.num(); int fden=end.den(); cout <<"**"<<fnum<<"/"<<fden<<"**" <<endl; } bool Rational::compare(Rational f2) //compares the two fractions to see if they are equal { float initial=(float)num()/den(); float final= (float)f2.num()/f2.den(); if (initial==final) return true; else return false; }



LinkBack URL
About LinkBacks


