Hey guys i was just wondering i have a code that will allow you to output times 4 different ways but instead of times i want it to output dates 4 different ways.
#include <iostream>
using std::cout;
#include <iomanip>
using std::setfill;
using std::setw;
using std::endl;
#include "Time.h" // include definition of class Time from Time.h
#
int main()
{
Time t1; // all arguments defaulted
Time t2( 2 ); // hour specified; minute and second defaulted
Time t3( 21, 34 ); // hour and minute specified; second defaulted
Time t4( 12, 25, 42 ); // hour, minute and second specified
Time t5( 27, 74, 99 ); // all bad values specified
cout << "Constructed with:\n\nt1: all arguments defaulted\n ";
t1.printUniversal(); // 00:00:00
cout << "\n ";
t1.printStandard(); // 12:00:00 AM
cout << "\n\nt2: hour specified; minute and second defaulted\n ";
t2.printUniversal(); // 02:00:00
cout << "\n ";
t2.printStandard(); // 2:00:00 AM
cout << "\n\nt3: hour and minute specified; second defaulted\n ";
t3.printUniversal(); // 21:34:00
cout << "\n ";
t3.printStandard(); // 9:34:00 PM
cout << "\n\nt4: hour, minute and second specified\n ";
t4.printUniversal(); // 12:25:42
cout << "\n ";
t4.printStandard(); // 12:25:42 PM
cout << "\n\nt5: all invalid values specified\n ";
t5.printUniversal(); // 00:00:00
cout << "\n ";
t5.printStandard(); // 12:00:00 AM
cout << endl;
system("pause");
return 0;
} // end main
// Time constructor initializes each data member to zero;
// ensures that Time objects start in a consistent state
Time::Time( int hr, int min, int sec )
{
setTime( hr, min, sec ); // validate and set time
} // end Time constructor
// set new Time value using universal time; ensure that
// the data remains consistent by setting invalid values to zero
void Time::setTime( int h, int m, int s )
{
setHour( h ); // set private field hour
setMinute( m ); // set private field minute
setSecond( s ); // set private field second
} // end function setTime
// set hour value
void Time::setHour( int h )
{
hour = ( h >= 0 && h < 24 ) ? h : 0; // validate hour
} // end function setHour
// set minute value
void Time::setMinute( int m )
{
minute = ( m >= 0 && m < 60 ) ? m : 0; // validate minute
} // end function setMinute
// set second value
void Time::setSecond( int s )
{
second = ( s >= 0 && s < 60 ) ? s : 0; // validate second
} // end function setSecond
// return hour value
int Time::getHour()
{
return hour;
} // end function getHour
// return minute value
int Time::getMinute()
{
return minute;
} // end function getMinute
// return second value
int Time::getSecond()
{
return second;
} // end function getSecond
// print Time in universal-time format (HH:MM:SS)
void Time::printUniversal()
{
cout << setfill( '0' ) << setw( 2 ) << getHour() << ":"
<< setw( 2 ) << getMinute() << ":" << setw( 2 ) << getSecond();
} // end function printUniversal
// print Time in standard-time format (HH:MM:SS AM or PM)
void Time::printStandard()
{
cout << ( ( getHour() == 0 || getHour() == 12 ) ? 12 : getHour() % 12 )
<< ":" << setfill( '0' ) << setw( 2 ) << getMinute()
<< ":" << setw( 2 ) << getSecond() << ( hour < 12 ? " AM" : " PM" );
} // end function printStandard