A program to perform the addition of time in hour and minute using the concept of function argument in C++(call by value)

#include<iostream>
using namespace std;
class Time
{
int hr, min;
public:
void setdata()
{
cout<<“enter hour and minute”;
cin>>hr>>min;
}
void display()
{
cout<<“Hour=”<<hr;
cout<<“Minute=”<<min;
}
void add(Time a, Time b)
{
int x,y;
x=a.min+b.min;
min=x%60;
hr=x/60;
hr=hr+a.hr+b.hr;
}
};
int main()
{
Time t1, t2, t3;
t1.setdata();
t2.setdata();
t3.add(t1, t2);
t1.display();
t2.display();
t3.display();
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *