-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock2.cpp
More file actions
47 lines (39 loc) · 1 KB
/
Copy pathclock2.cpp
File metadata and controls
47 lines (39 loc) · 1 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
#include <iostream>
#include <iomanip>
using namespace std;
class Clock
{
private:
int seconds;
int hours,minutes,sec;
public:
void getTime(void);
void convertIntoSeconds(void);
void displayTime(void);
};
void Clock::getTime(void)
{
cout << "Enter time:" << endl;
cout << "Hours? "; cin >> hours;
cout << "Minutes? "; cin >> minutes;
cout << "Seconds? "; cin >> sec;
}
void Clock::convertIntoSeconds(void)
{
seconds = hours*3600 + minutes*60 + sec;
}
void Clock::displayTime(void)
{
cout << "The time is = " << setw(2) << setfill('0') << hours << ":"
<< setw(2) << setfill('0') << minutes << ":"
<< setw(2) << setfill('0') << sec << endl;
cout << "Time in total seconds: " << seconds;
}
int main()
{
Clock c;
c.getTime();
c.convertIntoSeconds();
c.displayTime();
return 0;
}