Friday, 26 January 2018

Create a class called TIME that has separate member data for hour(int) and minutes(int).Include the following member functions: - setdata( )to set these values to predefined values in the program - getdata( )to get these values from the user -putdata( ) to display these values. -Member function add_time( ) to add two time objects to a third time object (e.g. T3.add_time(T1,T2). -Make new function to return a time object, so that the function works as follows: T3=T1.add_time(T2).

#include<iostream>
using namespace std;

class time
{
    int hour;
    int minute;
   
    public:
            void setdata()
            {
                hour=0;
                minute=0;
            }
           
            void getdata()
            {
                cout<<"\nEnter Hour and Minute: ";
                cin>>hour>>minute;
            }
           
            void putdata()
            {
                cout<<"\nHour is:"<<hour<<"\nMinute is:"<<minute;
            }
           
            time add_time(time t1,time t2)
            {
                time t3;
                t3.hour=t2.hour+t1.hour;
                t3.minute=(t2.minute+t1.minute);
               
                if(t3.hour>60)
                {
                    t3.hour++;
                    t3.minute = t3.minute-60;
                }
                return t3;
            }
           
            time add_time(time t2)
            {
                time t3;
                t3.hour=hour+t2.hour;
                t3.minute=(minute+t2.minute);
               
                if(t3.hour>60)
                {
                    t3.hour++;
                    t3.minute = t3.minute-60;
                }
                return t3;
            }
           
};
int main()
{
    time t1,t2,t3;
   
    t1.getdata();
    t1.putdata();
   
    t2.getdata();
    t2.putdata();

    t3.setdata();
    t3 = t3.add_time(t1,t2);
    t3.putdata();
   
    t3 = t1.add_time(t2);
    t3.putdata();
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...