Home Forums C Programming Object Oriented Programming Question

Viewing 1 reply thread
  • Author
    Posts
    • #1896
      grace
      Participant

      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:

      #include
      using std::cout;
      using std::endl;
      class rational{
                   public:
                                rational (int=0, int=1);
                                rational addition (const rational &);
                                rational subtraction (const rational &);
                                rational multiplication (const rational &);
                                rational division (const rational &);
                                void printrational();
                                void printrationald();
                   private:
                                int numerator;
                                int denominator;
                                void reduction();
      };

      rational :: rational(int n, int d)
      {
      int numerstor=n;
      int denominator =d;
      }
      rational rational ::addition (const rational &s)
      {
                   rational w;
                   w.numerator= s.numerator*denominator;
                   w.numerator+=s.denominator*numerator;
                   w.denominator=s.denominator*denominator;
                   w.reduction();
                   return w;
      }
      rational rational:: subtraction(const rational &r)
      {
                   rational w;
                   w.numerator= r.numerator*denominator;
                   w.numerator-=r.denominator*numerator;
                   w.denominator=r.denominator*denominator;
                   w.reduction();
                   return w;
      }
      rational rational ::multiplication (const rational &j)
      {
                   rational w;
                   w.numerator= j.numerator*denominator;
                   w.denominator=j.denominator*denominator;
                   w.reduction();
                   return w;
      }
      rational rational ::division (const rational &k)
      {
                   rational w;
                   w.numerator= k.numerator*denominator;
                   w.denominator=denominator*k.denominator;
                   w.reduction();
                   return w;
      }
      void rational::printrational()
      {
                   cout< }
      void rational::printrationald();
      {
                   cout< }
      void rational:: reduction()
      {
                   int s;
                   s=numerator              int x=0;
                   for (int l=2; l<=s;++l)
                                if (numerator % l == 0 && denominator % l)
                                             x= l;
                                if (x!= 0)
                                {
                                int         numinator = x;
                                int         denominator = x;
                                }
      }
      int main()
      {
      rational a(1, 7), f(9,2), h;
      a.printrational();
      cout<<"+";
      f.printrational();
      h= a.addition(f);
      cout<<"=";
      h.printrational();
      cout<<'n';
      h.printrational();
      cout<<"=";
      h.printrationald();
      a.printrational();
      f.printrational();
      h=a.subtraction(f);
      cout<<"=";
      h.printrational();
      cout<<'n';
      h.printrational();
      cout<<"=";
      h.printrationald();
      a.printrational();
      cout<<"h";
      f.printrational();
      h=a.multiplication(f);
      cout<<"=";
      h.printrational();
      cout<<'n';
      h.printrational();
      cout<<'=';
      h.printrationald();
      a.printrational();
      f.printrational();
      h=a.division(f);
      cout<<"=";
      h.printrational();
      h.printrational();
      cout<<"=";
      h.printrationald();
      cout< return 0;
      }

    • #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.

      #include
      using std::cout;
      using std::endl;
      class rational{
      public:
      rational (int=0, int=1);
      rational addition (const rational &);
      rational subtraction (const rational &);
      rational multiplication (const rational &);
      rational division (const rational &);
      void printrational();
      void printrationald();
      private:
      int numerator;
      int denominator;
      void reduction();
      };
      rational :: rational(int n, int d){
      int numerstor=n;
      int denominator =d;
      }
      rational rational ::addition (const rational &s){
      rational w;
      w.numerator= s.numerator*denominator;
      w.numerator+=s.denominator*numerator;
      w.denominator=s.denominator*denominator;
      w.reduction();
      return w;
      }
      rational rational:: subtraction(const rational &r){
      rational w;
      w.numerator= r.numerator*denominator;
      w.numerator-=r.denominator*numerator;
      w.denominator=r.denominator*denominator;
      w.reduction();
      return w;
      }
      rational rational ::multiplication (const rational &j)
      {
      rational w;
      w.numerator= j.numerator*denominator;
      w.denominator=j.denominator*denominator;
      w.reduction();
      return w;
      }
      rational rational ::division (const rational &k)
      {
      rational w;
      w.numerator= k.numerator*denominator;
      w.denominator=denominator*k.denominator;
      w.reduction();
      return w;
      }
      void rational::printrational()
      {
      cout<<numerator<<'t'<<denominator;
      }
      void rational::printrationald(); // you should write like that void rational::printrationald() without the ;
      {
      cout<<numerator'/'<<denomirator; //spellings for denomirator are wrong you should write denominator
      }
      void rational:: reduction()
      {
      int s;
      s=numerator<denominator?numerator:denominator;
      int x=0;
      for (int l=2; l<=s;++l)
      if (numerator % l == 0 && denominator % l)
      x= l;
      if (x!= 0)
      {
      int numinator = x;
      int denominator = x;
      }
      } int main()
      {
      rational a(1, 7), f(9,2), h;
      a.printrational();
      cout<<"+";
      f.printrational();
      h= a.addition(f);
      cout<<"=";
      h.printrational();
      cout<<'n';
      h.printrational();
      cout<<"=";
      h.printrationald();
      a.printrational();
      f.printrational();
      h=a.subtraction(f);
      cout<<"=";
      h.printrational();
      cout<<'n';
      h.printrational();
      cout<<"=";
      h.printrationald();
      a.printrational();
      cout<<"h";
      f.printrational();
      h=a.multiplication(f);
      cout<<"=";
      h.printrational();
      cout<<'n';
      h.printrational();
      cout<<'=';
      h.printrationald();
      a.printrational();
      f.printrational();
      h=a.division(f);
      cout<<"=";
      h.printrational();
      h.printrational();
      cout<<"=";
      h.printrationald();
      cout<<endl;
      return 0;
      }
Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.