by Dinesh Thakur Category: Array Pointer and Union

 

#include<iostream.h>

#include<conio.h>
class rational
{
       private:
       int n,d;
       public:
              void set(int a,int a1)
           {
                n=a;
               d=a1;
           }
             void put() const
          {
               cout<<"Sum:";
               cout<<n<<"/"<<d;
          }
             void add(rational u1, rational u2)
         {
             n=u1.n*u2.d+u2.n*u1.d;
             d=u1.d*u2.d;
        }
};
           void main()
       {
              clrscr();
              rational obj1 ,obj2,obj3;
              obj1.set(15,5);
              obj2.set(3,5);
              obj3.add(obj1,obj2);
              obj3.put();
              getch();
       }
Output :
Sum:90/25


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles