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
#include "Time.h"
#include "MilTime.h"
#include <iostream>
usingnamespace 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;
}
#ifndef MILTIME_H
#define MILTIME_H
#include "Time.h"
#include <iostream>
usingnamespace 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