The MilTime class should convert time in military (24-hour) format to the standard time format used by the Time class.

Theclass should have the following member variables:

milHours : Contains the hour in 24-hour format. For example, 1:00 pm would be stored as 1300 hours, and 4:30 pm would be stored as 1630 hours.

milSeconds : Contains the seconds in standard format.

The class should have the following member functions:

Constructor : The constructor should accept arguments for the hour and seconds, in military format.

The time should then be converted to standard time and stored in the hours , min , and sec variables of the Time class.

setTime : Accepts arguments to be stored in the milHours and milSeconds variables.

The time should then be converted to standard time andstored in the hours , min , and sec variables of the Time class.

getHour : Returns the hour in military format.

getStandHr : Returns the hour in standard format.

Demonstrate the class in a program that asks the user to enter the time in military for- mat. The program should then display the time in both military and standard format

Basically trying to create a program that in incorporates Inheritance, Polymorphism, and Virtual Functions.

My code thus far for the problem.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

class Time



protected:

    int hour;
    int min;
    int sec;

public:

    Time()

    {
        hour = 0; min = 0; sec = 0;
    }

    Time(int h, int m, int s);

    (hour = h; min = m; sec = s);
}

int gethour() const

{
    return hour;
}

int getMin() const
{
    return min;
}

int getSec() const
{
    return sec;
}

};


class MilTime : public Time
{

private: int milHours;
         int milSeconds;

public:

    MilTime(int hours, int seconds)

    {

        milHours = hours;
        milSeconds = seconds;
    }

    void setTime(int milhours, int milseconds);
    int gethour();
    int getMin();
    int getStandHr();
};

void MilTime::setTime(int mhours, int mseconds)
{

    milHours = milHours;
    mseconds = mseconds;
    hour = (milHours / 100);
    min = milHours % 100;
    sec = mseconds;
}


int MilTime::getHour()
{
    return mHours;
}

int MilTime::getStandHr()
{
    return hour % 12;
}


int main()
{

    int hr, sec;

    MilTime time1(0, 0);

    cout << "Enter Time in Milatary format: ";

    cin >> hr;

    sec = hr % 10;

    time1.setTime(hr, sec);

    cout << "MiltataryFormat: " << time1.getHour() << "hours" << endl;

    if.(time1.gethour() / 12 == 1)
    {

        cout << "Standard Format: " << time1.getStandHr() << " : ";

        if (time1.getMin() == 0)
        {
            cout << time1.getMin() << "0" << "PM" << endl;

        else
            cout << time1.getMin() << "PM" << endl;
        }

        else
        {

            cout << "Standard Format: " << time1.getStandHr() << ":";

            if (time1.getMin() == 0)
            {

                cout << time1.getMin() << "0" << "AM" << endl;
            }

            else

                cout << time1.getMin() << "AM" << endl;

        }

        system("pause");

        return 0;

    }

There are 40 errors messages at the moment, is there a better way to build this?

is there a better way to build this?

That depends. How are you building it? If your using a modern C++ compiler, and your using reasonable flags, you should be fine.

There are 40 errors messages at the moment

It would take at least 2 minutes to find problems by staring at the code. However, if you post the errors, we would be able to spot the problem in 10's of seconds and give a more meaninful responce.

Your errors seem to do with basic syntax and don't really have anything to do with the structure of your code. Go through every structure and check for proper braces, variable name spelling, and line terminations. One glaring syntax error is, the if and else blocks, in lines 115-121, are sharing one set of braces when they should each have there own.

One thing to remember, the c++ compiler is very linear. It expects to see things in a specific format. A mistake in one part early in your code can generate dozens of errors farther down, even though the syntax there is correct.

The compiler should report the line number, creating the first error, first. Find the error there and rebuild, then repeat, only looking at the first reported error, until all the errors are cleared up. You'll find that all of a sudden the error count goes from 40 to nothing after you've fixed only a few errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.