by Dinesh Thakur Category: Classes in C++

 

#include<iostream.h>

#include<conio.h>
class time
{
      private:
                       int h,m;
      public:
                      void readt();
                      void addt(time,time);
                      void showt();
 };
                      void time::readt()
                {
                       cout<<"\nEnter Time in Hours and Minutes : ";
                       cin>>h>>m;
                }
                      void time::addt(time u1 ,time u2)
             {
                       int min=u1.m+u2.m;
                       int hrs=min/60;
                       m=min%60;
                       h=hrs+u1.h+u2.h;
             }
                       void time::showt()
            {
                       cout<<"\nTime obtained on adding = ";
                       cout<<h<<":"<<m;
             }
                      void main()
              {
                       clrscr();
                       time ob1 ,ob2,ob3;
                       ob1.readt();
                       ob2.readt();
                       ob3.addt(ob1,ob2);
                       ob3.showt();
                       getch();
               }

Passing Of Objects By Its Value



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