-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timeconverted_into_seconds.c++
49 lines (40 loc) · 1.02 KB
/
Timeconverted_into_seconds.c++
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
/*C++ program to read time in HH:MM:SS format and convert into total seconds.*/
#include <iostream>
#include <iomanip>
using namespace std;
class Time
{
private:
int seconds;
int hh,mm,ss;
public:
void getTime(void);
void convertIntoSeconds(void);
void displayTime(void);
};
void Time::getTime(void)
{
cout << "Enter time:" << endl;
cout << "Hours? "; cin >> hh;
cout << "Minutes? "; cin >> mm;
cout << "Seconds? "; cin >> ss;
}
void Time::convertIntoSeconds(void)
{
seconds = hh*3600 + mm*60 + ss;
}
void Time::displayTime(void)
{
cout << "The time is = " << setw(2) << setfill('0') << hh << ":"
<< setw(2) << setfill('0') << mm << ":"
<< setw(2) << setfill('0') << ss << endl;
cout << "Time in total seconds: " << seconds;
}
int main()
{
Time T; //creating objects
T.getTime();
T.convertIntoSeconds();
T.displayTime();
return 0;
}