mirror of
https://github.com/RustyRaptor/CS271.git
synced 2026-12-03 15:45:18 -07:00
added comments
This commit is contained in:
1 parent
32e0aa1d24
commit
39c8522b85
2 files changed
+37
-34
No files matched your search
+15
-5
@@ -16,10 +16,15 @@
|
||||
using namespace std;
|
||||
|
||||
int main( ) {
|
||||
|
||||
// Create an array of time objects
|
||||
Time timearr[ARRSIZE];
|
||||
int num;
|
||||
srand( time( NULL ) );
|
||||
for ( int i = 0; i < ARRSIZE; i++ ) {
|
||||
|
||||
// initialize the object to a new empty time
|
||||
// generate a random number for each variable
|
||||
num = rand( ) % MAXHOUR + 1;
|
||||
timearr[i] = Time( );
|
||||
timearr[i].setHour( num );
|
||||
@@ -29,22 +34,25 @@ int main( ) {
|
||||
|
||||
num = rand( ) % MAXSECOND + 1;
|
||||
timearr[i].setSecond( num );
|
||||
}
|
||||
}// end for
|
||||
|
||||
cout << "The generated times in 24 hour format are: " << endl;
|
||||
for ( int i = 0; i < ARRSIZE; i++ ) {
|
||||
timearr[i].print( );
|
||||
}
|
||||
}// end for
|
||||
|
||||
cout << "The generated times in 12 hour format are: " << endl;
|
||||
for ( int i = 0; i < ARRSIZE; i++ ) {
|
||||
timearr[i].print12( );
|
||||
}
|
||||
}// end for
|
||||
|
||||
|
||||
|
||||
// do the same for date objects
|
||||
Date datearr[ARRSIZE];
|
||||
|
||||
|
||||
// Ask the user for a month day and year 5 times.
|
||||
int inMonth, inDay, inYear;
|
||||
for (int i = 0; i < ARRSIZE; i++) {
|
||||
cout << "Enter the month for DATE " << i+1 << endl;
|
||||
@@ -59,13 +67,15 @@ int main( ) {
|
||||
datearr[i].setMonth(inMonth);
|
||||
datearr[i].setDay(inDay);
|
||||
datearr[i].setYear(inYear);
|
||||
}
|
||||
} // end for
|
||||
|
||||
cout << "The inputted dates are: " << endl;
|
||||
for ( int i = 0; i < ARRSIZE; i++ ) {
|
||||
datearr[i].print( );
|
||||
}
|
||||
}// end for
|
||||
|
||||
|
||||
// test to see that the constructor is working.
|
||||
Date testDate = Date(6, 12, 1998);
|
||||
|
||||
cout << "testing arg constructor" << endl;
|
||||
|
||||
+22
-29
@@ -18,53 +18,52 @@ Time::Time( ) {
|
||||
hour = 0;
|
||||
minute = 0;
|
||||
second = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Time::Time( int h, int m, int s ) {
|
||||
hour = h;
|
||||
minute = m;
|
||||
second = s;
|
||||
}
|
||||
}
|
||||
|
||||
void Time::setHour( int h ) {
|
||||
if ( h >= 0 && h <= HR_LIMIT ) {
|
||||
hour = h;
|
||||
}
|
||||
// end if
|
||||
}
|
||||
} // end if
|
||||
}
|
||||
|
||||
void Time::setMinute( int m ) {
|
||||
if ( m >= 0 && m <= MIN_SEC_LIMIT ) {
|
||||
minute = m;
|
||||
}
|
||||
// end if
|
||||
}
|
||||
} // end if
|
||||
}
|
||||
|
||||
void Time::setSecond( int s ) {
|
||||
if ( s >= 0 && s <= MIN_SEC_LIMIT ) {
|
||||
second = s;
|
||||
}
|
||||
// end if
|
||||
}
|
||||
} // end if
|
||||
}
|
||||
|
||||
int Time::getHour( ) {
|
||||
return hour;
|
||||
}
|
||||
}
|
||||
|
||||
int Time::getMinute( ) {
|
||||
return minute;
|
||||
}
|
||||
}
|
||||
|
||||
int Time::getSecond( ) {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
||||
void Time::print( ) {
|
||||
cout << setfill( '0' ) << setw( 2 ) << getHour( ) << ":"
|
||||
<< setfill( '0' ) << setw( 2 ) << getMinute( ) << ":"
|
||||
<< setfill( '0' ) << setw( 2 ) << getSecond( ) << endl;
|
||||
}
|
||||
cout << setfill( '0' ) << setw( 2 ) << getHour( ) << ":" << setfill( '0' )
|
||||
<< setw( 2 ) << getMinute( ) << ":" << setfill( '0' ) << setw( 2 )
|
||||
<< getSecond( ) << endl;
|
||||
}
|
||||
|
||||
|
||||
// print the time in 12 hour format
|
||||
void Time::print12( ) {
|
||||
const int twlve = 12;
|
||||
int twelve_hour = getHour( );
|
||||
@@ -73,19 +72,13 @@ void Time::print12( ) {
|
||||
twelve_hour = twelve_hour - twlve;
|
||||
cout << setfill( '0' ) << setw( 2 ) << twelve_hour << ":"
|
||||
<< setfill( '0' ) << setw( 2 ) << getMinute( ) << ":"
|
||||
<< setfill( '0' ) << setw( 2 ) << getSecond( ) << " PM"
|
||||
<< endl;
|
||||
<< setfill( '0' ) << setw( 2 ) << getSecond( ) << " PM" << endl;
|
||||
|
||||
}
|
||||
//end if
|
||||
} //end if
|
||||
|
||||
else {
|
||||
cout << setfill( '0' ) << setw( 2 ) << twelve_hour << ":"
|
||||
<< setfill( '0' ) << setw( 2 ) << getMinute( ) << ":"
|
||||
<< setfill( '0' ) << setw( 2 ) << getSecond( ) << " AM"
|
||||
<< endl;
|
||||
|
||||
}
|
||||
//end else
|
||||
}
|
||||
|
||||
<< setfill( '0' ) << setw( 2 ) << getSecond( ) << " AM" << endl;
|
||||
} //end else
|
||||
}
|
||||
Reference in new issue
Block a user