Sunday, January 23, 2011

CS201_____4 inro to programming

#include<iostream.h>
class Price
{
      private:
              int rupees;
              int paisa;
      public:
             Price()
             {
                    rupees=0;
                    paisa=0;
             };
             Price operator +(Price& p)
             {
                   Price e;
                   int t1,t2,t3=0;
                  t1=paisa+p.paisa;
                  if(t1>=100)
                       {
                            t2=t1/100;
                            t3=t1%100;
                            e.paisa=t3;
                            e.rupees=p.rupees+t2+rupees;
                       }
                       else if(t1<100)
                       {
                       e.paisa=t1;
                       e.rupees=p.rupees+rupees;
                       }
                      
                      
                       return e;
             };
             Price(int pr,int pa)
             {
                       int tmp=0;
                       int tmp2;
                       if(pa<100)
                       {
                                 paisa=pa;
                       }
                       else if(pa>=100)
                       {
                            tmp=pa/100;
                            tmp2=pa%100;
                            paisa=tmp2;
                       }
                       rupees=pr+tmp;
             };
             void print()
             {
                  cout<<"Price is "<<rupees<<" rupees and "<<paisa<<" paisas"<<endl;
                
             };
};

main()
{
      Price l(10,60),m(12,80);
      l.print();
      m.print();
      cout<<"After Addition "<<endl;
      Price a = l + m;
      a.print();
      cout<<"\n\n\n\n\n"<<endl;
      system("pause");
     
}

No comments:

Post a Comment