Throw when an invalid number of seconds (<0 or > 59) is passed to the class. Demonstrate the class in a driver program. Demo in the main function. the file: // MillTIme.cpp // #include "stdafx.h" #include using namespace std; class Time

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
  • Modify the MilTime class given under Final exam module. 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. Demo in the main function.

the file:

// MillTIme.cpp
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Time
{
protected:
    int hour;
    int min;
    int sec;
public:
    Time(int h, int m, int s)
    {
        hour = h; min = m; sec = s;
    }

    int getHour()
    {
        return hour;
    }

    int getMin()
    {
        return min;
    }

    int getSec()
    {
        return sec;
    }
};

class MilTime : public Time
{
private:
    int milHours;
    int milSeconds;
public:
    MilTime(int h = 0, int s = 0) : Time(0, 0, s)
    {
        if (h < 0 || h > 2359)
        {
            cout << "Hours must be in the range 0 - 2359.\n";
            milHours = h;
            milSeconds = s;
            convert();
            
        }
        else if (s < 0 || s > 59)
        {
            cout << "Seconds must be in the range 0 - 59.\n";
            milSeconds = 0;
        }
        else
        {
            milHours = h;
            milSeconds = s;
        }
        convert();
    }

    void convert()
    {
        double temp;

        if (milHours > 1200)
            hour = milHours - 1200;
        else
            hour = milHours;

        hour /= 100;
        temp = (milHours - 1200) / 100.0;
        min = static_cast<int>(((temp - static_cast<int>(temp)) * 100));
    }

    void setTime(int h, int s)
    {
        
            // Create a MilTime object.
            MilTime timeObj(hour, sec);

            // Display the hour in military and
            // standard formats.
            cout << "The hour in military format is "
                << timeObj.getHour() << endl;
            cout << "The hour in standard format is "
                << timeObj.getStandHr() << endl;

            // Display the minutes.
            cout << "The minutes are "
                << timeObj.getMin() << endl;

            // Display the seconds.
            cout << "The seconds are "
                << timeObj.getSec() << endl;
        
    }

    int getHour()
    {
        return milHours;
    }

    int getStandHr()
    {
        return hour;
    }
};

int main()
{
    // Create a MilTime object for 1445 hours, 27 seconds.
    MilTime timeObj(1445, 27);

    // Display the hours, minutes, and seconds.
    cout << "The hour in military format is "
        << timeObj.getHour() << endl;
    cout << "The hour in standard format is "
        << timeObj.getStandHr() << endl;
    cout << "The minutes are "
        << timeObj.getMin() << endl;
    cout << "The seconds are "
        << timeObj.getSec() << endl;
    return 0;
}

Modify the MilTime class given under Final exam module.
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. Demo in the main function.
Transcribed Image Text:Modify the MilTime class given under Final exam module. 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. Demo in the main function.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY