Hint needed to access private functions

It's been long since I used this forum, but I am stuck on one part. I have a program that inputs a time in HH::MM AM(PM) and converts from a 12hr time to 24 hr time. Most of the code besides the implementations are from a book. It also gives me a time24 class that would be too long to post and time consuming to look at, but the class time24 has:

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
void time24::readTime()
{
   char colonSeparator;

   cin >> hour >> colonSeparator >> minute;
   // make sure hour and minute are in range
   normalizeTime();
}

// output time in the format <hour>:<minute>
void time24::writeTime() const
{
	// the implementation uses stream handling functions
	// not discussed in the book. consult your compiler
	// help system for details

   // save current format flags and fill character
   long currentFlags = cout.flags();
   char currentFill = cout.fill();

   // set fill char to ' ' and enable right justification
   cout.fill(' ');
   cout.setf(ios::right,ios::adjustfield);
   
   // output the hour
   cout << setw(2) << hour << ':';

   // set fill char to '0' and output the minute
   cout.fill('0');
   cout << setw(2) << minute <<" ";

   // restore the fill char and the format flags
   cout.fill(currentFill);
   cout.setf(currentFlags);
}


I'm assuming the methods in time24 are to be used since in time12 there is a t object for time24 to store in 24 hour format, meaning the convert12To24 method must be used before the variables are stored in t can go into that object.
The main question is how to access the the convert function/method and where to call it from.(since it is private for some reason) Main? readTime? writeTime? Any hints are greatly appreciated. Thank you for your 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
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
#ifndef TIME12_H
#define TIME12_H
#include <iostream>
#include "d_time24.h"
using namespace std;

//12 Hour clock time units 
enum timeUnit {AM = 0, PM};


class time12 // Time 12 class
{
private:
	
	
	time24 t; //Creation of a time24 "object". Purpose: To store time in a 24 hour format.
	time24 convert12To24(int h, int m, timeUnit tunit); //build t from standard time
	
public:
	
	time12(int h, int m, timeUnit tunit); 
		//Initialize time24 data member.
	
	void addTime(int m);
	// add m minutes to update current time
	
	void readTime();
	
	void writeTime();
	// I/O member functions use format HH:MM AM(PM)
	
};
#endif


//****************************************************************************
//Class member function implementation.
//****************************************************************************

time12::time12(int h, int m, timeUnit tunit) //set h, m, time
{ h = 12, m = 0 , tunit = AM;}

time24 time12::convert12To24(int h, int m, timeUnit when) //time24 is type; time12 is class; convert 12 To 24 is method.
{
	if (h < 12 && when == 0)
	{h = h; return (h,m,when);}
	else if (h >= 12 && when == 1)
	{h = h= + 12; return (h, m, when);}
}
void time12::addTime(int m)//addTime is method.
{t.addTime(m);}

void time12::readTime() {t.readTime();}; //Is this correct?

void time12::writeTime(){t.writeTime(); if (t.getHour() < 12) {cout <<"AM"<<endl;}else if (t.getHour() >= 12) {cout<< "PM"<<endl;}};


Last edited on
If a method is private that means it's only supposed to be used for class internal purposes. That simple.
Thanks hanst99.
Topic archived. No new replies allowed.