-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_in_sec.cpp
More file actions
49 lines (41 loc) · 907 Bytes
/
time_in_sec.cpp
File metadata and controls
49 lines (41 loc) · 907 Bytes
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
//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:\t"<<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<<"\nThe time you've entered is = "<<setw(2)<<setfill('0')<<hh<< ":"<<setw(2)<<setfill('0')<<mm<< ":"<<setw(2)<<setfill('0')<<ss<<endl;
cout<<"\nTime in total seconds: "<<seconds;
}
int main()
{
Time T;
T.getTime();
T.convertIntoSeconds();
T.displayTime();
return 0;
}