-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path9.cpp
57 lines (43 loc) · 1.39 KB
/
9.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
/*
Repeat Exercise 8, but instead of two int variables, have the swap() function inter-
change two struct time values (see Exercise 6).
*/
//author @Nishant
#include <iostream>
using namespace std;
struct timee{
int hours, mins, secs;
};
void swap(timee&, timee&);
int main(){
timee time1, time2;
cout << "Values for Time-1" << endl;
cout << "Enter hours: ";
cin >> time1.hours;
cout << "Enter minutes: ";
cin >> time1.mins;
cout << "Enter seconds: ";
cin >> time1.secs;
cout << "Values for Time-2" << endl;
cout << "Enter hours: ";
cin >> time2.hours;
cout << "Enter minutes: ";
cin >> time2.mins;
cout << "Enter seconds: ";
cin >> time2.secs;
swap(time1, time2);
cout << "After swap:" << endl;
cout << "Equivalent in HH:MM:SS format\nTime-1: " << time1.hours << ":" << time1.mins << ":" << time1.secs << "\nTime-2: " << time2.hours << ":" << time2.mins << ":" << time2.secs << endl;
return 0;
}
void swap(timee& time1, timee& time2){
time1.hours = time1.hours+time2.hours;
time2.hours = time1.hours-time2.hours;
time1.hours = time1.hours-time2.hours;
time1.mins = time1.mins+time2.mins;
time2.mins = time1.mins-time2.mins;
time1.mins = time1.mins-time2.mins;
time1.secs = time1.secs+time2.secs;
time2.secs = time1.secs-time2.secs;
time1.secs = time1.secs-time2.secs;
}