C++ Programming Blog

 
 
 
//Conversion CLASS TO BASIC
//TIME CONVERSION

#include <iostream.h>
#include <conio.h>

class time
{
 int hrs;
 int mins;
 public:
   time()
   {}
   void getdata()
   {
     cout<<\"Enter value for Hours  : \";
     cin>>hrs;
     cout<<\"Enter value for Minutes: \";
     cin>>mins;
   }
   void display()
   {
     cout<<\"\\n\\nHours   : \"<<hrs;
     cout<<\"\\nMinutes : \"<<mins;
   }
   operator int()
   {
     int t;
     t = hrs*60;
     t = t + mins;
     return t;
   }
};


void main()
{
  clrscr();
  time o1;
  o1.getdata();
  o1.display();

  int duration;
  duration=o1;

  cout<<\"\\nDuration : \"<<duration<<\"  minutes\";
  getch();
}

 
 
Didn't find what you were looking for? Find more on Program to illustrate operator overloading from class to basic type