Confused about boolean class constructor

Given a complete clock class specification, I am supposed to write an implementation and also write a program to get the current time and display the time in military format or in standard format.
Here is the complete clock specification.

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
#include <string>
using namespace std;
class Clock

{

public:

/* Constructs a clock that can tell the local time. It also sets the

location to "Local"

@param use_military true if the clock uses military format */

Clock(bool use_military);

/* display this clock. It display the current time.

Display clock in military or standard format */

void displayClock() const;

private:

/* Gets the location of this clock.

@return the location */

string get_location() const;

/* Gets the hours of this clock.

Use the ctime struct tm

@return the hours, in military or standard format */

int get_hours() const;

/* Gets the minutes of this clock.

Use the ctime struct tm

@return the minutes */

int get_minutes() const;

/* Checks whether this clock uses military format.

@return true if military format */

bool is_military() const;

// declare data members

bool military;

}; //end of class Clock 


This is my program to display the current time. I am supposed to use an input delay so the time can be tested at a later time.
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
#include <iostream> 
#include "clock.h"
 
using namespace std;

int main()

{

  char ch;

  Clock clock1(true);
  Clock clock2(false);

  clock1.displayClock();

  clock2.displayClock();

  //delay my response for a while

  cin >> ch; //enter data at a later time

  clock1.displayClock();

  clock2.displayClock();


  return 0;

}

My problem is in the implementation. I am having trouble understanding how to work with a non default boolean constructor. The question marks are the points I'm confused about. I've agonized over it all day. I assume i am just over thinking it. Any and all hints or guidance is appreciated. While i wouldn't mind the code for it, i want to understand how this process works.
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
59
60
61
62
63
64
65
#include <ctime>
#include <iomanip>
#include <iostream>
#include <string>
#include "clock.h"
using namespace std;

Clock::Clock(?)
{
   ?
}

void Clock::displayClock() const
{
   int hours = get_hours();
   int minutes = get_minutes();
   if(?)    // logic needed to display in military format
     {
        // this is simply to add a 0 to single digit minutes
	if(minutes < 10)
	cout << get_location() << " time is " << hours << ":" << setfill('0') << setw(2) << minutes << endl;
	else
	cout << get_location() << " time is " << hours << ":" << minutes << endl;
     }
   else
     {
        /* this is the logic needed to convert military to standard time
	i can sort this out after i figure out my problem */
	if(minutes < 10)
	cout << get_location() << " time is " << hours << ":" << setfill('0') << setw(2) << minutes << endl;
	else
	cout << get_location() << " time is " << hours << ":" << minutes << endl;
	}	
}

string Clock::get_location() const
{
return "Local";	
}

int Clock::get_hours() const
{
    time_t rawtime;
    struct tm *info;
    info = new tm;
    time( &rawtime );
    info = localtime( &rawtime );
    return info->tm_hour;
}

int Clock::get_minutes() const
{
    time_t rawtime;
    struct tm *info;
    info = new tm;
    time( &rawtime );
    info = localtime( &rawtime );
    return info->tm_min;
}

bool Clock::is_military() const
{
   ?	
}
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
// initialise the member 'military' with 'use_military' 
Clock::Clock( bool use_military ) : military(use_military)
{
}

void Clock::displayClock() const
{
    int hours = get_hours();
    int minutes = get_minutes();

    if( military )    // logic needed to display in military format
    {
        // this is simply to add a 0 to single digit minutes
        
        // ...
    }
    else
    {
        // this is the logic needed to convert military to standard time
        
        // ...
    }	
}

bool Clock::is_military() const
{
    return military ;
}

// etc. 
Thank you. I was seriously over thinking the problem. I also realized the (minutes < 10) is unnecessary as it will only auto fill if there isn't a value in the first field. This allowed me to do the output in a single line of code.
Topic archived. No new replies allowed.