By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

PLEASE I need a Quick HELP

P: 5
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::Fraction()
{
numerator = 1 ;
denominator = 1 ;
}

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

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

bool Fraction::infinite ()
{
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_decimal ()
{
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.denomerator=a.denomerator+b.denomerator;
return tempC;
}

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

//////////////////////////////////////////////////////////////
//I tryed to Overload >> by this way , But it was filled !!!!!
///////////////////////////////////////////////////////////////
//Fraction Fraction:perator >>(istream &ins )
///{
// Fraction f ;
///
// cout << "Enter Fraction " << endl;
// ins >> f.numerator ;
// ins >> f.denominator ;
//
// return f ;
//}
Mar 22 '07 #1
Share this Question
Share on Google+
6 Replies


Roonie
P: 99
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.)
Mar 22 '07 #2

P: 5
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
Mar 23 '07 #3

Roonie
P: 99
i am trying very hard to understand
now please give me what you have ..
as a very PATIENT now-please-give-me-what-you-have . . .

. . .

anyways, you have this:
Expand|Select|Wrap|Line Numbers
  1. 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/
Mar 23 '07 #4

Roonie
P: 99
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.)
Mar 23 '07 #5

Roonie
P: 99
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 . . .
http://www.see.ed.ac.uk/~sasg/Comput.../Cpp/cpp6.html
. . . i think im slightly outdated.:(

but you still do have typos in your code. (denomerator != denominator)
Mar 23 '07 #6

P: 5
i am trying very hard to understand

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

. . .

anyways, you have this:
Expand|Select|Wrap|Line Numbers
  1. 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....... ........
Mar 23 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.