-
Notifications
You must be signed in to change notification settings - Fork 23
/
6.cpp
65 lines (48 loc) · 1.43 KB
/
6.cpp
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
/*
Start with the program from Exercise 11 in Chapter 4, “Structures,” which adds two
struct time values. Keep the same functionality, but modify the program so that it uses
two functions. The first, time_to_secs() , takes as its only argument a structure of type time ,
and returns the equivalent in seconds (type long ). The second function,
takes as its only argument a time in seconds (type long ), and returns a
structure of type time .
*/
//author @Nishant
#include <iostream>
using namespace std;
struct timee {
int hours, minutes, seconds;
};
long time_to_secs(timee);
timee secs_to_time(long);
int main(){
timee time1, time2;
char temp;
long secTime;
cout << "Enter hours: ";
cin >> time1.hours;
cout << "Enter minutes: ";
cin >> time1.minutes;
cout << "Enter seconds: ";
cin >> time1.seconds;
cout << "Equivalent in seconds: " << time_to_secs(time1) << endl;
cout << endl << "Enter time in seconds: ";
cin >> secTime;
time2 = secs_to_time(secTime);
cout << "Equivalent in HH:MM:SS format: " << time2.hours << ":" << time2.minutes << ":" << time2.seconds << endl;
return 0;
}
long time_to_secs(timee time1) {
return time1.hours*3600 + time1.minutes*60 + time1.seconds;
}
timee secs_to_time(long tt) {
int hh, mm, ss;
timee time2;
mm = tt/60;
ss = tt%60;
hh = mm/60;
mm = mm%60;
time2.hours = hh;
time2.minutes = mm;
time2.seconds = ss;
return time2;
}