in need of some help with my program

Hi.
So i am working on a program that takes a user input of military time and converts it to standard time. I'm almost done with the program and i'm very very new to this header file and cpp file stuff so i'm a bit stumped as to how I finalize the program and use the data from the header to work in the cpp file.

I'm trying to have a user input of the military time and I have tried everything i know and can't figure it out so hopefully someone can help.

Below i have my 2 header files(MilTime.h and Time.h) and my c++ program useMilTime.cpp.

In my main program i have written a comment at the beginning explaining what i want to do.

Hopefully what i am trying to say makes sense to someone.
Thanks

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
#include "Time.h"
#include "MilTime.h"
#include <iostream>
using namespace std;

int main()
{
cout << "Please enter the time in military format" << endl;
//I want to put user input here for military time
//it will then be tested below based on the parameters set in my milTime class in milTime.h



//Test milTime for errors, if all goes well output the time, if not display where the error is occurring

		try
		{

		}
		catch (MilTime::InvalidHour) //Displays an error if the day is outside of the range defined in the Date.h header file
		{
			cout << "\nThe hour is invalid" << endl;
		}

		catch (MilTime::InvalidMin) //Displays an error if the month is outside of the range defined in the Date.h header file
		{
			cout << "\nThe minute is invalid" << endl;
		}

		catch (MilTime::InvalidSec) //Displays an error if the year is outside of the range defined in the Date.h header file
		{
			cout << "\nThe second is invalid" << endl;
		}

//Display military time to standard time conversion
//unfinished atm

	system("pause");
	return 0;
}



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Specification file for the Time class
#ifndef TIME_H
#define TIME_H

#include <iostream>
using namespace std;

class Time
{
protected:
   int hour;
   int min;
   int sec;
public:
	class InvalidHour{}; //Empty class
	class InvalidMin{}; //Empty class
	class InvalidSec{}; //Empty class
   // Default constructor
   Time() 
   { 
	   hour = 0; min = 0; sec = 0; 
   }
   
   // Constructor
   Time(int h, int m, int s) 
   { 
	   setHour(h); 
	   setMin(m); 
	   setSec(s); 
   }

   // Accessor functions
   int getHour() const
   { 
	   return hour; 
   }

   int getMin() const
   { 
	   return min; 
   }

   int getSec() const
   { 
	   return sec; 
   }

   void showTime() const
   {
	   cout << getHour() << ":" << getMin() << ":" << getSec() << " ";
   }

   // Mutators

   //input validation for hours
   void setHour(int h)
   {
	   if (h < 0 || h > 12)
		   throw InvalidHour{};
	   else
		   hour = h;
   }

   //Input validation for minutes
   void setMin (int m)
   {
	   if (m < 0 || m > 59)
		   throw InvalidMin{};
	   else
		   min = m;
   }

   //Input validation for seconds
   void setSec(int s)
   {
	   if (s < 0 || s > 59)
		   throw InvalidSec{};
	   else
		   sec = s;
   }
};
#endif 


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
#ifndef MILTIME_H
#define MILTIME_H

#include "Time.h"
#include <iostream>
using namespace std;

class MilTime : public Time
{
protected:
	int milHours;
	int milSeconds;
public:
	MilTime()
	{
		milHours = 0;
		milSeconds = 0;
	}

	MilTime(int h, int m, int s)
	{
		setTime(h, m, s);
	}

	
	void setTime(int h, int m, int s)
	{
		//data validation for milHours
			if (h < 0 || h > 23)
				throw InvalidHour{};
			else
				milHours = h;
		//Data validation for minutes
			if (m < 0 || m > 59)
				throw InvalidMin{};
			else
				min = m;

		//Data validation for milSeconds
			if (s < 0 || s > 59)
				throw InvalidSec{};
			else
				sec = s;
		
	}

	int getHour() const
	{
		return milHours;
	}

	int getStandHr() const
	{
		return hour;
	}

	void showMilTime() const
	{

	}


};
#endif 
Topic archived. No new replies allowed.