Nessun titolo diapositiva - PowerPoint PPT Presentation

About This Presentation
Title:

Nessun titolo diapositiva

Description:

void printMilitary(); // print military time format ... Military time after setTime is 13:27. Standard time after setTime is 1:27:06 PM ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 8
Provided by: utente6
Category:

less

Transcript and Presenter's Notes

Title: Nessun titolo diapositiva


1
// Driver for Time1 class // NOTE Compile with
time1.cpp include ltiostreamgt using
stdcout using stdendl include
"time1.h" // Driver to test simple class
Time int main() Time t // instantiate
object t of class time cout ltlt "The initial
military time is " t.printMilitary() cout
ltlt "\nThe initial standard time is "
t.printStandard()
2
t.setTime( 13, 27, 6 ) cout ltlt "\n\nMilitary
time after setTime is " t.printMilitary()
cout ltlt "\nStandard time after setTime is "
t.printStandard() t.setTime( 99, 99, 99 )
// attempt invalid settings cout ltlt "\n\nAfter
attempting invalid settings\n" ltlt
"Military time " t.printMilitary() cout
ltlt "\nStandard time " t.printStandard()
cout ltlt endl return 0
3
// Member function definitions for Time
class. include ltiostreamgt using
stdcout include "time1.h" // Time
constructor initializes each data member to
zero. // Ensures all Time objects start in a
consistent state. TimeTime() hour minute
second 0 // Set a new Time value using
military time. Perform validity // checks on the
data values. Set invalid values to zero. void
TimesetTime( int h, int m, int s ) hour
( h gt 0 h lt 24 ) ? h 0 minute ( m
gt 0 m lt 60 ) ? m 0 second ( s gt 0
s lt 60 ) ? s 0
4
// Print Time in military format void
TimeprintMilitary() cout ltlt ( hour lt 10 ?
"0" "" ) ltlt hour ltlt "" ltlt ( minute lt
10 ? "0" "" ) ltlt minute // Print time in
standard format void TimeprintStandard()
cout ltlt ( ( hour 0 hour 12 ) ? 12 hour
12 ) ltlt "" ltlt ( minute lt 10 ? "0" ""
) ltlt minute ltlt "" ltlt ( second lt 10 ? "0"
"" ) ltlt second ltlt ( hour lt 12 ? " AM"
" PM" )
5
// Declaration of the Time class. // Member
functions are defined in time1.cpp // prevent
multiple inclusions of header file ifndef
TIME1_H define TIME1_H // Time abstract data
type definition class Time public Time()
// constructor void
setTime( int, int, int ) // set hour, minute,
second void printMilitary() // print
military time format void printStandard()
// print standard time format
6
private int hour // 0 - 23 int
minute // 0 - 59 int second // 0 -
59 endif
7
The initial military time is 0000 The initial
standard time is 120000 AM Military time after
setTime is 1327 Standard time after setTime is
12706 PM After attempting invalid
settings Military time 0000 Standard time
120000 AM
Write a Comment
User Comments (0)
About PowerShow.com