Home › Forums › C Programming › Object Oriented Programming Question
- This topic has 1 reply, 2 voices, and was last updated 19 years, 9 months ago by msaqib.
Viewing 1 reply thread
- AuthorPosts
- February 28, 2005 at 11:00 am #1896graceParticipant
Dear everybody…i have a problem in a program that I’m working on and it keeps giving me the same error every time I compile it…
the error is the following:
missing function header (old-style formal list?) the program is:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122#include<iostream><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 /><br />rational :: rational(int n, int d)<br />{<br />int numerstor=n;<br />int denominator =d;<br />}<br />rational rational ::addition (const rational &s)<br />{<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 />{<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 />void rational::printrationald();<br />{<br />cout<<numerator'/'<<denomirator;<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 />}<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 />}</iostream> - April 1, 2005 at 11:14 am #3142msaqibParticipant
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.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118#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 />
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.