Wednesday, 24 September 2014

OOP PROGRAM

#include<iostream>
using namespace std;

class Time{
      private:
      int Hours, Minutes, Seconds;
public:
      Time();
      void setHours(int Hours_value);
      int getHours();
      void setMinutes(int Minutes_value);
      int getMinutes();
      void setSeconds(int Seconds_value);
      int getSeconds();
      void UniversalPrint();
};

Time::Time()
{
                  Hours=0;
                  Minutes=0;
                  Seconds=0;
}

void Time::setHours(int Hours_value)
{
     if(0>=Hours_value||Hours_value>=24)
     {
                         cout<<"Wrong Input"<<endl;
                         Hours=0;
     }
     else
     {    
                   Hours=Hours_value;
     }
}
int Time::getHours()
{
                return Hours;
}

void Time::setMinutes(int Minutes_value)
{
     if(0>=Minutes_value||Minutes_value>60)
     {
                         cout<<"Wrong Input"<<endl;
                         Minutes=0;
     }
     else
     {    
                   Minutes=Minutes_value;
     }                      
}

int Time::getMinutes()
{
    return Minutes;
}

void Time::setSeconds(int Seconds_value)
{
     if(0>=Seconds_value||Seconds_value>=60)
     {
                         cout<<"Wrong Input"<<endl;
                         Seconds=0;
     }
     else
     {    
                   Seconds=Seconds_value;
     }
}
int Time::getSeconds()
{
    return Seconds;
}

void Time::UniversalPrint()
{
        cout<<getHours()<<":"<<getMinutes()<<":"<<getSeconds();
}


int main()
{
    Time my;
    int Hours_value, Minutes_value, Seconds_value;
    cout<<"Enter Hours: "<<endl;
    cin>>Hours_value;
    my.setHours(Hours_value);
   
   
    cout<<"Enter Minutes: "<<endl;
    cin>>Minutes_value;
    my.setMinutes(Minutes_value);

   
    cout<<"Enter Seconds: "<<endl;
    cin>>Seconds_value;
    my.setSeconds(Seconds_value);

   
   
   
    my.UniversalPrint();
   
    system("pause");
   
     
}

No comments:

Post a Comment