Rational Class help. Reduction funtion doesnt work. Linker error in Dev cpp.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rjddude1
    New Member
    • Aug 2009
    • 7

    Rational Class help. Reduction funtion doesnt work. Linker error in Dev cpp.

    I created a rational class, created member functions to add, subtract, multiply and divide. The reduction function however doesn't work. And the Dev cpp compiler gives a linker error. I have attached the header, implementation and the driver file in rational.zip
    Could you help me fix this code?
    What am I doing wrong?
    Attached Files
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Please post your linker errors.

    Comment

    • rjddude1
      New Member
      • Aug 2009
      • 7

      #3
      Linker error gone

      Originally posted by Banfa
      Please post your linker errors.
      Linker errors are gone however my reduction function does not work.
      How do I make it so that it stores the function in reduced form and reduces them before they are printed.

      Thank you in advance.

      Here's my function implementation file

      Code:
      #include "Rational.h"
      
      Rational::Rational()
      : is_valid_( false ), num ( 1 ), den ( 1 )
      {
      }
      
      Rational::Rational( const int init_num, const int init_den )
      : num( init_num ), den( init_den )
      {
          if ( den == 0 || (den == 0 && num == 0))
              is_valid_ = false;
          else
              is_valid_ = true;
      }
      
      bool Rational::is_valid() const
      {
          return is_valid_;
      }
      
      void Rational::check() const
      {
          if ( ! ( is_valid() ) )
      	{
      		cout << "Indeterminate form of rational." << endl;
      		system("pause");
              exit(1);
      	}
      }          
      
      int Rational::get_num() const
      {
         check();
         return num;
      }
      
      int Rational::get_den() const
      {
         check();
         return den;
      }
      
      void Rational::set_num( const int val1 )
      {
           num = val1;
      }
      
      void Rational::set_den( const int val2 )
      {
           den = val2;
      }
      
      void Rational::reduce ()
      {
           //Reduction function...
           //Help required
      }
      
      
      void Rational::printRational() const
      {
              cout << num << '/' << den;
      }
      
      void Rational:: printRationalAsFloating() const
      {
              cout << float(num)/den;
      }
               
      Rational Rational::addition ( const Rational &a )
      {
               Rational add;
               add.num = (a.num * den) + (num * a.den);
               add.den = (den * a.den);
               reduce();
               return add;
      }
      
      Rational Rational::subtraction ( const Rational &a )
      {
               Rational sub;
               sub.num = (num * a.den) - (den * a.num);
               sub.den = (den * a.den);
               reduce();
               return sub;
      }
      
      Rational Rational::multiplication ( const Rational &a )
      {
               Rational multi;
               multi.num = (num * a.num);
               multi.den = (den * a.den);
               reduce();
               return multi;
      }
      
      Rational Rational::division ( const Rational &a )
      {
               Rational div;
               div.num = (num * a.den);
               div.den = (den * a.num);
               reduce();
               return div;
      }

      Comment

      Working...