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
|
// 9.5.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <iomanip>
using namespace std;
void GetInput(int& hrs, int& min, int& sec);
void Output(int hrs, int min, int sec, int format=0);
int main()
{
int hrs, min, sec;
GetInput(hrs, min, sec);
Output(hrs, min, sec);
Output(hrs, min, sec, 1);
Output(hrs, min, sec, 2);
}
void GetInput(int& hrs, int& min, int& sec)
{
cout << "Input the hour in 24 hour time: ";
cin >> hrs;
cout << "\nInput the minute: ";
cin >> min;
cout << "\nInput the second: ";
cin >> sec;
cout << "\n\n";
}
void Output(int hrs, int min, int sec, int format)
{
if (format == 2)
{
cout << "Showing in 24-hour time:\n";
cout << setw(2) << setfill('0') << hrs << ":" << setw(2) << min << ":" << setw(2) << sec << "\n";
}
else if (format == 1)
{
cout << "Showing in military time:\n";
cout << setw(2) << setfill('0') << hrs << setw(2) << min << ":" << setw(2) << sec << "\n";
}
else
{
cout << "Showing in regular time:\n";
if (hrs >= 12) {
cout << hrs-12 << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << sec << " PM" << "\n";
}
else
{
cout << hrs << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << sec << " AM" << "\n";
}
}
}
|