Feedjit

Articles for you

Tuesday, December 31, 2013

C++ Plus Plus Program Simple Operator Overloading in C++, Easy Implementation, Airtime in C++ , C Plus Plus Program

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#include<iostream.h>
#include<conio.h>
 
  class airtime
  
    {
        private:
                int hrs,min,sec;
                
        public:
                airtime() : hrs(0),min(0),sec(0){}
                void settime();        
                void display();
                airtime operator + (const airtime &a);
                void operator += (const airtime &a);
                int operator > (const airtime &a);
                void operator ++ ();
                void operator ++ (int);
                
                
                
   };
void airtime::settime()
     
     {
          cout<<"Enter hours min and sec "<<endl;
          cin>>hrs>>min>>sec;
          
             cout<<endl<<endl;
     } 
void airtime::display()
{cout<<hrs<<":"<<min<<":"<<sec<<"\n";
}                      
airtime airtime::operator + (const airtime &a)
{
                       airtime temp;
                       
                       temp.hrs=hrs + a.hrs;
                       temp.min=min + a.min;
                       temp.sec=sec + a.sec;
                       return temp;}                 
              
void airtime::operator += (const airtime &a)
{
                            
                            sec+= a.sec;
                            min+=a.min;   
                            hrs+=a.hrs;}             
int airtime::operator > (const airtime &t)
{ if(hrs>t.hrs)
             return 1;
  else if(min>t.min)
             return 1;
  else if(sec>t.sec)
           return 1;
else 
return 0;
}                     
void airtime::operator ++ ()
{                         
                      
                              ++hrs;
                              ++min;
                              ++sec;
}            
            
            
void airtime::operator ++ (int)
{
                              hrs++;
                              min++;
                              sec++; }
int main()
       
       {
           
            airtime a1,a2,a3,a4;
            int result;
            
              a1.settime();
              a2.settime();
              
                    a3=a1 + a2;
                    a4+=a1;
              
              result=a1>a2;
              
                 if(result==1)
                   cout<<"Time1 is greater than Time 2\n";
                 else
                   cout<<"Time2 is greater than Time 1\n";
                            
                
                       ++a1;
                       a2++;
                       
                     
              a1.display();
              a2.display();
              a3.display();
              a4.display();
              
                     getche();
                     
                     
                       return 0;
                       
      }                 
                    
  

Read More

Articles for you