Please, fix the following code and compile it! #include <iostream> #include <str
ID: 3669992 • Letter: P
Question
Please, fix the following code and compile it!
#include <iostream>
#include <string>
#include "Time.h"
#include <sstream>
using namespace std;
int main()
{
/* Default constructor test */
cout << "Object test: ";
Time test{};
if (test.is24Hour())
cout << "test is 24 hour formatted";
else
cout << "test is not 24 hour formatted";
cout << endl <<test.toString() << " ";
/* Overloaded test: asLong() test */
cout << "Object raw: ";
Time raw{14,02,50,600};
raw.set24Hour(true);
if (raw.is24Hour())
cout << "raw is 24 hour formatted ";
else
cout << "raw is not 24 hour formatted ";
cout << raw.toString() << " Time in ms: " << raw.asLong() << endl;
/* Overloaded test: 24 hour */
cout << "Object now: ";
Time now{13, 20, 04, 600};
now.set24Hour(true);
if (now.is24Hour())
cout << "now is 24 hour formatted";
else
cout << "now is not 24 hour formatted";
cout << endl <<now.toString() << " ";
/* Overloaded test: 12 hour */
cout << "Object t_money: ";
Time t_money {15, 55, 43, 900};
if (t_money.is24Hour())
cout << "t_money is 24 hour formatted";
else
cout << "t_money is not 24 hour formatted";
cout << endl <<t_money.toString() << " ";
/* Overloaded test: max time, min time [ALL WORKING, MIDNIGHT CASE HANDLED]*/
cout << "Object min: ";
Time min {0,0,0,0};
cout << min.toString() << " ";
min.set24Hour(true);
cout << min.toString() << " ";
cout << "Object max: ";
Time max {23, 59, 59, 999};
cout << max.toString() << " ";
max.set24Hour(true);
cout << max.toString() << " ";
/* Overloaded test: bad input */
cout << "Object bad1: ";
Time bad1 {-30, 80, 109, 1010}; //Negative, out of bound values
cout << bad1.toString() << " ";
cout << "Object bad2: ";
Time bad2 {'T', 'a', 6, 509}; //non-integer values
cout << bad2.toString() << " ";
cout << "Object bad3: ";
Time bad3 {14, 43, 50, 1010}; //Out of bound only
cout << bad3.toString() << " ";
cout << "Object bad4: ";
Time bad4 {15, 45, 20, 50};
cout << bad4.toString() << " ";
}
Explanation / Answer
Hi please post Time.h