Computer Science, asked by 70111156, 17 hours ago

Write a class called time that has hours and minutes as integers. The class has the following member functions: void settime(int, int) to set the specified value in object void showtime() to display time object time sum(time) to sum two time object & return time 1. Write the definitions for each of the above member functions. 2. Write main function to create three time objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all time objects.​

Answers

Answered by Unlikely
5

Answer:

#include<iostream.h>

#include<conio.h>

class time

{

  private:

int hours;

int minutes;

  public:

void settime(int h, int m)

{

 hours=h; minutes=m;

}

time sum(time);

void showtime();

};

time time::sum(time TM)

{

time t;

t.minutes = minutes + TM.minutes;

t.hours=t.minutes/60;

t.minutes=t.minutes%60;

t.hours += hours + TM.hours;

return t;

}

void time::showtime()

{

cout<<hours<<" hours and "<<minutes<<" minutes"<<endl;

}

int main()

{

time T1,T2,T3;

T1.settime(2,45);

T2.settime(3,30);

T3=T1.sum(T2);

cout<<"\n Time 1 : ";T1.showtime();

cout<<"\n Time 2 : ";T2.showtime();

cout<<"\n Time 3 : ";T3.showtime();

getch();

return 0;

}

Explanation:

The class has the following member functions:

void settime(int, int) to set the specified value in object

void showtime() to display time object

time sum(time) to sum two time object & return time

Similar questions