Ok just take a break and take a chill pill too u r in great need of it
Ok just take a break and take a chill pill too u r in great need of it
i m almost done with it,, how to simplify the rational numbers??Code:#include<iostream.h> #include<conio.h> class rational { private: int num; int denom; int normalize(); public: rational() { num=0; denom=1; } rational( int n ) { num=n; denom=1; } rational (int numerator, int denominator) { num=numerator; denom=denominator; } void input() { cin>>num>>denom; } rational operator + (rational& right) { rational result; result.num = (num* right.denom + right.num* denom); result.denom = denom*right.denom; return result; } rational operator - (rational& right) { rational result; result.num = (num*right.denom-right.num*denom); result.denom = denom*right.denom; return result; } rational operator * (rational& right) { rational result; result.num =num*right.num; result.denom =denom*right.denom; return result; } rational operator / (rational& right) { rational result; result.num = num*right.denom; result.denom = denom*right.num; return result; } void display() { cout<<num<<"/"<<denom<<endl; } }; int main() { clrscr(); rational x,e,f,g,h; rational a(3); rational b(3, 4); rational c(2, 4); x.input(); x.display(); e=b + x; e.display(); f=b - x; f.display(); g=b * x; g.display(); h=b/x; h.display(); getch(); return 0; }
the code i used in the first post,, the same way i add it to private??
Can anybuddy tell me my mistakeCode:#include<iostream.h> #include<conio.h> class rational { private: int num; int denom; int normalize(); public: rational() { num=0; denom=1; } rational( int n ) { num=n; denom=1; } rational (int numerator, int denominator) { num=numerator; denom=denominator; } void input() { cin>>num>>denom; } rational operator + (rational& right) { rational result; result.num = (num* right.denom + right.num* denom); result.denom = denom*right.denom; result.normalize(); return result; } rational operator - (rational& right) { rational result; result.num = (num*right.denom-right.num*denom); result.denom = denom*right.denom; return result; } rational operator * (rational& right) { rational result; result.num =num*right.num; result.denom =denom*right.denom; return result; } rational operator / (rational& right) { rational result; result.num = num*right.denom; result.denom = denom*right.num; return result; } void display() { cout<<num<<"/"<<denom<<endl; } }; int gcd(int n, int m); int main() { clrscr(); void rational::normalize() { int d, sign; sign = 1; if (top < 0) { sign = -1; top = -top; } d = gcd(top, bottom); top = sign*(top / d); bottom = bottom / d; } rational x,e,f,g,h; rational a(3); rational b(3, 4); rational c(2, 4); x.input(); x.display(); e=b + x; e.display(); f=b - x; f.display(); g=b * x; g.display(); h=b/x; h.display(); getch(); return 0; } unsigned int gcd(unsigned int n, unsigned int m) { if (n == 0) return m; if (m == 0) return n; while (m != n) { if (n > m) n = n - m; else m = m - n; } return n; }
What does the compiler say is wrong with your program?
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
ohk i have done it,,
how to print a constructor??
Funny thing is, his code for that actually is correct. Yours is simply unoptimal and can be simplified to what he has! Now just who should be helping who?
You should not use variable names with double-leading-underscores. I can't quite remember exactly what names are reserved for the compiler, but you're either using them or close.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"