Home › Forums › C Programming › Object Oriented Programming Question › Reply To: Object Oriented Programming Question
April 1, 2005 at 11:14 am
#3142
msaqib
Participant
Hello, you have done the following things wrong:
in the function definition ; is not allowed void rational::printrationald() also you will need to correct the variable name denominator I hope now your problem will be solved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | #include<br /> using std::cout;<br /> using std::endl;<br /> class rational{<br /> public:<br /> rational (int=0, int=1);<br /> rational addition (const rational &);<br /> rational subtraction (const rational &);<br /> rational multiplication (const rational &);<br /> rational division (const rational &);<br /> void printrational();<br /> void printrationald();<br /> private:<br /> int numerator;<br /> int denominator;<br /> void reduction();<br /> };<br /> rational :: rational(int n, int d){<br /> int numerstor=n;<br /> int denominator =d;<br /> }<br /> rational rational ::addition (const rational &s){<br /> rational w;<br /> w.numerator= s.numerator*denominator;<br /> w.numerator+=s.denominator*numerator;<br /> w.denominator=s.denominator*denominator;<br /> w.reduction();<br /> return w;<br /> }<br /> rational rational:: subtraction(const rational &r){<br /> rational w;<br /> w.numerator= r.numerator*denominator;<br /> w.numerator-=r.denominator*numerator;<br /> w.denominator=r.denominator*denominator;<br /> w.reduction();<br /> return w;<br /> }<br /> rational rational ::multiplication (const rational &j)<br /> {<br /> rational w;<br /> w.numerator= j.numerator*denominator;<br /> w.denominator=j.denominator*denominator;<br /> w.reduction();<br /> return w;<br /> }<br /> rational rational ::division (const rational &k)<br /> {<br /> rational w;<br /> w.numerator= k.numerator*denominator;<br /> w.denominator=denominator*k.denominator;<br /> w.reduction();<br /> return w;<br /> }<br /> void rational::printrational()<br /> {<br /> cout<<numerator<<'t'<<denominator;<br /> }<br /> <strong>void rational::printrationald(); // you should write like that void rational::printrationald() without the ;</strong><br /> {<br /> <strong>cout<<numerator'/'<<denomirator; //spellings for denomirator are wrong you should write denominator</strong><br /> }<br /> void rational:: reduction()<br /> {<br /> int s;<br /> s=numerator<denominator?numerator:denominator;<br /> int x=0;<br /> for (int l=2; l<=s;++l)<br /> if (numerator % l == 0 && denominator % l)<br /> x= l;<br /> if (x!= 0)<br /> {<br /> int numinator = x;<br /> int denominator = x;<br /> }<br /> } int main()<br /> {<br /> rational a(1, 7), f(9,2), h;<br /> a.printrational();<br /> cout<<"+";<br /> f.printrational();<br /> h= a.addition(f);<br /> cout<<"=";<br /> h.printrational();<br /> cout<<'n';<br /> h.printrational();<br /> cout<<"=";<br /> h.printrationald();<br /> a.printrational();<br /> f.printrational();<br /> h=a.subtraction(f);<br /> cout<<"=";<br /> h.printrational();<br /> cout<<'n';<br /> h.printrational();<br /> cout<<"=";<br /> h.printrationald();<br /> a.printrational();<br /> cout<<"h";<br /> f.printrational();<br /> h=a.multiplication(f);<br /> cout<<"=";<br /> h.printrational();<br /> cout<<'n';<br /> h.printrational();<br /> cout<<'=';<br /> h.printrationald();<br /> a.printrational();<br /> f.printrational();<br /> h=a.division(f);<br /> cout<<"=";<br /> h.printrational();<br /> h.printrational();<br /> cout<<"=";<br /> h.printrationald();<br /> cout<<endl;<br /> return 0;<br /> }<br /> |