In line 20 of MilTime, it tells me the arguments in the following, : Time(h, m, s)
that h, m, s are undefined. I did a similar assignment and no such problems occurred.
One can see this in the "full code" text box in the 1st post of the following: http://www.dreaminco...1&#entry1654950
Another problem stems from Line 49 of MilTime class. The set precision refuses to create at least 2 digits for minute and seconds. E.g., program display 6:4:0 PM, instead of 6:04:00. I tried setw, but that incorrect though, since it only adds width.
MilTime <<Derived Class>>
#include <iostream>
#include <iomanip>
#include "Time.h"
//#include "Date.h"
//#include "DateTime.h"
using namespace std;
class MilTime : public Time
{
private:
int milHours;
int milSeconds;
public:
MilTime() : Time()
{
milHours = 0;
milSeconds = 0;
}
MilTime(int mh, int ms)// : Time(h, m, s)//,
//DateTime(dy, mon, yr, hr, mt, se),
//Date(dy, mon, yr)
{
milHours = mh;
milSeconds = ms;
setTime(milHours, milSeconds);
}
// Accepts arguments to be stored in the milHour and milSeconds variables.
void setTime(int mh, int ms)
{
hour = mh / 100; // e.g., 2459/100 = 24.59 = 24
min = mh % 100; // 2459/100 = 24.59 = .59 * 100 = 59
sec = ms;
}
// Returns the hour in military format.
int getHour()
{
return milHours;
}
// Returns the hour in standard format.
void getStandHr()
{
cout << setprecision(2) << fixed;
cout << (( hour == 0 || hour == 12 ) ? 12 : (hour % 12)) << // 0 or 12 will output 12... 1,2,3,4...11,12,13,14,...23
":" << setprecision (2) << min << ":" << setprecision(2) << sec << (hour < 12 ? " AM" : " PM" ); //outputs e.g. 11/12 = 0.96667 * 12 = 11,,,23 % 12 = 1.91667 - 1 = .91667 * 12 = 11
}
};
#endif
Time.header <<Base Class>>
Spoiler
Driver
// This program demonstrates a class with multiple inheritance.
#include <iostream>
#include "DateTime.h"
#include "MilTime.h"
using namespace std;
int main()
{
/*
// Define a DateTime object and use the default constructor to initialize it.
DateTime emptyDay;
// Display the object's date and time.
cout << emptyDay.getDateTime() << endl;
// Define a DateTime object and initialize it with the date 2/4/60 and the time 5 32:27.
DateTime pastDay(2, 4, 60, 5, 32, 27);
DateTime secDay(2, 5, 60, 22, 31, 30);
// Display the object'S date and time.
cout << pastDay.getDateTime() << endl;
cout << secDay.getDateTime() << endl;*/
MilTime mt1;
cout << "\nPassing 2359..\n";
mt1.setTime(2359, 00); //@ line 22 of MT class. Pass 2359 h/m, 00 for sec
mt1.getStandHr();
cout << endl;
int num;
do{
cout << "Enter a military time to convert to standard time: ";
cin >> num;
} while (num < 0 || num > 2359);
MilTime mt2(num, 00);
mt2.getStandHr();
cout << endl;
system("pause");
return 0;
}
This post has been edited by mgrex: 09 October 2012 - 09:05 AM

New Topic/Question
Reply



MultiQuote




|