PLEASE I need a Quick HELP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adoobi05
    New Member
    • Mar 2007
    • 5

    PLEASE I need a Quick HELP

    Hello ...

    Now , When I write this massege I feel with a huge disappointment becouse I waste 6 houers to konow what is the Problem with this code .

    The I didn't write the hole code , becouse every thing was Ok Until I want to OverLoad the + operation using friend function , the compiler give me this massege :

    INTERNAL COMPILER ERROR

    The binfit of the programe is to add Fraction using class and the overload all the artheamtic operations

    I need help please , becouse I have to complete it befoe Saturday and I have also MATH MAJOR

    ---------------------------------------------
    This is .h file :

    #include <iostream>
    using namespace std ;

    class Fraction
    {
    private :
    double numerator ;
    double denominator ;

    public :

    friend Fraction operator +(Fraction &a , Fraction &b ) ;

    Fraction () ;
    Fraction ( double x , double y ) ;

    bool zero () ;
    bool infinite () ;

    void print () ;
    void print_decimal () ;


    friend istream &operator>> ( istream &ins , Fraction &f )
    {
    cout << "Enter the Fraction " << endl;
    ins >> f.numerator ;
    ins >> f.denominator ;

    return ins ;
    }
    };

    -------------------------------------
    This is .cpp file :

    ///////// Fraction.cpp ///////
    ///////////////////////////////

    #include <iostream>
    #include <iomanip>
    #include "Fraction.h "
    using namespace std ;



    Fraction::Fract ion()
    {
    numerator = 1 ;
    denominator = 1 ;
    }

    Fraction::Fract ion ( double x , double y )
    {
    numerator = x ;
    denominator = y ;
    }

    bool Fraction::zero( )
    {
    if ( numerator == 0 )
    return 0 ;
    else
    return ( false ) ;
    }

    bool Fraction::infin ite ()
    {
    if ( denominator == 0 )
    return ( true ) ;
    else
    return ( false ) ;
    }

    void Fraction:rint ()
    {
    if ( infinite () == true )
    cout << " oo " << endl;
    else
    cout << "Fraction as fraction " << setw(5) << "==" << setw(5) << numerator << "/" << denominator << endl;

    }

    void Fraction:rint_d ecimal ()
    {
    cout << "Fraction as dicimal " << setw(5) << "==" << setw(5) << numerator / denominator << endl;
    }

    Fraction operator+(const Fraction &a , const Fraction &b)
    {
    Fraction tempC;
    tempC.numerator =a.numerator +b.numerator;
    tempC.denomerat or=a.denomerato r+b.denomerator ;
    return tempC;
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////
    //I tryed to Overload >> by this way , But it was filled !!!!!
    ///////////////////////////////////////////////////////////////
    //Fraction Fraction:perato r >>(istream &ins )
    ///{
    // Fraction f ;
    ///
    // cout << "Enter Fraction " << endl;
    // ins >> f.numerator ;
    // ins >> f.denominator ;
    //
    // return f ;
    //}
  • Roonie
    New Member
    • Mar 2007
    • 99

    #2
    ok, first, if youre going to ask us for help, do NOT start by saying what a disappointment it is that it will take so long.

    (i dont know about others, but i personally will require an apology before helping you.)

    Comment

    • adoobi05
      New Member
      • Mar 2007
      • 5

      #3
      Originally posted by Roonie
      ok, first, if youre going to ask us for help, do NOT start by saying what a disappointment it is that it will take so long.

      (i dont know about others, but i personally will require an apology before helping you.)
      Ok ... I'm sorry ...

      now please give me what you have ..

      Thanks

      Comment

      • Roonie
        New Member
        • Mar 2007
        • 99

        #4
        i am trying very hard to understand
        Originally posted by adoobi05
        now please give me what you have ..
        as a very PATIENT now-please-give-me-what-you-have . . .

        . . .

        anyways, you have this:
        Code:
        tempC.denomerator=a.denomerator+b.denomerator;
        when you declare both numerator and denomiator as private members . . . meaning that you need to use a function to access them instead of the dot operator. (and check your typos.)

        also, if you are overloading the + operator, you should only give one parameter to the overload function. when you use the overloaded function, you are using the + of one fraction, so you have one fraction already and thus you only need to (can) specify one other fraction to add with.

        you also need to check your algebra:
        (a/b)+(c/d) does not equal ((a+c)/(b+d)).

        check:

        Comment

        • Roonie
          New Member
          • Mar 2007
          • 99

          #5
          Originally posted by Roonie
          you declare both numerator and denomiator as private members . . . meaning that you need to use a function to access them instead of the dot operator.
          (maybe the friend operator changes this, im not sure, ive not used it much personally. but i would fix up your overload + function before trying to determine the exact effects of this keyword on that function.)

          Comment

          • Roonie
            New Member
            • Mar 2007
            • 99

            #6
            well, it looks like its my turn to apologize . . .

            i guess that using friend with an operator over load allows both operands to be passed as parameters . . .

            . . . i think im slightly outdated.:(

            but you still do have typos in your code. (denomerator != denominator)

            Comment

            • adoobi05
              New Member
              • Mar 2007
              • 5

              #7
              Originally posted by Roonie
              i am trying very hard to understand

              as a very PATIENT now-please-give-me-what-you-have . . .

              . . .

              anyways, you have this:
              Code:
              tempC.denomerator=a.denomerator+b.denomerator;
              when you declare both numerator and denomiator as private members . . . meaning that you need to use a function to access them instead of the dot operator. (and check your typos.)

              also, if you are overloading the + operator, you should only give one parameter to the overload function. when you use the overloaded function, you are using the + of one fraction, so you have one fraction already and thus you only need to (can) specify one other fraction to add with.

              you also need to check your algebra:
              (a/b)+(c/d) does not equal ((a+c)/(b+d)).

              check:
              http://www.devarticles.com/c/a/Cplus...ing-in-C-plus/
              First of all , thanks my new friend Roonie for your replying

              But the methode that you mentioned aboev is anothoer way to overload operations ..

              Yestaday after I post my problem here, I go througth internet and I looked for ( Internal Compiler Error ) .

              The resuld shoced me ... The error was from Microsoft co. and they have an update for such errors .,

              Becouse the file was little bit big , I asked samoebody to download it
              and I will try again ...

              Thanks again ....

              ............... ............... ......GoodBye.. .............

              Comment

              Working...