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?