0% found this document useful (0 votes)
75 views2 pages

#Include: "Enter The First Time: Hour, Minuate, Second/n"

This C++ program defines a Time class to represent times in hours, minutes, and seconds. It includes methods to input two times from the user, convert the seconds and minutes to hours if needed, and add the two times together by summing the hours, minutes, and seconds components and properly carrying over values. The main function demonstrates creating two Time objects, inputting times for each, calling the add method to sum the times, and returning the result.

Uploaded by

ratan lal mourya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views2 pages

#Include: "Enter The First Time: Hour, Minuate, Second/n"

This C++ program defines a Time class to represent times in hours, minutes, and seconds. It includes methods to input two times from the user, convert the seconds and minutes to hours if needed, and add the two times together by summing the hours, minutes, and seconds components and properly carrying over values. The main function demonstrates creating two Time objects, inputting times for each, calling the add method to sum the times, and returning the result.

Uploaded by

ratan lal mourya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1: #include<iostream>

2: using namespace std;
3: class time
4: {
5:     int h1,m1,s1;
6:     int h2,m2,s2;
7:     public:
8:     void time1()
9:         {
10:             cout<<"enter the first time: hour,minuate,second\n";
11:             cin>>h1>>m1>>s1;
12:             
13:             
14:             cout<<h1<<":"<<m1<<":"<<s1<<"\n";
15:         }
16:         void time2()
17:         {
18:             cout<<"enter the second time: hour,minute,secod\n";
19:             cin>>h2>>m2>>s2;
20:                 if(s2>=60)
21:             {
22:                 m2=m2+s2/60;
23:                 s2=s2%60;
24:             }
25:             if(m2>=60)
26:             {
27:                 h2=h2+m2/60;
28:                 m2=m2%60;
29:             }
30:             cout<<h2<<":"<<m2<<":"<<s2<<"\n";
31:         }
32:         
33:      friend int add(time x,time y);
34: };
35: int add(time x,time y )
36: {  int h3,m3,s3;
37:     h3=x.h1+y.h2;
38:     m3=x.m1+y.m2;
39:     s3=x.s1+y.s2;  
40:     if(s3>=60)
41:     {
42:         m3=m3+s3/60;
43:         s3=s3%60;
44:     }
45:     if(m3>=60)
46:     {
47:         h3=h3+m3/60;
48:         m3=m3%60;
49:     }
50:     cout<<h3<<":"<<m3<<":"<<s3<<"\n";   
51: }
52: 
53: int main()
54: {
55:     time p,m;
56:     int a;
57:     p.time1();
58:     m.time2();
59:     a=add( p, m);
60:     return 0;
61: }

You might also like