CPP/OOP Time class to perform add times

/*2.Write a class to represent time that includes the member function
to perform the following:
i. Take input for time in hours and minutes.
ii. Add two times.
iii.Display the time in form hours : minutes.
#include <iostream>
using namespace std;
class time
{int hours;
int minutes;
void gettime(int h, int m)
{hours= h; minutes = m;}
void puttime (void)
cout<< hours<< “hours:”;
cout<< minutes << “minutes”<<endl;
void sum(time,time); // declaration with objects as arguments
void time::sum(time t1, time t2) //t1, t2 are objects
minutes = t1.minutes+t2.minutes;

int main()
time T1,T2,T3;

T1.gettime(2,45); //get T1
T2.gettime(3,30); // get T2

T3.sum(T1,T2); //T3=T1+T2

cout<< “T1= “; T1.puttime(); //display T1
cout<< “T2= “; T2.puttime(); //display T2
cout<< “T3= “; T3.puttime(); //display T3;


Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>