Write a Program to add two time and store result into 3rd object

/*
  WAP to add two time and store result
  into 3rd object
*/
#include<iostream>
using namespace std;

class Time
{
int hour,min;

public:
void accept()
{
cout<<"\n\n Enter hour and minute: ";
cin>>hour>>min;
}

void display()
{
cout<<"\n\n"<<hour<<" hour "<<min<<" min";
}

void add(Time t1,Time t2)
{
hour=t1.hour+t2.hour;
min=t1.min+t2.min;

if(min>=60)
{
hour=hour+(min/60);
min=min%60;
}
display();
}
};

int main()
{
Time t1,t2,t3;

t1.accept();
t2.accept();
   
t1.display();
t2.display();

t3.add(t1,t2);
   
    return 0;
}

Previous
Next Post »