-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.cpp
More file actions
74 lines (68 loc) · 1.42 KB
/
Copy pathTime.cpp
File metadata and controls
74 lines (68 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*Create a class 'Time' with hours, minutes and seconds as private data members,
two constructors (one default and one parameterized),
two public methods increment_min() and print().
Also write a private function convertToSec() that converts and returns the stored time into seconds?.
Show the use of such an object through the main() function.
*/
#include <iostream>
#include <iomanip>
using namespace std;
class Time
{
private:int hr;
int min;
int sec;
int convertToSec();
public:void increment_min();
void print();
Time();
Time(int h,int m,int s);
};
Time::Time()
{
hr=0;
min=0;
sec=0;
}
Time::Time(int h,int m,int s)
{
hr=h;
min=m;
sec=s;
}
void Time::increment_min()
{
while(sec>=60)
{
min+=1;
sec=sec-60;
}
while(min>=60)
{
hr+=1;
min=min-60;
}
}
void Time::print()
{
cout<<"Time in Hour:Minute:Second Format-\t"<<hr<<":"<<min<<":"<<sec<<endl;
}
int Time::convertToSec()
{
int second=0;
second=second+(hr*3600);
second=second+(min*60);
second=second+sec;
return second;
}
int main()
{
Time ob;
int hours,minutes,seconds;
cout<<"Enter Hours,minutes and seconds respectively"<<endl;
cin>>hours>>minutes>>seconds;
Time ob1(hours,minutes,seconds);
ob.print();
ob1.increment_min();
ob1.print();
}