Question: Problem Description: Modify the MilTime class you created for Programming Challenge 4 of Chapter 15 (Time Format). The class should implement the following exceptions: BadHour

Problem Description:

Modify the MilTime class you created for Programming Challenge 4 of Chapter 15 (Time Format). The class should implement the following exceptions: BadHour Throw when an invalid hour (< 0 or > 2359) is passed to the class. BadSeconds Throw when an invalid number of seconds (< 0 or > 59) is passed to the class. Demonstrate the class in a driver program.

my code c++:

#include"pch.h"

#include

using namespace std;

class Time {

public:

int hour, minutes, seconds;

};

class MilTime : public Time {

private:

int milHours, milSeconds;

public:

MilTime(int milH, int milS) {

if (milH < 0 || milH> 2359) {

cout << "Error in Hour value!";

return;

}

if (milS < 0 || milS > 59) {

cout << "Error in Second value!";

return;A

}

milHours = milH;

milSeconds = milS;

setTime(milHours, milSeconds);

}

void setTime(int milH, int milS) {

this->hour = (milH / 100) % 12;

this->minutes = milH % 100;

this->seconds = milS;

}

int getHour() {

return milHours;

}

int getStandHr() {

return hour;

}

int getMinutes() {

return minutes;

}

int getSeconds() {

return seconds;

}

};

int main() {

int h, s;

cout << "Enter the hour in military format : ";

cin >> h;

cout << "Enter the seconds : ";

cin >> s;

MilTime time(h, s);

cout << " Standard format : " << time.getStandHr() << ":" << time.getMinutes() << ":" << time.getSeconds();

if (time.getHour() >= 1200) {

cout << "pm";

}

else {

cout << "am";

}

cout << endl;

cout << "Military Format : " << time.getHour() << " " << time.getSeconds() << " seconds";

cout << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!