Answer:
THE CODE FOR THE PROGRAM IS GIVEN BELOW:
#include <iostream>
#include "ConvertTimeHeader.h"
using namespace std;
int main()
{
convertTime convert;
int hr, mn, sc = 0;
cout << "Please input hours in 12 hr notation: ";
cin >> hr;
cout << "Please input minutes: ";
cin >> mn;
cout << "Please input seconds: ";
cin >> sc;
convert.invalidHr(hr);
convert.invalidMin(mn);
convert.invalidSec(sc);
convert.printMilTime();
system("Pause");
return 0;
}
#include <iostream>
#include "ConvertTimeHeader.h"
using namespace std;
int convertTime::invalidHr (int hour)
{
try{
if (hour < 13 && hour > 0)
{hour = hour + 12;
return hour;}
else{
cin.clear();
cin.ignore();
cout << "Invalid input! Please input hour again in correct 12 hour format: ";
cin >> hour;
invalidHr(hour);
throw 10;
}
}
catch (int c) { cout << "Invalid hour input!";}
}
int convertTime::invalidMin (int min)
{
try{
if (min < 60 && min > 0)
{return min;}
else{
cin.clear();
cin.ignore();
cout << "Invalid input! Please input minutes again in correct 12 hour format: ";
cin >> min;
invalidMin(min);
throw 20;
return 0;
}
}
catch (int e) { cout << "Invalid minute input!" << endl;}
}
int convertTime::invalidSec(int sec)
{
try{
if (sec < 60 && sec > 0)
{return sec;}
else{
cin.clear();
cin.ignore();
cout << "Invalid input! Please input seconds again in correct 12 hour format: ";
cin >> sec;
invalidSec(sec);
throw 30;
return 0;
}
}
catch (int t) { cout << "Invalid second input!" << endl;}
}
void convertTime::printMilTime()
{
cout << "Your time converted: " << hour << ":" << min << ":" << sec;
}
Explanation: