     13

      

    , ,    ,    ,  
    - ,   ( 
    )!     1990-, 
 ( - ),       
    . ,     
 ,      , , ,   
    ,  ,   , 
        C++  . 
     ,    -   
   .  C++     
,   int, double  char.      
  ,         
  . 

       -   

        ,     C++   
,        10,000   . 
       ,  
 .         
      ,      
 .  C++     ,   
        ,  
     .    
     ,       
,     ""  . 
          ,   ,    
   . C++       
.      ""  ,  

    305 (192) 

 SmallTalk  Actor, C++    ,  
      - .  
,        ,    
  C++.         . 
      ,     14  15,     
  C++  ,        
 . 

    	 
    	 
    	  

        ,        
.          ! 
            
,    .  C++      
        
       . 

       

           
,   . , ,      
    ,    ,   
 .  ANSI     ,  : 

    struct TTime { 
      int year; 
      int month; 
      int day; 
      int hour; 
      int minute; 
   }; 

     TTime      .    TTime 
  (type)   ,      
  .         
  TTime  : 

   TTime appointment; 

    ,  C++     struct  TTime, 
  ANSI .         
   appointment    : 

    appointment.year = 1996; 
    appointment.month = 7; 
    appointment.day = 14; 
    appointment.hour = 8; 
    appointment.minute = 30; 

     ,    TTime, ,  
    ,   ,    
 ..      : 

    void Display(struct TTime *tp) 
    { 
    char buffer[32] ; 
    sprintf( buffer,   "Date: %02d/%02d/%04d Time: %02d:%02d\n",  tp->month,  
    tp->day,  tp->year,  tp->hour,  tp->minute ) ; 
    cout  buffer ; 
    } 

        ,       
Display()   appointment  TTime: 

    Display ( & appointment ) ; 

     " "  .    , ,  
,        .   
,  TTime,   - ,   
  ,        
,       . 
,          
  .       
 ,         
  .  ,       !  
        
    . 
    
    306	 III.   ANSI C++ 

         TTime       
-   . (     
 .) 
         ,  Display(),    
 TTime    TTime,     . 
           ,    
  TTime.      
     .   ,  
  ,     TTime  
 .        ,  
  .  ,      
 .    :   
.  ,         
    ,    . 
          
    ,      
  .       ,  
     .  C++  
      ,   
         . 

        


            
    - 
    - 

                  . 13.1.  
                                         

              
.     ,      
  (. 13.1). 
       TTime      
  : 

    class TTime	{ 
    public:			//   
      int year ;		// - 
      int month ;		//             "             " 
      int day ;		//             "             "                                     
      int hour ;		//             "             "                                   
      int minute;		// 
      void Display(void) ;	// - 
    }; 
           TTime,   
,       class.  ,   
       ,     .  
    ,    public,  
    ,    
    .       
   private  protected.   public 
    ,   ,    
,     . 
    -      ,   -  . 
-,   year, month  day,   , 
, , ,   ..      
 . ,       
 auto, extern  register. 
    - , ,  Display()   . 
, -,  Display()  TTime,  
   - .     
  . 
      13.1   TTime    C++  
  -.     
      . 

     13.1.  CLASS. ( TTime) 

    1:	#include <iostream.h> 
    2:	#include <stdio.n> 
    3: 
    4:	class TTime { 
    5:	public: //   
    6:	  int year; // - 
    7:	  int month; // " " 
    8:	  int day; // " " 
    9: 	  int hour; // " " 
    10:	  int minute; // " " 
    11:	  void Display(void); // - 
    12:	}; 
    
    
     13.  	307(194) 

    14:	main() 
    15:	{ 
    16:	TTime appointment;     //   TTime 
    18:	appointment.month = 7; //  -  
    19:	appointment.day =14;   
    20:	appointment.year = 1996; 
    21:	appointment.hour = 8; 
    22:	appointment.minute = 30; 
    23:	cout  "Appointment == "; 
    24:	appointment.Display() ; //  - 
    25:	cout  '\n' ; 
    26:	return 0;                           , 
    27:	} 
    28: 
    29:	void TTime::Display(void) 
    30:	{ 
    31:	char s[32]; 
    32:	sprintf(s, "Date: %02d/%02d/%04d Time: %02d:%02d\n", 
    33:	month, day, year, hour, minute); 
    34:	cout  s ; 
    35:         }

      4-12   TTime.     
  ,         
,    .
        29-35,      
Display().       -  
 . 
        -       
 .   void TTime::Display(void)  
,  Display()    TTime.     
  -,        
-    Display(),    . 
        -       . 
,   32-33   -  
TTime  month, year, hour  minute. 
        TTime   ,     
 .    16,  appointment,    
TTime.    ,     . 
 TTime    , ,    .  
    ,  appointment,  ,  
 . 
    ,   18-22   - appointment, 
   .    24,  - 
Display(),    ,   appointment.    
        .   
      -  ( 
   public)     
.      (.  24), C++  
,       - 
 . ,   24   Display()  
  - appointment.      
   TTime,   : 

    TTime today; 
    TTime tomorrow; 
    TTime yesterday; 

        ,       : 

    today.Display();		//     today 
    tomorrow.Display();	//     tomorrow 
    yesterday.DisplayO;	//     yesterday 

     

    C++      - ,  
. ,    class  struct   
  public,   ,   . ( 
       ). ,  
 -:         
   . 

     CLASS1.CPP       
  ,  .  -   
TTime    , ,    
  ,  ,     18-22. -


    308 (195)    III.   ANSI C++ 

 -         
   ,     . 
      13.2      TTime,  
 -    - .   
   - ,     
. 
 
     13.2.  CLASS2.CPP (    TTime)

    1:	#include <iostream.h> 
    2:	#include <stdio.h> 
    3:	 
    4:	class TTime { 
    5:	private:
    6:             int year ; 
    7:             int month ; 
    8:             int day; 
    9:             int hour; 
    10:           int minute; 
    11:	public: 
    12:           void Display(void) ; 
    13:           void GetTime( int &m, int &d, int &y, int &hr, int &min ) ; 
    14:           void SetTime( int m, int d, int y, int hr, int min ) ; 
    15:	}
    16: 
    17:	main() 
    18:	{ 
    19:	TTime appointment; 
    20:	int month, day, year, hour, minute; 
    21: 
    22:	appointment.SetTime(7, 14, 1996, 8, 30); 
    23:	cout  "Appointment == ";                      . 
    24:	appointment. Display() ; 
    25:	appointment.GetTime( month, day, year, hour, minute ) ; 
    26:	appointment.SetTime( month, day, year, hour, minute ) ; 
    27:	cout  "Next hour == ";
    28:	appointment. Display() ; 
    29:	return 0 ; 
    30:	} 
    31:
    32:	void TTime::Display(void) 
    33:	{ 
    34:	char s[32]; 
    35:	sprintf(s, "Date: %02d/%02d/%04d Time: %02d:%02d\n", 
    36:	month, day, year, hour, minute); 
    37:	cout  s; 
    38:	} 
    39: 
    40:	void TTime::GetTime(int &m, int &id, int &y, int &ihr, int &min) 
    41:	{ 
    42:	m = month; //  - ,    
    43:	d = day ; 
    44:	 = year ; 
    45:	hr = hour ;
    46:	min = minute ; 
    47:	} 
    49:	void TTime::SetTime(int m, int d, int y, int hr, int min) 
    50:	{ 
    51:	month = m; //   - 
    52:	day = d; 
    53:	year = y; 
    54:	hour = hr; 
    55:	minute = min; 
    56:	}

       TTime   . -,   
private ( 5)     -   6-10. 
    -    
   -.   :  (private) 
         ,  
   . 
    
    
     13.  	                                   309 (196) 

     

        , , ;  5  
CLASS2.CPP  . ,       
       private  
 . 

            , 
   .     
 private  public    ( 5  11)  , 
 .      , -   
    ,    .     
  , protected,   14. 
        TTime  - GetTime()  SetTime() ( 
13-14).   Display()  -     
 .    - TTime   
      - .  
           
    - .  ,  
  ,      
- ,       , 
       - 
.  . 13.2   ,    
      . ,     
    , ..       . 
      40-56    -  GetTime()  SetTime(). 
  Display(),        TTime:: 
  ,       
 .         
-   GetTime()  SetTime()       
 TTime. 
      -      
-  month, day, year, hour  minute (. 13.2.) ,  
GetTime(),   4246      
,    ,     
 .  SetTimeO    
- . 

    \			 
    / /			X 
    /		 - 			            ^ _ 
    - 
    \  !    ^        J							| 
  ]    ^       J 
    \			J.       
    ,\		 -			 
    4  	- .  . 	W 
    */			,		^ 
    
    
    -          
    
    . 13.2.       

      ,  - TTime   , 
      . 
,   CLASS1.CPP 

    appointment.month = 7;	// ??? 

           CLASS2.CPP,   month 
   TTime       
        , 
 "",  "TTime::month is not accessible in function 
main()" (TTime::month     main()). 


    310 (197)                                                                III.   ANSI C++ 

            appointment 
  -. ,   22  , 
      appointment  14  1996 , 8:30: 

	    appointment.SetTime(7,   14,   1996,  8,  30); 

    ,   25   GetTime()  
 - appointment   ,   
 20.      SetTime()    1 
 hour,    appointment  . (,  
      ,      .) 

     - 

          ,   
        
  .     
 TTime          
   . 
      13.3    TTime,     
CLASS2.CPP,     -.   ,  
    -. 
      ,    ,  
    .     ,  
       ,  
   . 
         , TIME1.H   ,   
      .    
( 13.4  13.5)    ,  , 
  ,   .    
  ,       . 

     13.3. TIME1.H (  TTime   ) 

    1:	// timel.h --   TTime 
    2: 
    3:	#ifndef __TIME1_H 
    4:	#define _TIME1_H 1 //   #include 
    5: 
    6:	class TTime { 
    7:	private: 
    8:	  int month; 
    9:	  int day; 
    10:	  int year; 
    11:	  int hour; 
    12:	  int minute; 
    13:	public: 
    14:	  void Display(void); 
    15:	  void GetTime(int &m,  int &d,  int &y,, int &hr,  int tain); 
    16:	  void SetTime(int m,   int d,   int y,   int hr,   int min); 
    17:	  char *GetSTime(void);                                                  
    18:	  void ChangeTime(long nminutes); 
    19:	}; 
    20: 
    21:	#endif // __TIME1_H 

     3, 4  21    TIME1.H     
    . (      11.2 
 11.)   TTime      
    . 
      13.4  -  TTime.  
        . 
        , 
  .,    -    
,  ,..      DOS  
  - timel.c.        
   TIME.CPP,  TargetExpert  EasyWin   <Alt+F9>. 

     

     TIME1.CPP      <    
 main () ).    TIME1.CPP    
TIME1.OBJ,   ,     ,   
   ,  main(). TIME1.CPP   

     13.                                              311

,    TTime.    
  (,   )    . 
  TTime  ,     
  .    ,  
ime,          
 . 

     13.4.  TIME.CPP (  TTime) 

    1:	// timel.cpp --   Ttime 
    2: 
    3:	#include <iostream.h> 
    4:	#include <stdio.h> 
    5:	#include <dos.h> 
    6:	#include <string.h>
    7:	#include "timel.h" 
    8: 
    9:	//     
   10:	void TTime::Display(void) 
    11:	{ 
    12:	char s[30]; 
    . 13:	sprintf(s, "Date: %02d/9402d/%04d Time: %02d:%02d", 
    14:	month, day, year, hour, minute ); 
    15:	cout  s  '\n'; 
    16:	} 
    17: 
    18':	//   -    
    19:	void TTime::GetTime(int &m, int &d, int &y, int &hr, int &min) 
    20:	{ 
    21:	m = month; //  - ,    
    22:	d = day; 
    23:	 = year; 
    24:	hr = hour; 
    25:	min = minute; 
    26:	} 
    27: 
    28:	//  -   
    29:	void TTime::SetTime(int m, int d, int y, int hr, int min) 
    30:	{ 
    31:	month = m; //   - 
    32:	day = d; 
    33:	year = y; 
    34:	hour = hr; 
    35:	minute = min; 
    36:	} 
    37: 
    38:	//        
    39:	char *TTime::GetSTime(void) 
    40:	{ 
    41:	char buffer[40]; //   
    42:	char *cp; //   ,   43: 
    44:	sprintf(buffer, "Date: %02d/%02d/%04d Time: %02d:K02d\n", 
    45:	month, day, year, hour, minute ); 
    46:	cp = strdup(buffer); //      
    47:	return cp; 
    48:	}
    50:	//  nminutes (  )    
    51:	void TTime::ChangeTime(long nminutes) 
    52:	{ 
    53:	struct date ds; 
    54:	struct time ts; 
    55:	long timeinsecs; 
    56: 
    57:	ds.da_year = year; 
    58:	ds.da_mon = month; 
    59:	ds.da_day = day; 
    60:	ts.ti_hour = hour; 
    61:	ts.tijnin = minute; 
    62:	ts.ti_sec = 0; 
    63:	ts.ti_hund = 0; 
    64:	timeinsecs = dostounix(&ds, &ts); 
    65:	timeinsecs += (nminutes * 60); 
    66:	unixtodos(timeinsecs, &ds, &ts); 
    
    
    312	 III.   ANSI C++ 

    67:	year = ds.da_year; 
    68:	month = ds.da_mon; 
    69:	day = ds.da_day; 
    70:	hour = ts.ti_hour; 
    71:	minute = ts.ti min; 
    72:	} 

      ,   TIME.CPP   TTime,  
   13.5   ,    
     . (   , 
          .)  
   DOS  bcc appointl timel, ,     
   TIME1,  bcc appointl timel.obj.

     

      APPOINT.CPP   ,  
    1. ,    
,     DOS.  WINDOWS   
     APPOINT1.IDE    
Project\Open project...       
(APPOINT.CPP),   (TIME1.CPP)    East/Win  
APPOINT1.EXE         .  
    <Ctrl+F9>    , 
          
   .     ,  
     TIME1  DOS   EasyWin Windows, 
   Project\Build All.    
 local options  APPOINT1.EXE (      
),         
Borland C++.    ,    
     2. 

     13.5. APPOINT1.CPP (   ) 

    1:	#include <iostream.h> 
    2:	#include <stdio.h> 
    3:	#include "time1.h" 
    4: 
    5:	main() 
    6:	{ 
    7:	  TTime appointment; 
    8: 
    9:	  appointment,SetTime(7, 21, 1996, 8, 30); 
    10:	  for (int slots = 1; slots <= 17; slots++) { 
    11:	    appointment.Display(); 
    12:	    appointment.ChangeTime(30); 
    13:	  } 
    14:	  return 0; 
    15:	}

      3  TIME1.H,      
TTime  .   7    appointment  
TTime.   9  appointment     
,     for      
 30 .   12  - ChangeTime()   30 
      appointment.      
-     appointment. 
    ,   ,    TTime,   
1. ( 13.4),    - . -  
     .  -  
GetSTime() ( 39-48),         
 TTime,  ChangeTime() ( 51-72),    
       . 
       -  TTime::    
    TTime. - GetSTime()  sprintf() 
( 44)      - month, day, 
year, hour  minute,    .   
 46  strdup()        
     .   47  
  ,         free(). 
    - ChangeTime()      dostounixO  
unixtodosO           
  .      
    
     13.  	313 

 65      ,  
-     nminutes.    
( 13.5,  12)   appointment.ChangeTime(30);  
- ChangeTime()       appointment  30 . 
        -, C++    
,     appointment.  -   
      this.  - 
  this,    ,   
-  .   13.5,   12, - 
ChangeTime()   this,     appointment. 
 ,   -    ,  
   .
       this       . 
,  21   13.4     : 

    m = this->month; 

      ,      m 
 month    ,  this. ,  
       this.  
    m = month;     month    ,  
  this. 

      - 

             
     .   ,  
           (, 1 
 1970   DOS)       
 ,        . 
    - ChangeTime()   13.4  -   
    (timemsecs),       
    . ,   ,  
         . 
      13.6  13.7        
 TTime.  TIME2.H     TIME2.CPP   
 .        
  ,  APPOINT2.CPP,     mainO. 
     DOS,   bcc 
appoint2 time2.       
APPOINT2.EXE,   .       
         : 

    	- appoint2 
    bcc	- time2 
    	appoints.obj time2.obj 

     ,      "   "  
   C++.       
APPOINT2   ,    APPOINT2.IDE  
 <Ctrl+F9>,       APPOINT1.    
Project\Build all     (,   
  TIME2  DOS,       Windows). 

     13.6.  TIME2.H (  TTime) 

   1:  // time2.h --   TTime 
   2: 
   3:  #ifndef __TIME2_H 
   4:  #define _TIME2 H 1 //   include 
   5: 
   6:  class TTime { 
   7:  private: 
   8:     long dt; //    -    1  1970  
   9:  public: 
  10:   void Display(void); 
  11:   void GetTime(int &m, int &d, int &y, int &hr, int &min); 
  12:   void SetTime(int m, int d, int y, int hr, int min); 
  13:   char *GetSTime(void); 
  14:   void ChangeTime(long nminutes); 
  15:  } ; 
  16: 
  17: #endif // __TIHE2_H
    
    
    314 201	 III.   ANSI C++ 

     TTime  TIME2.H  TTime  TIME1.H   ,   
       dt.  
  month, day, year, hour  minute. ,  
  ,  -    ,     
 ,     TTime. 
     -   , ,   ,  
      .   
13.7   . 

     13.7.  TIME2.CPP (   TTime)	: 

    1:    // time2.cpp --   TTime 
    2
    3:	#include <iostream.h>
    4:	#include <time.h>
    5:	#include <dos.h>
    6:	#include <string.h>
    7:	#include "time2.h"
    8: 
    9:    //    ; 
    10:     void   TTime:: Display( void)) 
    11:     { 
    12:	cout  ctime(&dt) ; 
	    13:      } 
    14: 
    15:	//   - (                         
    16:	void TTine::GetTime(int &m,  int id,   int &y,  int &hr,  int &min)    
    17:	{ 
    18:	  struct date ds; 
    19:	  struct tine ts; 
    20: 
    21:	  unixtodos(dt,  &ds,  &ts); 
    22:	   = ds.da_year; 
    23:	  m = ds.da_mon; 
    24:	  d = ds.da_day; 
    25:          hr = ts.ti_hour; 
    26:          nin = ts.ti_min; 
    27:	} 
    28: 
    29:	//   dt 
    30:	void TTime::SetTime(int m,   int d,  int y,  int hr,  int min) 
    31:	{ 
    32:	struct date ds; 
    33:	struct time ts; 
    34; 
    35:	ds.da_year = ; 
    36:	ds.da_mon = m; 
    37:	ds.da day = d;                                 
    38:	ts.tilhour = hf 
    39:	ts.tijnin = min; 
    40:	ts.ti_sec = 0; 
    41:	ts.ti hund = 0; 
    42:	dt = dostounix(&ds, &ts); 
    43:	} 
    44: 
    45:	//        
    46:	char TTime: :GetSTime(void) 
    47:	{ 
    48:	char *cp = strdup(ctime(&dt));
    49:	return ; 
    50         } 
    51 
    52:	//  nninutes (  )   
    53:	void TTime::ChangeTime(long nminutes) 
    54:	{ 
    55:	dt += (nminutes * 60); 
    56:	} 

               
. ,          ,  
 12     ctime( )   
     ASCII. - GetTimeO  PutTimeO  
y ,   ,      
            
unixtodosO  dostounixO,  . 
    
    13.      -	315 202 

    - GetSTime()  ChangeTime()  ( 45-56). 
GetSTime()   ctime() strdup()  
      .     
ChangeTime(),    .      
   ,       
  . 
              
 .      C++   
       
,   .     13.8, 
    " "   ,   
 TTime. 
      . APPOINT2.CPP,  APPOINT1.CPP,  
  3,    TIME2.H  TIME1.H.  
        . 
,    10,000      TTime  
  ,    !      
          , 
     ,  
    . 

     13.8. APPOIN'2 CPP (   ) 

    1:	#include <iostream.h> 
    2:	#include <time.h> 
    3:	#include "time2 h" 
    4: 
    5:      main() 
    6      { 
    7:	TTime apooint~ent; 
    8 
    9:      appointment.SetTiee(7,  21.  1996. 8.  30); 
  10:      for ( int slots = 1:  slots <= 17; slots++ ) { 
  11:        appointment. DisplayO: 
  12:        appointment.ChangeTie(30); 
  13:       } 
  14:      return 0; 
  15:    } 


     - 

    ,       . C++ 
   ,      . 
,  -    -  
    .  -,  
SetTimeO,    -    
,       , 
,     . 
       ,  ,      
      ,   . 
         
         ? 
        -     
-     . ,   
   .   C++   
   -.   - 
   ,    ,     
 .    -  
    (. 13.3). 


     -    
     -      
    // 
    ,\		 
    ;	f1() 
     -			 
    ();            *	 - 
    t2();	 
     
    
    
    . 13.3.  -    
  


    316                                  III.   ANSI C++ 

     13.9    TTime    
 - ( 14  17-22).     , 
          
.   DOS,   bcc appoint3 time3,   
       APPOINT3.EXE.   
      APPOINT3.IDE   
<Ctrl+F9>    . 

     13.9.  (   TTime   -) 

   1:    // time3.h --   TTime 
   2  
   3:    #ifndef _I_ 
   4:    #define _TIME3_H 1 //  ((include 
   5:    
   6:    #include <iostream.h>                 
   7:    # include <time.h>                             
   8:    #include <string.h>                      
   9: 
  10:    class TTime { 
  11:     private:                                                            
  12:	  	long dt; //    -    1  1970  
  13:     public: 
  14:	 	void Display(void) { cout  ctime(&dt); } 
  15:	 	void GetTime(int &m, int &d, int &y, int &hr, int &min); 
  16:	 	void SetTime(int m, int d, int y, int hr, int min);                    
  17:	 	char *GetSTime(void) 
  18:		{ 
  19:	  		char *cp = strdup(ctime(&dt)); 
  20:	  		return cp; 
  21:		} 
  22:		void ChangeTime(long nminutes) { dt += (nminutes * 60);  } 
  23:     } ; 
  24: 
  25:   #endif // __IME_ 

          TIME3.H  
   13.10 c . 

     13.10.  TIME3.CPP (    TTime) 

   1:	// timeS.cpp --   TTime 
   2: 
   3:	#include <dos.h>                                                       
   4:	#include "timeS.h" 
   5:	
   6:	//   -                     
   7:	void TTime::GetTime(int &m, int &d, int &y, int &hr, int &min) 
   8:	{                                                : 
   9:		struct date ds;                                
  10:		struct time ts;                                      
  11:
  12:		unixtodos(dt, &ds. &ts);                 
  13:		y = ds.da_year; 
  14:		m = ds.da_mon; 
  15:		d = ds.da_day; 
  16:		hr = ts.ti_hour;                                                      
  17:       min = ts.ti min;	
  18:  }
  19: 
  20:	//   dt 
  21:	void TTime::SetTime(int m,  int d,  int y,  int ir, int min)
  22:	{ 
  23:		struct date ds;                                                        
  24:		struct time ts;                                                        
  25: 
  26:		ds.da_year = y; 
  27:		ds.da mon = m; 
  28:		ds.dalday = d; 
  29:		ts.tijiour = hr; 
  30:		ts.tijnin = min;                                                       
  31:		ts.ti_sec = 0; 
  32:		ts.ti_hund = 0; 
  33:		dt = dostounix(&ds, &ts); 
  34:	} 
    
     13.  	317 

       -    
  -,     
.  13.11  APPOINT2.CPP   ,   
 3     TIME3.H  TIME2.H. 
  ,   DOS  bcc appoint3 time3.  
       ,   
 APPOINT3.CPP  TIME3.CPP. 

     13.11.  APPOINT3.CPP (   ) 

    1:	#include <iostream.h> 
    2:	#include <stdio.h> 
    3:	#include "time3.h" 
    4:	 
    5:	main() 
    6:	{ 
    7:	TTime appointment; 
    8:	 
    9:	appointment,SetTime(7, 21, 1996, 8, 30); 
    10:	for (int slots = 1; slots <= 17; slots++ ) { 
    11:	appointment. Display() ; 
    12:	appointment.ChangeTime(30) ; 
    13:	
    14	return 0; 
    15:	}
      __________________________________________________ 


      14  1. ( 13.9)    
 -.       
 TTime: 

    class TTime { 
	private: 
    		long dt; 
	public: 
	    void Display(void)  { cout  ctime(&dt);   } 
    } 

     - DisplayO       
    .       
,      cout. .     
   C++,  ,        
.   ,     ,   
 -,    : 

  class TTime { 
   private: 
     long dt; 
   public: 
     void Display(void) 
     { 
       cout  ctirae(idt); 
     } 
  }; 

        ,     
     - ,    
. ,      Display(),   
    . ,      
     : 

    TTime today; 
    today.SetTime(4,   19,   1998,   6,  0); 

        - Display()   today:

    today. Display();	

       ,    ,      

    cout  ctime(&today.dt); 

    ,        , 
 dt     TTime , ,   . 

     

           , C++     
-    . ,  
 -  ,    
     . 
    
    318	 III.   ANSI C++ 

     -    ,   
   14  13.9.      
-     inline    . 
,   GetTime()  TTime   ,  
      13.10  : 

    inline void TTime::GetTime(in &m,   int &y,  int &hr,   int &mip) 
    {
      ....
    }

    ,  inline   ,     
 ,    -  
    ,     .  
   -   ,  
    . 

     - 

      12  ,   ,    
     ,  ,   ,  . 
        - . 
     -  ,    
 (  ) -. ,     
SetTime()  TTime   .     
  : 15  1997 , 11:45,    

    TTime anyTime; 
    anyTime.SetTime( 1,   15,   1997,   11,   45 ); 

    ,        , 
       .    
   TTime  - .  SetTime()
         
  ,     

    anyTime.SetTime( 1,   15,   1997); 

      13.12    TTime    
- SetTime().   TIME4.H    , 
,   .     
TIME4.H    . 

     13.12.  TIME4.H ( TTime   -) 

    1:	// time4.h --   TTime                                   
    2:	
    3:	#ifndef  __TIME4_H 
    4:	#define __TIME4 H 1 //   #include
    5:	 
    6:	#include <iostream. h>    
    7:	#include <time.h>       
    8:	#include <string.h>                
    9:	
    10:	class TTime {
    11:	private:                
    12:	  long dt; //    -    1  1970           
    13:	public: 
    14:	  void Display(void) { cout  ctime(&dt); } 
    15;	  void GetTime(int &im, int &id, int &y, int &hr, int &min); 
    16:	  void SetTime( int m, int d, int y, int hr, int min); 
    17:	  void SetTime( int m, int d, int y, int hr); 
    18:	  void SetTime( int m, int d, int y); 
    19:	  void SetTitne( int m, int d);                   
    20:	  void SetTime( int m);            
    21:	  void SetTime(void); 
    22:	  char *GetSTime(void) 
    23:	  { 
    24:	   char *cp = strdup(ctime(&dt)); 
    25:	   return cp;                                                             
    26:	  } 
    27:	  void ChangeTime(long nminutes) { dt += (nminutes * 60); } 
    28:    }; 
    29: 
    30:  #endif // __TIME4_H
     ______________________________________________________ 

      16-21    - SetTime().
             
 ,     

    
     13.  ,	319 

.     -   ,    
  ,       ,   
   13.13. 
      TIME4.CPP    main(), ,     
 ,    .       
 ,     ,  
 ,      . 

     13.13.  TIME4.CPP (  -) 
    
    1:	// time4.cpp --   TTime 
    2: 
    3:	#include <dos.h> 
    4:	#include "time4.h" 
    5: 
    6:	//   -    
    7:	void TTime::GetTime(int &m, int &d, int &y, int &hr, int imin) 
    8:	{ 
    9:	struct date ds; 
    10:	struct time ts; 11: 
    12:	unixtodos(dt, &ds, its); 
    13:	 = ds.da_year;            
    14:	m = ds.dajnon; 
    15:	d = ds.da_day; 
    16:	hr = ts.ti_hour;                                           
    17:	min = ts.tijnin; 
    18:	} 
    19: 
    20:	//   dt 
    21:	void TTime::SetTime(int m, int d, int y, int hr, int min) 
    22:	{ 
    23:	struct date ds; 
    24:	struct time ts; 
    25:	
    26:	getdate(ids); //      
    27:	gettime(&ts); 
    28:	if ( >= 0) ds.da_year = ; 
    29:	if (m >= 0) ds.da_mon = m; 
    30:	if (d >= 0) ds.da_day = d; 
    31:	if (hr >= 0) ts.ti hour = hr; 
    32:	if (min >= 0) ts.ti_min = min; 
    33:	ts.ti_sec = 0;         
    34:	ts.ti_hund = 0;                 
    35:	dt = dostounix(ids, its);  : 
    36:	}                   
    37: 
    38:	void TTime::SetTime(int m, int d, int y, int hr) 
    39:	{ 
    40:	SetTime(m, d, y, hr, -1);  
    41:	} 
    42: 
    43:	void TTime: : SetTime(int m, int d, int y)  
    44:	{ 
    45:	SetTime(m, d, y, -1. -1); 
    46:	} 
    47: 
    48:	void TTime::SetTime(int m,   int d) 
    49:	{                                                                      
    50:	SetTime(m,  d,  -1,   -1,   -1); 
    51:	} 
    52: 
    53:	void TTime::SetTime(int m)    = 
    54:	{ 
    55:	SetTime(n,   -1,   -1,   -1,   -1); 
    56:	} 
    57:	
    58:	void TTime::SetTime(void) 
    59:	{
    60;	 SetTime(-1,   -1,   -1,   -1,   -1);                                   
    61:	}
    ___________________________________________________ 

    ,   - SetTime()   1-36  
  getdateO  gettimeO      
 .     SetTime() -
    
    320	 III.   ANSI C++ 

 -         
   ,           
,   .  -today - ,  , 

   today.SetTime( O,  15,  1998,  -1,  -1);          

 ,   today,  15  1998 
,    ,       -1. 
      ,       
,   .     

    today.SetTime(1, 15, 1998);

         -    
 ( 43-46),     
 .  ,    
- SetTimeO ,      , 
  .   -  
       SetTime()   
. ,  

    today.SetTime() ;	

  - SetTime(),    
58-61    , ,   ,    
     today    . 
      13.14    
- TTime.      TIME4.H  
DOS,   bcc overmf time4.     
  OVERMF.EXE,   .      
   Project    OVERMF. IDE    
<Ctrl+F9>    .

     13.14.  OVERMF.CPP (  -)

    1:	#include	<iostream.h> 
    2:	#include	<stdio.h> 
    3:	#include	"time4.h"
    4:	
    5:	main()
    6.      {
    7:           TTime appointment;
    9:	appointment.SetTime();
    10:	appointment.Display();            
    11:	appointmentSetTime(8); 
    12:	appointment.Display(); 
    13:	appointment.SetTime(8, 1);
    14:	appointment.Display ( );            
    15:	appointment.SetTime(8, 1, 1996);     
    16:	appointment.Display(); 
    17:	appointment.SetTime(8, 1, 1996, 8); 
    18:	appointment.Display(); 
    19:	appointment.SetTime(8, 1, 1996, 8, 30); 
    20:	appointment.Display(); 
    21:	return 0; 
    22:      } 

      9-20    - SetTime(),  
     ,    Display().   
   Display()      SetTime(). 

     -   

      -,     
16-21  13.12, ,       .  
   -     
 -,       
 . 
      12        
.  -      ,   , 
   ,      .  
 13.15,     SetTime()  TTime, 
   .     , TIME5.H 
  ,    .    
  ,      ,  
,    TTime. 

     13.  	321 
    
    11   Borland C++4.5 

     13.15. TIME5.H (   TTime   
 -  ) 

    1: // time5.h --   TTime 
    2:   #ifndef __TIME5_H 
    3: 
    4:   #define _TIME5_H 1 //   #include 
    5:   #include <iostream.h> 
    6:   #include <time.h> 
    7:   #include <string.h> 
    8:
    9:
    10:	class TTime {
    11:	private:	
    12:	  long dt; //    -   	1  1970  
    13:	public: 
    14:           void Display(void) { cout  ctime(&dt) }
    15:	  void GetTime( int &m, int &d, int &y, int &hr, int imin ) ; 
    16:	  void SetTime(int m =	-1, int d =	-1, int	 = -1, 
    17:	                           int hr = -1, int min = -1 ) ; 
    18:	  char *GetSTime(void) 
    19:	  {
    20:	     char *cp = strdup(ctime( &dt ) );			
    21:	    return cp;
    22:	  }			i 
    23:	  void ChangeTime( long nminutes ) { dt += (nminutes * 60) ;  }              
    24:      }; 
    25: 
    26:     #endif // __TIME5_H 
    
       SetTimeO   16-17    
 -1,       
  -.        
     -.     
TTime   today  
    
    today.SetTime(15,1998);	

  15  1998     SetTimeO.  
     ,    
    -1,     
,                                                   

    today. SetTime(1,   15,   1998,   -1,   -1); 

       TTime       
- SetTime().   13.16  .  TIME5.CPP 
  ,    ,      
 . 
     -         
 21.         -. 
      13.17    TTime. ,   
   -     
      SetTime().   
 ,      . ,    
  .        
 TIME5,   DOS bcc default time5.     
   Easy Win-,     Project 
  DEFAULT. IDE   <Ctrl+F9>. 

     13.16.  TIME5.CPP (   TTime) 

    1:   // time5.cpp    TTime 
    2: 
    3:      #include <dos.h> 
    4:      #include "time5.h" 
    5:
    6:	//   -    
    7:	void TTime:: GetTime( int &m, int &d, int &y, int &hr, int &min) 
    8:	{ 
    9:	  struct date ds; 
    10:	  struct time ts; 11: 
    12:	  unixtodos(dt, &ds, &ts); 
    13:	   = ds.da_year; 
    14:	  m = ds.da_mon;                                 
    15:	  d = ds.da_day; 


    322       III.   ANSI C++ 

    16:         hr = ts.ti_hourr;  
    17:	min = ts.ti_min;
    18:         }
    19:
    20:      //   dt                                      
    21:      void TTime::SetTime(int m,  int d,  int y, int hr,  int min) 
    22:      {
    23:	struct date ds; 
    24:	struct time ts;                  
    25:
    26:	getdate(Sds);  //      
    27:	gettirae(&ts); 
    28:	if ( >= 0) ds.da_year = ; 
    29:	if (m >= 0) ds.da_mon = m; 
    30:	if (d >= 0) ds.da_day = d; 
    31:	if (hr >= 0) ts.ti_hour = hr; 
    32:	if (min >= 0) ts.tijnin = min; 
    33:	ts.ti_sec = 0; 
    34:	ts.ti_hund = 0; 
    35:	dt = dostounix(&ds,  &ts); 
    36:	} 
    
     13.17.  DEFAULT.CPP (  -  ) 

    1:	#include <iostream.h>               
    2:	#include <stdio.h>     
    3:	#include "times. h"	
    4:		
    5: 
    6:	main()          
    7: 
    8.	TTime appointment;   
    9:	appointment . SetTime( ) ; 
    10:	appointment . Display ( ) ; 
    11:	appointment. SetTime(8);	
    12:	appointment . Display ( ) ;	
    13:	appointment. SetTime( 8, 1); 
    14:	appointment. Display( ) ; 
    15:	appointment. SetTime(8, 1, 1996); 
    16:	appointment . Display( ) ; 
    17:	appointment. SetTime(8, 1, 1996, 8); 
    18:	appointment. Display( );	
    19:	appointment. SetTiue(8, 1. 1996, 8,. 30);	
    20:	appointment . Display ( ) ;	
    21:	return 0;	
    22:	} 


       


             . 
     TTime. 	

    TTime anyTime ;    
    
   anyTime  TTime,     
-.      ,  

   anyTime.Display(); 

     ,   ,    . 
             
     ,    
  ,    
.       (  ) , 
         . 
      -,    
    . C++   
        . 
      13.18      TTime.   
         TTime. 
          TTime,  
  .    .     . 

    13.        323 

     13.18. TIME6.H (  TTime    ) 

    1:   // time6.h --   TTime 2: 
    3:   #ifndef __TIME6_H 
    4:   #define __TIME6_H 1 //   include 5: 
    6:   #include <iostream.h>	
    7:   #include <time.h>           
    8:   #include <string.h> 
    9:
    10:	class TTime {
    11:	private:
    12:	   long dt; //    -    1  1970  
    13:	   char *dts; // 	      
    14:	   void DeleteDts(void); //   tits 
    15:	public: 
    16:	  TTime() ; //  
    17:	  TTime( int m, int d = -1, int y =	-1,	//	 
    18:		int hr = -1, int min = -1) ; 
    19:	 ~TTime(); //  
    20:	 void Display(void) { cout 	ctime(Sdt);			}
    21:	 void GetTime( int &m, int &d,	int &y, int	&hr, int tain ) ; 
    22:  	 void SetTime(int m = -1, int d =	-1, int y = -1
    23:	 	       int hr = -1, int min = -1);				
    24:		const char *GetSTime(void);				
    25:	void ChangeTime(long nminutes)                                         
    26:	{ dt += (nminutes * 60); DeleteDts(); } 
    27:	}
    28: 
    29:	#endif // __TIHE6_H 

       -,    
,       (  
,    ). ,  , 
   ,       .  
    ,   ,   .   
    . 
      16  TTime()     TTime. 
    ,    . 
  17-18      TTime.  
      ,        
  ,      
   -1.  TTime     19 ,   
   . 
            TTime    
.   13        
 dts.         
.    ,        
      ,     
 .   14   - 
DeleteDts(),  ,    dts.  
-     -  ,  
   ,   .    
   DeleteDts()   ,   
 dts.      . 
        ,   
TTime   13.19.       TTime, TIME6.CPP  
 ,     main(), ,  
  ,      .   
 ,       . 

     13.19.  TIME6.CPP ( TTime)

    1:   // time6.cpp --   TTime 
    2: 
    3:   #include <dos.h>	
    4:   #include "time6.h" 
    5: 
    6: //    
    7: TTime::TTime() 
    8: { 
    9:   dts = NULL; //    
  10:   SetTime(-1, -1, -1, -1, -1); 
  11: } 
  12:	
    

    324	 III.   ANSI C++ 

    3:	//   
    4:	TTime::TTime( int m, int d, int y, int hr, int min )
    3:	{ 
    16:	  dts = NULL; //    
    17:	  SetTime(m, d, , hr, min); 
    18:	} 
    19: 
    20:	//         
    21:	TTime::~TTime()
    22:	{ 
    23:	  delete dts; //  ,    
    24.	} 
    25: 
    26:	//   dts             
    27:	void TTime::DeleteDts(void) 
    28:	{ 
    29:	  delete dts; //  ,    
    30:	  dts = NULL; //   
    31:	} 
    32: 
    33:	//   -    
    34:	void TTime::GetTime(int im, int &d, int &y, int &hr, int &min) 
    35:	{ 
    36:	  struct date ds;                
    37:	  struct time ts;                
    38: 
    39:	  unixtodos(dt, &ds, its); 
    40:	   = ds.da_year; 
    41: 	  m = ds.dajnon; 
    42:	  d = -ds.da_day; 
    43;	  hr = ts.ti_hour; 
    44:	  min = ts.tijnin; 
    45:	} 
    46: 
    47:	//   dt 
    48:	void TTime::SetTime(int m,  int d,  int y,  int hr,  int min) 
    49:	{ 
    50:	  struct date ds; 
    51:	  struct time ts; 
    52: 
    53:	  getdate(ids);   //                  
    54:	  gettime(its); 
    55:	  if ( >= 0) ds.da_year =  ;                                        
    56:	  if (m >= 0) ds.dajnon = m ;                                    
    57:	  if (d >= 0) ds.da_day = d ; 
    55:	  if  (hr >= 0) ts.tijiour = hr ;             
    59:	  if (mm >= 0) ts.tijnin = min;                  
    50:	  ts.tijsec = 0 ;
    61:	  ts.tijiund = 0;                                                 
    62:	  dt = dostounix(&ds,  &ts);                                         
    63:	  DeleteDts();  //    
    64:       }                                                           
    65: 
    66:	const char *TTime::GetSTime(void) 
    67:	{                                                                      
    68:	  if (dts)  //   ,     
    69:	    return dts; 
    70:	  dts = strdup(ctime(&dt));                                              
    71:	  return dts;                                                            
    72:	} 

      7-11   TTime    TTime().    
   -,     
     .     
TTime::TTime(), ,    ,     
   TTime(),    TTime (. 13.4). 
            
  -   . , 
      
 - ,  ,   
,  ..      16   dts 
  NULL,  ,       
.  C++      
  TTime, ,      
 -
    
    
     13.  	325 

 dts.    - SetTime()   
  -1 ( 10),       
   . 

      
        
        
    /       
    =^^^ 
    TTime::TTime() ^^ 
       

    . 13.4.     

          14-18.    
  ,          
     .  
    -.      
  ,  ,  ,   
     .    
   ,     , , 
  . 

      

         ,       
  .          . 
        
.   13.20     TTime 
 TTime().      TIME6  
  DOS,  bcc construc time6.    
     CONSTRUC.EXE    . 
       CONSTRUC.IDE   
 Project   <Ctrl+F9>        
 EasyWin. 

     13.20.   CONSTRUC.CPP (  TTime) 

    1:	#include <iostream. h> 
    2:	#include <stdio.h> 
    3:	#include "time6.h"    
    4: 
    5:	main() 
    6:	{ 
    7:	 TTime t1; 
    8:	 TTime t2(8); 
    9:	 TTime t3(8,   1);
  10:	 	 TTime t4(8,   1, 1996);     
  11:	 	 TTime t5(8,   1, 1996,   8 ) ; 
  12:	 	 TTime t6(8,   1, 1996,  8, 30) ;
  13:  
  14:	  	 t1.Display(); 
  15:	 	 t2.Display();		
  16: 	 t3.Display();
  17: 	 t4.0isplay();
  18: 	 t5.Display();
  19:        t6.Display();	
  20:	 	 return 0 ; 
  21:		} 

      7-12     TTime. C++  
     . ,   
   tl,    d  7,  
     . 
      8-12     ,   t2 
  t6,       .   
     ,      
TTime    - SetTime()   

    326      III.   ANSI ++

 - . ,    
        .   
    ,   
         
  . 

    

         ,    
     TTime    
 Project  CONSTRUC.IDE,   CONSTRUC.CPP    
 ,          mane()  
 <F5>       .   
     .      
    .  <Ctrl+F9>     
.      .    
,     ,  <F9>    
 .       .  
<Ctrl+F9>          
   <F7>     ,       
  .      ,   
  .

      

           TTime  
TIME6.H  TIME6.CPP ( 13.18  13.19),   ,  
           
.   13.21,   DOS  bcc destruc timeG 
        Project   
DESTRUC.IDE;  <Ctrl+F9>       
 Easy Win.  DESTRUC   TIME6   
     TIME6   DOS, ,  , 
   Project\Build all     

     13.21.   DESTRUC.CPP (  TTime) 

    1:   #include <iostream.h> 
    2:   #include <stdio.h> 
    3:   #include "time6.h" 
    4: 
    5:   void f(void); 
    6: 
    7:   main() 
    8:    { 
    9:       f(); 
   10:     return 0; 
   11:    } 
   12: 
   13:   void f(void) 
   14:    { 
   15:     TTime today; 
   16:     const char *sp; 
   17: 
   18:     sp = today.GetSTime(); 
   19:     cout  "First time:   "  sp ; 
   10:     sp = today.GetSTime(); 
   11:     cout  "Second time:   "  sp; 
   12:    } 
    
     main()  DESTRUC.CPP    f(),   
 13-22.     15    
 TTime today,     .   
      ,    
, C++   today  Ttime()     
 ,    .    
    . (      
     .) 
      18-21  - GetSTime()    
today.         sp. 
   13.19,     GetSTime() ( 
66-72). -  ,     dts .  
,   dts,   strdup()  ctimeO   
      ,      
  dts    .  

     13.       327 

,   GetSTime()     
.        
        , 
       
 . 
       TTime   dts,   
  ,       
.   TTime        
    ,     , 
   .  ,       
TTime  (,     ChangeTime()  SetTime()),  
  dts       ,  
        GetSTime(). 
      TIME6.H ( 13.18)    19,   
    TTime.     
  ,      .     
     ,     (   
).      (~),  
     .    
: ,   ,    . 
           -.  
  ,   .   
13.19   21-24     TTime: 

    TTime:: ~TTime() 
    { 
       delete dts;  //  ,      
    } 

     ,    -,   -TTimeO 
        TTime::, 
      .    
 TTime  dts. (   dts   
 ;  delete   -.) 
          , C++  
   ,   .    
   ,   ,  
  -. 
    :  ,  .    
 , ,     
 . ,       , 
           
 .   -  ,  
  -,   switch    
     . 

    ""  

            .   
  ,       
 .   ,     ,    
 ,  ,     . 
     ,  :    , , 
   ..    ,    
     .    C++ 
         
,      .     
 , C++   .  . 13.5   
        , 
   . 
       ,     
     . 

       

            
 main().        
   .    TTime 
( 13.18  13.19)   

    TTime today;	

    328             III.   ANSI C++ 

   today  TTime.    main() C++ 
  today  ~irae  ,    
    . 

   Co   

   ++    

        

     -                 

         
C++   ,   
   

    0       t+1 t+2 t+3 t+n 

    . 13.5. ,        

         TTime - 
       : 

   TTime someTime( 9,  4, 1953, 10,  45) ; 

           C++   
  TTime ,    .    C++ 
   TTime ( 17-18  13.18),   
 someTime     4  1953 , 10:45. 
 ,     ,    main(). 
             
   ,     ,  
  atexitO (.   Borland C++ 4.5.  ). , 
  ,        abort(). 

       

      ,    ,  
        .    
 , -      
.  

    void anyFunction(void) 
    { 
       TTime now;     //       
    } 
    
        TTime     
now      ,   . 
       , C++   TTime   
now,     ""    ,     
 . 
       exit()  ,   ,  
     ,    
  ,    (  , 
   mainO),  .

       

          ,   
       new.     
pToday     TTime  : 

    TTime *pToday; 

         ,     .   
 , pToday     ,  
  new: 

    pToday = new TTime; 

        new       
 TTime.       pToday.   , 
C++     ,     
     . 
            
. ,      TTime     
        :

    pToday = new TTime(9,   4,   1953,   10,   45); 

     13.      329 

            ,   
    . ,      
   TTime,    pToday: 

    pToday->Display(); 

       ,        
      ->      
. ,      *    
 . ,  

    sp = (*pToday).GetSTime(); 

      sp ( ,  const char *sp;) 
 - GetSTLmeO   ,    
pToday. ,  

    sp = pToday->GetSTime(); 

        . 
    C++        .  

    delete pToday; 

     ,    pToday,    
     .   
  C++   ,   
     ,   
,. ,     TTime    
,     dts. 

     

          ,    . 
     ,    ,  
      ,    new  
   delete. ,  ,  
  ,         
.  ,    ,   
      .   f(),   
 new     ,       
  .        
,    ,         . 

      

         . ,   
   TTime: 

    TTime today;   //   today 

    ,  ,      today  : 

    TTime &rToday = today;	//   today 

     rToday    today,     today. 
,         : 

    rToday.Display() ; 
    today. Display() ;

          ,    
       , ,  
       .   
       . 
                
  ,     . 

    -

        ,       
     .     ,    
  ,     ,    
 .  :	

    void anyFunction(TTime t)	
   { 
     t. Display() ; 
   } 

    330      III.   ANSI C++ 

     anyFunctionO    t  TTime.   
 - Display()  t     ,  
 .      TTime:

   TTime  today;                                                       

       anyFunction():

   anyyFunction( today ) ;

             . 
           
        .  
   -:

    Function (TTime *tp) 
    {
        tp->Display();	
    }

        anyFunction()      
 TTime   :

    anyFunction(&today); 

    ,       . 
,         . 
  ,      ,  
        .   
 anyFuuctionO,         
  TTime: 

          void anyFunction(TTime &tr)      // tr -  	
          {
             tr.Display() ;	//  Display()  ,    tr                                   
          }
 
     -         TTime 
     anyFunction():	

     anyFunction(today);

         ,    
    today  .    anyFunction()
  today     .

       	

            
   .    ,  
   TTime:

   TTime newTime(void) 
   { 
      TTime t; 
      return t; 
   } 
   
   t (    
   )  .  newTimeO 
   : 

    TTime anotherTime = newTime() ;	.          

        newTimeO   anotherTime.   
  ,      TTime   : 

      TTime anotherTime ;  //                                     

            . , 
 ,       TTime   
 : 

    TTime *newTimeP(void) 
    {
      TTime *p = new TTime;      //     
       return p;	//        
   } 

         TTime     
TTime,    new.     , 
 ,     ,  ,  
    .    newTime()  
         TTime,  
tp: 

   Time *tp = newTimeP() ; 

     13.  	331 

    ,        .    
       ,   
  TTime today: 

   TTime &newTimeR(void) 
   {
      return today; 
   }

    -         TTime   
  newTimeR():

   TTime &tr = newTimeRO;

     tr    today      : 

     newTimeP().Display(); 

         ,  ,  newTimeR(),  
            
TTime,     . 

       

     ,        ,   
    . ,    
  10   TTime: 

    TTime tenTimes[10]; 

        ,   : 
 ,    ,     
.     ,  tenTimes, C++ 
        .   
 tenTimes, C++  10     TTime,  
   tenTimes[0]  tenTimes[9]    . 
     13.22      
.     TTime,    TIME6.H. 
    DOS  bcc obarray1 time6  
      OBARRAY1.EXE   
 .         Project  
 OBARRAY1.IDE   <Ctrl+F9>    . 

     13.22.  OBARRAY1.CPP (    )

    1:	#include <iostream.h> 
    2:	#include <stdiovh> 
    3:	#include "times.h"
    4: 
    5:           main()
    6:	{
    7:	  TTime tarray[6] ;
    8:
    9:	  for (int i=0;   i < 6; i++ )
    10:	    tarray[i].Display(): 
    11:	  return 0; 
    12:	} 

      7   tarray    TTime.   
 OBARRAY1,       ,  C++ 
       . 
(     Turbo Debugger   <F7>  
     ,   TTime  
  .) 
      ,  C++   ,    
    .     
   ,      13.23. 
 ,       OBARRAY1. 

     13.23.  OBARRAY2.CPP (    ) 

    1:	#include <iostream.h> 
    2.	#include <stdio.h> 
    3:	#include "timee.n" 
    4: 
    5:	main()                                                                
    6:	{                                         .                       
    7:	TTime tarray[6] = {   TTime(), TTime(8), 


    332      III.   ANSI C++ 

    10:	TTime(8,   1), 
    11:	TTime(8,   1,  1996), 
    12:	TTime(8,   1,  1996,  8), 
    13:	TTime(8,   1,   1996,   8,   30) 
    14:	}; 
    15:	for (int i = 0;   i < 6;   i++) 
    16:	   tarray[i].Display() ;
    17:	return 0; 
    18:        }

      7-14,    OBARRAY1.CPP,      
TTime. ,       
,   ,  ,    
 .   8   tarray[0]    
   TTime.   9-13   
     . 
             
   ,      
.      , ,  
 ,   OBARRAY1,      
   . ,   OBARRAY2, 
         
   . 
               
 .          
  .   13.24   
.  ,       OB ARRAY 1. 

     13.24.   OBARRAY3.CPP (    )	-is. 

    1:	#include	<iostream.h> 
    2:	#include	<stdio.h> 
    3:	#include	"time5.h" 
    5;	main() 
    6:	{ 
    7:	  TTime *tarrayP; 
    9:	  tarrayP = new TTime[6]; //    
    10:	  for (int 1=0; i < 6; i++) 
    11:	    tarrayP[i].Display(); 
    12:	  delete[] tarrayP; //      delete[] 
    13:	  return 0;     
    14:	} 

      7  tarrayP       
TTime.      9  new,   
     TTime   tarrayP   
 .      new C++    
     TTime    
  . 
           ,    
       . , 
    . -    C++ 
         
 delete[]        
     .    12  
OBARRAY3    

    delete tarrayP;	// ??? 

     ,    tarrayP     
 TTime    .   ,  tarrayP 
  ,      delete: 

    delete[] tarrayP;         //     TTime. 

             
 . 

     

       C++       
          
 delete[6] tarrayP        TTime,  
  tarrayP      ,  
Borland C++      delete[]    
   ,     "Array size for 
'delete' ignored in function x<)" (   delete   
 ()).


     13.   333 

     

    - ,  ,   
       . 
     C++           
 ,     , ,  int  
double.     ,     . 
       ,        .  
    ,      
 . 
        public  ,   
       .    
    ,     
private.  -        
-     -.     14 
      protected. 
        . ,     
  private      . 
    -     ,    ,  
           
.    -,   void f(void);,
  void T::f(void);,  ,   f()   
 . 
     -       this, 
  ,      .    
   - T::f() this   . 
                this       ,    
   -         . 
              ,    
     ,   .   
   ,       
  .	
      -    
 .  ,   inline     
,      ,  ,  .  
        
  inline    -. 
       , -   .   
    ,      ,  
,              . 
     -            ,   
       . 
,  -        
 . 
    -        
,    . 
              
    .   
  ,   ,    ,       
.       .  
      ,    
      .    
     ,      ,   
. C++        . 
          (  ).  
   ,    - 
 ,       . C++  
,           . 
         .    
  ,  C++        
.          
   . 
            C++  
      . 
                   
new,          .   ,   
   C++        ,  
 delete[] (  )   delete ( ),  
    .   delete  
       . 

    334  III.   ANSI C++ 

     

     

      ,     TTime,     
  TLME6.H ( 13.18)     TIME6.CPP 
( 13.19). 
    13.1.   ,      
,    /.     
  -     .
    13.2.    TTime ( 13.18  13.19)   
DT.CPP,     . 
    13.3.       13.2,  , 
       . 
    13.4.   TTime,     DAY.CPP, 
     ,      
DOS. ,  day jan 5 1997      
 . 
    13 5.  -   TTime       
,      ,   
  1  1970 .      
  TTime      .    
    -. 
    13 6.  ,     .  
         
     .     
   .      
       . 
    13 7.  ,       
13.6      . 

     13.   335 

