Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. relational operators in class time

relational operators in class time

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MMJ1989
    wrote on last edited by
    #1

    hello hello hello simply i have this code . and i need help to modify or change >= operators in class .

    #include using namespace std ;

    class time
    {
    private :
    int hour ;
    int minute ;
    int second ;
    public :
    time ()
    {}
    time (int h , int m , int s ) : hour ( h) , minute (m) , second(s)
    {}
    void get ()
    {
    cin >> hour >> minute >> second ;
    }
    void show ()
    {
    cout << hour << " : " << minute << " : " << second << endl ;
    }

       bool operator >= ( time r ) 
       { 
    	   if ( hour >= r.hour  ) 
    		   {
    			  if ( hour > r.hour ) 
    			  { 
    				  return true ; 
    			  }
    			  else 
    			  {
    				  if ( minute >= r.minute ) 
    				  {
    					  if ( second >= r.second ) 
    						  return true ; 
    						else 
    							return false ; 
    				  } else { 
    					  return false ; 
    				  }
    			  }
    			   
    		   }  
    	   else 
    		   return false ; 
       } 
    

    };

    int main ()
    {
    time a, b ;
    a.get() ;
    b.get() ;

    a.show() ; 
    b.show () ; 
    
    if ( a >= b ) 
    	cout << "true  \\n" ; 
    else 
    	cout << "not true \\n" ; 
    
    return 0 ; 
    

    }

    L 1 Reply Last reply
    0
    • M MMJ1989

      hello hello hello simply i have this code . and i need help to modify or change >= operators in class .

      #include using namespace std ;

      class time
      {
      private :
      int hour ;
      int minute ;
      int second ;
      public :
      time ()
      {}
      time (int h , int m , int s ) : hour ( h) , minute (m) , second(s)
      {}
      void get ()
      {
      cin >> hour >> minute >> second ;
      }
      void show ()
      {
      cout << hour << " : " << minute << " : " << second << endl ;
      }

         bool operator >= ( time r ) 
         { 
      	   if ( hour >= r.hour  ) 
      		   {
      			  if ( hour > r.hour ) 
      			  { 
      				  return true ; 
      			  }
      			  else 
      			  {
      				  if ( minute >= r.minute ) 
      				  {
      					  if ( second >= r.second ) 
      						  return true ; 
      						else 
      							return false ; 
      				  } else { 
      					  return false ; 
      				  }
      			  }
      			   
      		   }  
      	   else 
      		   return false ; 
         } 
      

      };

      int main ()
      {
      time a, b ;
      a.get() ;
      b.get() ;

      a.show() ; 
      b.show () ; 
      
      if ( a >= b ) 
      	cout << "true  \\n" ; 
      else 
      	cout << "not true \\n" ; 
      
      return 0 ; 
      

      }

      L Offline
      L Offline
      Lakamraju Raghuram
      wrote on last edited by
      #2

      Change to what?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups