-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02_time.cpp
58 lines (47 loc) · 1.32 KB
/
02_time.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
// // Define a class Time to represent Time (like 3 hr 45 min 20 sec). Declare appropriate number of instance member variables and also define instance member functions to set values for time and display values of time.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Time
class Time
{
private:
// // instance member variables
int hours, minutes, seconds;
public:
// // instance member function to set time
void setTime(int hr, int min, int sec)
{
hours = hr;
minutes = min;
seconds = sec;
}
// // instance member function to display time
void displayTime()
{
cout << "\n"
<< hours << " hr " << minutes << " min " << seconds << " sec " << endl;
}
};
// // Main Function Start
int main()
{
Time t1; // create object of Time
int hr, min, sec;
// // Get Time
cout << "\n>>>>>>>> Enter Time (24 Hour Format) <<<<<<<<<\n";
cout << "\nEnter Hours => ";
cin >> hr;
cout << "\nEnter Minutes => ";
cin >> min;
cout << "\nEnter Seconds => ";
cin >> sec;
t1.setTime(hr, min, sec); // set time
cout << "\n>>>>>>>> Entered Time <<<<<<<<<";
t1.displayTime(); // display time
cout << endl; // Add new line
cin.ignore();
return 0;
}
// // Main Function End