C++ #1

profiletheman04
advanced_c_week_1.zip

Advanced C++ Week 1/cityinfo.txt

APN 45.07 83.57 E ATL 33.65 84.42 E DCA 38.85 77.03 E DEN 39.75 104.87 M DFW 32.90 97.03 C DTW 42.23 83.33 E GRR 42.88 85.52 E JFK 40.65 73.78 E LAF 40.42 86.93 E LAN 42.77 84.60 E LAX 33.93 118.40 P MBS 43.53 84.08 E MIA 25.82 80.28 E MQT 46.53 87.55 E ORD 41.98 87.90 C SSM 46.47 84.37 E TVC 44.73 85.58 E YYZ 43.67 79.63 E

Advanced C++ Week 1/datefun.cpp

Advanced C++ Week 1/datefun.cpp

// This file includes implementations for date functions

#include   < iostream >
#include   < string >
using   namespace  std ;

#include   "datefun.h"

//-----------------------------------------------------------------  
// This function receives an integer year and returns true if the
// year is a leap year and false otherwise.

bool  leapYear ( int  theYear )
{
   if   (  theYear  %   400   ==   0   ||
      (  theYear  %   4   ==   0   &&  theYear  %   100   !=   0   )   )
      return   true ;
   else
      return   false ;
     
}    // end function leapYear

//-----------------------------------------------------------------  
// This function receives an integer month and year and returns an 
// integer of the number of days in the month.  Leap years are
// considered.

int   DaysInMonth ( int  theMonth ,   int  theYear )
{
   int  days  =   0 ;
  
   // 31 Day theMonths
   if   ( theMonth  ==   1   ||  theMonth  ==   3   ||  theMonth  ==   5    ||
      theMonth  ==   7   ||  theMonth  ==   8   ||  theMonth  ==   10   ||
      theMonth  ==   12   )  
         days  =   31 ;
            
   // 30 Day theMonths
   else   if   ( theMonth  ==   4   ||  theMonth  ==   6   ||  
           theMonth  ==   9   ||  theMonth  ==   11   )  
         days  =   30 ;
            
   // February
   else    // theMonth == 2
      if   (  leapYear ( theYear )   )
        days  =   29 ;
      else  
        days  =   28 ;  

   return  days ;
    
}    // end function DaysInMonth

//-----------------------------------------------------------------  
// This function receives a valid calendar date and returns the Julian
// date (the day number of the date in that year).

int  julianDate ( int  theMonth ,   int  theDay ,   int  theYear )
{
   int  dayCnt  =   0 ;
   int  mon ;
   for   ( mon  =   1 ;  mon  <  theMonth ;  mon ++ )             
     dayCnt  +=   DaysInMonth ( mon , theYear );         
  dayCnt  +=  theDay ;
  
   return  dayCnt ;
  
}    // end function julianDate

//-----------------------------------------------------------------  
// This function validates a calendar date and returns 'true' if
// all three components  represent a valid date and 'false' otherwise

bool  validDate ( int  mon ,   int  day ,   int  yr )
{
    bool  valDate  =   true ;     // Assume a good date
   
    // Test for conditions that would make the date validity false
    if   ( yr  <   1900 )
      valDate  =   false ;
    if   (( mon  <   1 )   ||   ( mon  >   12 )   ||   ( day  <   1 )   ||   ( day  >   31 ))
      valDate  =   false ;
    else   if   ((( mon  ==   4 )   ||   ( mon  ==   6 )   ||   ( mon  ==   9 )   ||   ( mon  ==   11 ))   &&   ( day  ==   31 ))
      valDate  =   false ;
    else   if   (( mon  ==   2 )    &&  leapYear ( yr )   &&   ( day  >   29 ))
     valDate  =   false ;
    else   if   (( mon  ==   2 )    &&   !  leapYear ( yr )   &&   ( day  >   28 ))
     valDate  =   false ;
      
   return  valDate ;
}    // end function validDate
   
//-----------------------------------------------------------------  
// This function receives a valid date and returns a date code for the
// day of the week.  It counts the number of days since 1/1/1900
// which was on a Sunday.  Output is: 0=Sun,1=Mon, ..., 6=Sat.

int  weekDay ( int  mon ,   int  day ,   int  year )
{         
     int   DayCnt ;
     int  daynum , i ;

     DayCnt   =   ( year  -   1900 )   *   365 ;     
     DayCnt   +=   (( year  -   1900 )   /   4 )   +   1 ;
     for   ( i = 1 ; i <= mon - 1 ; i ++ )
     switch ( i )
     {
         case   2 :       DayCnt   += 28 ;   break ;
         case   4 :
         case   6 :
         case   9 :
         case   11 :       DayCnt   += 30 ;   break ;
         default :      DayCnt   += 31 ;  
     };
    
     if   ((( year  -   1900 )   %   4   ==   0 )   &&   ( mon  <=   2 ))
         DayCnt -- ;
     DayCnt   +=  day ;
    daynum  =   ( DayCnt   -   1 )   %   7 ;
    
     return  daynum ;
}   // end function weekDay 
   
//-----------------------------------------------------------------  
// This function receives a day code and returns the string (2nd
// parametere with the three-character day of the week descriptor
// (0=Sun,1=Mon, ..., 6=Sat)
void  dayCode ( int  code ,   char  descript [])
{         
      switch ( code )
      {
           case   0 :  strcpy ( descript ,   "SUN" );   break ;
           case   1 :  strcpy ( descript ,   "MON" );   break ;
           case   2 :  strcpy ( descript ,   "TUE" );   break ;
           case   3 :  strcpy ( descript ,   "WED" );   break ;
           case   4 :  strcpy ( descript ,   "THU" );   break ;
           case   5 :  strcpy ( descript ,   "FRI" );   break ;
           case   6 :  strcpy ( descript ,   "SAT" );   break ;
      };   // end switch
}


Advanced C++ Week 1/datefun.h

// These functions include various date manipulation algorithms //----------------------------------------------------------------- // This function receives an integer year and returns true if the // year is a leap year and false otherwise. bool leapYear(int theYear); //----------------------------------------------------------------- // This function receives an integer month and year and returns an // integer of the number of days in the month. Leap years are // considered. int DaysInMonth(int theMonth, int theYear); //----------------------------------------------------------------- // This function receives a valid calendar date and returns the Julian // date (the day number of the date in that year). int julianDate(int theMonth, int theDay, int theYear); //----------------------------------------------------------------- // This method receives a calendar date and returns a boolean value // defining the validity of the date. bool validDate(int mon, int day, int yr); //----------------------------------------------------------------- // This function receives a valid date and returns a date code for the // day of the week. It counts the number of days since 1/1/1900 // which was on a Sunday. Output is: 0=Sun,1=Mon, ..., 6=Sat. int weekDay(int mon, int day, int year); //----------------------------------------------------------------- // This function receives a day code and returns the string (2nd // parametere with the three-character day of the week descriptor // (0=Sun,1=Mon, ..., 6=Sat) void dayCode(int code, char descript[]);

Advanced C++ Week 1/delta99Wx.txt

1 1 1999 12.7 4.5 0.00 1 2 1999 20.9 9.5 0.04 1 3 1999 24.2 14.4 0.28 1 4 1999 19.3 12.1 0.00 1 5 1999 12.1 -1.8 0.00 1 6 1999 21.6 1.4 0.00 1 7 1999 13.6 0.0 0.00 1 8 1999 15.0 2.7 0.07 1 9 1999 20.3 1.1 0.00 1 10 1999 12.6 0.5 0.00 1 11 1999 9.1 -4.7 0.02 1 12 1999 16.0 7.3 0.11 1 13 1999 12.9 4.7 0.00 1 14 1999 11.2 1.5 0.00 1 15 1999 17.5 3.7 0.01 1 16 1999 38.0 17.5 0.02 1 17 1999 40.7 16.1 0.21 1 18 1999 41.0 32.1 0.16 1 19 1999 34.0 22.0 0.00 1 20 1999 34.5 14.5 0.00 1 21 1999 35.3 22.4 0.00 1 22 1999 41.6 32.6 1.11 1 23 1999 52.7 35.4 0.07 1 24 1999 35.4 29.9 0.02 1 25 1999 31.8 25.7 0.13 1 26 1999 30.9 22.3 0.00 1 27 1999 41.1 22.9 0.00 1 28 1999 36.7 26.6 0.02 1 29 1999 34.7 20.7 0.00 1 30 1999 35.6 24.1 0.00 1 31 1999 38.2 22.8 0.00 2 1 1999 39.4 24.2 0.00 2 2 1999 41.4 32.7 0.07 2 3 1999 44.1 32.7 0.02 2 4 1999 38.5 20.6 0.01 2 5 1999 32.9 20.2 0.00 2 6 1999 42.4 29.1 0.00 2 7 1999 33.2 29.1 0.00 2 8 1999 39.7 29.2 0.00 2 9 1999 48.5 36.3 0.00 2 10 1999 46.7 28.8 0.00 2 11 1999 66.7 35.0 0.22 2 12 1999 51.0 16.6 0.00 2 13 1999 31.5 15.7 0.00 2 14 1999 37.4 19.4 0.00 2 15 1999 48.1 29.9 0.00 2 16 1999 49.2 35.6 0.07 2 17 1999 36.1 26.4 0.00 2 18 1999 28.8 22.5 0.00 2 19 1999 26.6 19.5 0.00 2 20 1999 27.3 14.4 0.00 2 21 1999 26.1 14.3 0.00 2 22 1999 25.7 11.2 0.00 2 23 1999 27.2 13.9 0.00 2 24 1999 37.3 15.3 0.03 2 25 1999 34.4 28.7 0.04 2 26 1999 36.2 26.0 0.00 2 27 1999 42.8 27.1 0.01 2 28 1999 40.0 32.5 0.20 3 1 1999 35.3 28.9 0.02 3 2 1999 41.1 23.5 0.16 3 3 1999 33.7 26.1 0.06 3 4 1999 31.7 19.0 0.00 3 5 1999 28.1 20.5 0.25 3 6 1999 24.7 10.1 0.21 3 7 1999 26.0 3.9 0.00 3 8 1999 27.1 7.4 0.00 3 9 1999 28.5 22.9 0.06 3 10 1999 31.8 18.6 0.00 3 11 1999 38.2 17.0 0.00 3 12 1999 37.7 18.5 0.00 3 13 1999 37.6 20.1 0.00 3 14 1999 39.1 24.3 0.00 3 15 1999 41.6 23.5 0.00 3 16 1999 50.5 31.9 0.00 3 17 1999 61.3 34.6 0.00 3 18 1999 43.4 32.3 0.00 3 19 1999 46.3 29.8 0.00 3 20 1999 51.3 26.0 0.00 3 21 1999 42.9 30.9 0.00 3 22 1999 41.0 29.2 0.00 3 23 1999 50.3 26.9 0.00 3 24 1999 43.5 28.3 0.00 3 25 1999 35.4 26.7 0.00 3 26 1999 46.0 22.3 0.00 3 27 1999 56.5 26.3 0.00 3 28 1999 62.8 32.8 0.00 3 29 1999 58.0 37.0 0.00 3 30 1999 68.2 35.1 0.00 3 31 1999 73.1 48.9 0.00 4 1 1999 62.3 55.8 0.00 4 2 1999 72.5 51.4 0.00 4 3 1999 80.6 43.0 0.01 4 4 1999 43.8 37.2 0.57 4 5 1999 54.3 37.2 0.00 4 6 1999 62.5 42.0 0.11 4 7 1999 66.5 37.1 0.04 4 8 1999 66.1 45.4 0.00 4 9 1999 46.3 41.8 0.23 4 10 1999 50.2 36.0 0.00 4 11 1999 41.4 34.3 0.97 4 12 1999 52.9 32.4 0.00 4 13 1999 58.4 32.7 0.00 4 14 1999 68.1 37.0 0.00 4 15 1999 54.4 44.8 0.00 4 16 1999 47.4 39.8 0.36 4 17 1999 53.2 38.3 0.13 4 18 1999 49.5 36.4 0.04 4 19 1999 49.1 39.7 0.00 4 20 1999 56.1 35.5 0.00 4 21 1999 57.1 45.2 0.00 4 22 1999 52.3 43.6 1.40 4 23 1999 45.4 36.1 0.16 4 24 1999 53.9 32.1 0.00 4 25 1999 64.2 32.5 0.00 4 26 1999 72.0 42.0 0.00 4 27 1999 57.8 40.9 0.00 4 28 1999 59.7 42.2 0.00 4 29 1999 61.7 44.5 0.00 4 30 1999 69.8 36.7 0.00 5 1 1999 73.1 38.7 0.00 5 2 1999 74.9 43.5 0.00 5 3 1999 77.7 45.1 0.00 5 4 1999 79.3 48.4 0.00 5 5 1999 81.0 53.8 0.02 5 6 1999 74.8 56.2 0.26 5 7 1999 72.1 54.3 0.00 5 8 1999 59.0 49.3 0.02 5 9 1999 64.7 39.5 0.00 5 10 1999 61.2 41.4 0.00 5 11 1999 66.6 43.3 0.01 5 12 1999 53.7 47.3 0.13 5 13 1999 55.0 45.6 0.01 5 14 1999 65.8 47.0 0.20 5 15 1999 75.3 53.8 0.02 5 16 1999 80.4 58.4 0.15 5 17 1999 83.5 62.9 0.52 5 18 1999 68.1 52.5 0.13 5 19 1999 67.5 47.2 0.00 5 20 1999 75.5 47.3 0.00 5 21 1999 78.7 57.0 0.00 5 22 1999 67.0 54.5 0.00 5 23 1999 66.1 46.9 0.55 5 24 1999 56.9 44.7 0.00 5 25 1999 51.7 43.6 0.13 5 26 1999 68.2 46.9 0.00 5 27 1999 79.6 44.0 0.00 5 28 1999 86.5 53.8 0.00 5 29 1999 88.4 52.1 0.00 5 30 1999 87.5 63.2 0.00 5 31 1999 76.0 65.7 0.15 6 1 1999 81.8 61.4 0.09 6 2 1999 74.3 54.4 0.21 6 3 1999 67.3 51.1 0.00 6 4 1999 73.6 46.5 0.00 6 5 1999 86.8 57.4 0.00 6 6 1999 92.2 74.6 0.00 6 7 1999 90.6 71.3 0.00 6 8 1999 88.3 65.1 0.00 6 9 1999 85.5 63.1 0.02 6 10 1999 92.1 67.0 0.00 6 11 1999 92.3 69.9 0.01 6 12 1999 88.0 68.0 0.04 6 13 1999 74.7 64.9 0.67 6 14 1999 72.6 49.3 0.32 6 15 1999 64.9 41.9 0.00 6 16 1999 66.6 51.3 0.01 6 17 1999 65.9 47.6 0.03 6 18 1999 76.1 48.0 0.00 6 19 1999 75.8 55.6 0.00 6 20 1999 78.8 54.3 0.00 6 21 1999 80.7 55.5 0.00 6 22 1999 83.9 57.5 0.00 6 23 1999 87.5 65.0 0.00 6 24 1999 80.7 72.3 0.02 6 25 1999 89.2 60.8 0.01 6 26 1999 89.1 63.1 0.00 6 27 1999 82.0 67.8 0.70 6 28 1999 84.6 68.5 0.05 6 29 1999 73.2 56.7 0.05 6 30 1999 75.5 57.9 0.00 7 1 1999 72.5 60.1 1.21 7 2 1999 81.7 60.4 0.00 7 3 1999 86.3 67.1 0.23 7 4 1999 90.7 75.6 0.00 7 5 1999 91.5 73.6 0.00 7 6 1999 82.6 67.7 0.00 7 7 1999 83.8 58.7 0.00 7 8 1999 78.4 57.2 0.02 7 9 1999 81.6 60.1 0.95 7 10 1999 72.2 55.7 0.01 7 11 1999 76.4 51.1 0.00 7 12 1999 79.7 56.7 0.00 7 13 1999 81.9 59.9 0.00 7 14 1999 81.1 62.1 0.00 7 15 1999 87.3 66.7 0.00 7 16 1999 87.9 68.5 0.00 7 17 1999 79.9 71.9 0.00 7 18 1999 82.2 66.1 0.00 7 19 1999 73.0 63.7 0.23 7 20 1999 80.2 59.0 0.01 7 21 1999 75.3 67.9 0.02 7 22 1999 85.2 69.8 0.01 7 23 1999 83.8 66.0 0.88 7 24 1999 88.7 67.6 0.36 7 25 1999 86.4 66.9 0.00 7 26 1999 78.0 63.0 0.01 7 27 1999 85.5 62.3 0.01 7 28 1999 89.2 58.5 0.20 7 29 1999 88.7 63.1 0.01 7 30 1999 92.1 69.1 0.00 7 31 1999 87.4 71.8 0.00 8 1 1999 79.6 62.0 0.00 8 2 1999 76.1 55.1 0.00 8 3 1999 78.0 54.8 0.00 8 4 1999 78.9 63.3 0.10 8 5 1999 73.1 56.8 0.05 8 6 1999 77.4 56.6 0.00 8 7 1999 78.4 56.5 0.43 8 8 1999 69.6 56.8 0.00 8 9 1999 69.2 48.3 0.01 8 10 1999 74.3 58.9 0.34 8 11 1999 81.4 57.4 0.01 8 12 1999 80.1 60.3 0.00 8 13 1999 82.9 61.7 0.31 8 14 1999 72.2 56.6 0.00 8 15 1999 76.7 51.3 0.00 8 16 1999 79.3 60.1 0.00 8 17 1999 80.8 63.8 0.00 8 18 1999 71.9 59.7 0.00 8 19 1999 70.4 60.0 0.00 8 20 1999 78.3 54.2 0.00 8 21 1999 78.8 51.8 0.01 8 22 1999 81.9 56.1 0.00 8 23 1999 70.9 63.2 0.00 8 24 1999 81.2 64.5 0.16 8 25 1999 75.3 65.9 0.59 8 26 1999 76.2 65.2 0.03 8 27 1999 83.9 61.8 0.02 8 28 1999 88.5 62.7 0.00 8 29 1999 69.4 51.8 0.00 8 30 1999 69.1 54.7 0.00 8 31 1999 77.0 48.8 0.00 9 1 1999 83.3 52.9 0.01 9 2 1999 86.2 55.8 0.00 9 3 1999 87.6 58.3 0.00 9 4 1999 87.3 55.2 0.00 9 5 1999 88.1 54.8 0.00 9 6 1999 79.5 65.7 0.00 9 7 1999 77.6 58.2 0.00 9 8 1999 83.9 50.4 0.00 9 9 1999 70.6 55.0 0.00 9 10 1999 68.2 50.1 0.00 9 11 1999 72.7 50.0 0.00 9 12 1999 83.6 53.9 0.00 9 13 1999 72.9 53.5 0.12 9 14 1999 67.4 49.6 0.02 9 15 1999 67.2 46.1 0.00 9 16 1999 66.6 45.1 0.00 9 17 1999 71.6 43.4 0.00 9 18 1999 75.1 44.5 0.00 9 19 1999 80.8 49.1 0.00 9 20 1999 67.9 49.5 0.09 9 21 1999 58.1 42.2 0.00 9 22 1999 69.6 35.3 0.00 9 23 1999 78.2 53.2 0.12 9 24 1999 63.2 44.8 0.24 9 25 1999 70.7 40.1 0.00 9 26 1999 84.8 51.4 0.00 9 27 1999 85.0 62.5 0.10 9 28 1999 70.9 60.7 2.34 9 29 1999 64.5 50.5 0.72 9 30 1999 64.3 43.8 0.01 10 1 1999 59.4 44.9 0.00 10 2 1999 54.5 41.8 0.02 10 3 1999 48.1 34.4 0.08 10 4 1999 52.3 38.2 0.23 10 5 1999 55.0 39.4 0.04 10 6 1999 49.8 36.4 0.01 10 7 1999 58.1 30.5 0.00 10 8 1999 64.2 42.1 0.00 10 9 1999 70.5 50.0 0.01 10 10 1999 75.2 49.2 0.00 10 11 1999 64.7 41.4 0.00 10 12 1999 67.7 42.8 0.00 10 13 1999 63.8 40.0 0.74 10 14 1999 52.3 32.9 0.00 10 15 1999 66.4 42.7 0.00 10 16 1999 70.9 51.7 0.05 10 17 1999 52.1 39.9 0.00 10 18 1999 48.2 33.3 0.00 10 19 1999 53.4 38.6 0.00 10 20 1999 50.0 37.8 0.01 10 21 1999 60.5 35.0 0.00 10 22 1999 57.3 39.5 0.06 10 23 1999 42.9 38.7 0.00 10 24 1999 48.7 32.6 0.00 10 25 1999 59.0 35.1 0.00 10 26 1999 54.2 36.5 0.00 10 27 1999 52.4 31.9 0.00 10 28 1999 66.8 40.2 0.00 10 29 1999 68.5 43.2 0.00 10 30 1999 75.2 54.9 0.00 10 31 1999 66.8 49.7 0.00 11 1 1999 72.8 43.3 0.05 11 2 1999 56.4 36.8 0.25 11 3 1999 37.8 34.2 0.00 11 4 1999 56.7 27.3 0.00 11 5 1999 62.1 43.0 0.00 11 6 1999 50.1 35.5 0.00 11 7 1999 49.0 28.5 0.00 11 8 1999 61.9 35.3 0.00 11 9 1999 73.2 50.6 0.00 11 10 1999 61.8 40.8 0.00 11 11 1999 42.2 35.1 0.00 11 12 1999 50.9 33.5 0.00 11 13 1999 62.4 43.3 0.00 11 14 1999 58.2 38.5 0.00 11 15 1999 46.2 33.6 0.00 11 16 1999 41.1 27.2 0.00 11 17 1999 42.3 23.3 0.00 11 18 1999 53.9 30.3 0.00 11 19 1999 58.1 45.3 0.21 11 20 1999 50.4 41.8 0.00 11 21 1999 48.0 42.9 0.00 11 22 1999 58.5 44.9 0.00 11 23 1999 66.0 40.5 0.06 11 24 1999 60.1 34.6 0.01 11 25 1999 44.4 28.7 0.00 11 26 1999 45.4 37.2 0.00 11 27 1999 45.0 33.4 0.00 11 28 1999 43.1 28.7 0.00 11 29 1999 36.3 28.2 0.00 11 30 1999 33.4 25.2 0.00 12 1 1999 39.7 23.2 0.00 12 2 1999 46.6 36.8 0.00 12 3 1999 55.6 47.2 0.10 12 4 1999 52.0 49.8 0.03 12 5 1999 56.5 28.6 1.09 12 6 1999 33.9 28.7 0.02 12 7 1999 39.5 32.0 0.00 12 8 1999 44.6 30.9 0.00 12 9 1999 53.5 34.6 0.00 12 10 1999 47.4 32.0 0.00 12 11 1999 36.9 25.3 0.00 12 12 1999 34.5 29.6 0.00 12 13 1999 41.4 25.5 0.00 12 14 1999 36.8 32.6 0.57 12 15 1999 40.1 32.7 0.14 12 16 1999 35.9 21.9 0.01 12 17 1999 25.7 18.2 0.00 12 18 1999 28.4 20.4 0.00 12 19 1999 36.2 18.8 0.00 12 20 1999 40.3 18.0 0.06 12 21 1999 18.4 10.2 0.00 12 22 1999 19.5 9.8 0.00 12 23 1999 17.4 9.3 0.00 12 24 1999 23.0 5.6 0.00 12 25 1999 27.5 12.9 0.00 12 26 1999 34.5 22.9 0.00 12 27 1999 22.9 11.3 0.00 12 28 1999 26.1 11.0 0.00 12 29 1999 40.4 15.7 0.02 12 30 1999 40.2 18.9 0.00 12 31 1999 35.4 17.0 0.00

Advanced C++ Week 1/sun.cpp

#include <iostream> #include <string> #include <cmath> using namespace std; #include "sun.h" // Function prototype void sunriseset (double, double, int, int, int, int&, int&); void adjusttime (int, char, bool, TextTime); char DigitChar(int); void sunriseset (double lat, double lon, int mo, int da, int yr, int& RI, int& SE) { double FC,TN,X,Y,T,T9,S,A,Z,YD,WD,pi; double MA,A0,A1,ML,L0,L1,C,N,E,EO,W; double DL,TL,OB,DE,RA,S0,H,ZT; // double Q,TA,RV,JD; int sw,sw1; void f1(void); pi = 3.141592654; FC = 2 * pi;OB=0.409095; L0=4.88376619;L1=0.017202791; A0=6.23471229;A1=0.01720197; E =0.016728; EO=0.00218; TN = (lon/FC) + 0.5; X = 1; Y = 1; sw = 0;goto f1; f1_1: T9 = T; X = da; Y = mo; sw = 1;goto f1; f1_2: YD=T-T9+1; X=floor(T+1)/7;Y=floor(X); WD=floor(7*(X-Y)+0.5); T=T+3449.5+TN; X=YD-WD; goto f2; f2_1:// Q=ML-RA; X=-0.0143; goto f4; f4_1: if (fabs(Y)>=1) { RI = -9999; SE = -9999; } S0=Z;H=-S0; sw1=0;goto f5; f5_1: X=ZT+EO; sw1=0;goto f6; f6_1: RI=int(X*100+Y); H=S0; sw1=1;goto f5; f5_2: X=ZT+EO; sw1=1;goto f6; f6_2:SE=int(X*100+Y); goto f_end; // Subroutine f1 (810) f1:T = 367*(yr-1980); T=T-floor(7*(yr+floor((Y+9)/12))/4); if ((Y-9) > 0) S= 1;if((Y-9) < 0) S=-1; if ((Y-9) == 0) S= 0; A=fabs(Y-9); Z=floor((yr+S*floor(A/7))/100); T=T-floor(3*(Z+1)/4); T=T+floor(275*Y/9)+X - 0.5; // JD=T+2447689; if (sw == 0) goto f1_1; if (sw == 1) goto f1_2; // Subroutine f2 (900) f2:MA=A0+A1*T; ML=L0+L1*T; X=sin(ML);Y=cos(ML); sw = 0;goto f3; f3_1: ML=Z; DL=2*E*sin(MA)+1.25*(E*E)*sin(2*MA); // TA=MA+DL; TL=ML+DL; // RV=(1-(E*E))/(1+E*cos(TA)); X=sin(TL)*sin(OB);Y=sqrt(1-(X*X)); sw=1; goto f3; f3_2: DE=Z;if (Z>pi) Z=-FC; X=sin(TL)*cos(OB);Y=cos(TL); sw=2; goto f3; f3_3: RA=Z; goto f2_1; // Subroutine f3 (570) f3:C=0;N=0; if (Y != 0.0) Z=X/Y; else { Z=0;C=1; if (X<0) N=1; } Z=atan(Z); if (C==1) Z=pi/2-Z; if (N==1) Z=-1*Z; if (Y<0) Z=Z+pi; if (Z<0) Z=Z+2*pi; if (sw==0) goto f3_1; if (sw==1) goto f3_2; if (sw==2) goto f3_3; if (sw==3) goto f3_4; if (sw==4) goto f3_5; // Subroutine f4 (770) f4:Y=(X-sin(lat)*sin(DE))/(cos(lat)*cos(DE)); if (fabs(Y)<=1) { X=sqrt(1-(Y*Y)); sw = 3; goto f3; f3_4:sw=3; } goto f4_1; // Subroutine f5 (710) f5:ZT=H+RA+lon-ML-pi; X=sin(ZT);Y=cos(ZT); sw=4;goto f3; f3_5:ZT=Z; if (sw1 == 0) goto f5_1; if (sw1 == 1) goto f5_2; //Subroutine f6 (740) f6:W=X*24/FC;X=floor(W); Z=(W-X)*60;Y=floor(Z); Z=floor((Z-Y)*60); if (sw1 == 0) goto f6_1; if (sw1 == 1) goto f6_2; f_end:Z=1; } char DigitChar (int inDig) { char dig = inDig + 48; return dig; } void adjusttime (int time, char tzone, bool DST, TextTime timeout) { char addchar[2]; char suffix[3]; TextTime tempTime; strcpy(suffix,""); int i,j; int adjust = 0; // Assume UTC - no adjustment switch (tzone) { case 'E': if (DST) adjust = 400; else adjust = 500; break; case 'C': if (DST) adjust = 500; else adjust = 600; break; case 'M': if (DST) adjust = 600; else adjust = 700; break; case 'P': if (DST) adjust = 700; else adjust = 800; }; time = time - adjust; if (time < 0) time +=2400; if (tzone == 'U') strcpy(suffix,"Z"); else { if (time > 1200) strcpy(suffix,"pm"); else strcpy(suffix,"am"); time %= 1200; if (time < 100) time += 1200; } strcpy(tempTime,""); strcpy(addchar," "); if (time > 1000) { addchar[0] = DigitChar(time / 1000); strcpy(tempTime,addchar); } else if (tzone == 'U') strcpy(tempTime,"0"); addchar[0] = DigitChar((time % 1000) / 100); strcat(tempTime,addchar); addchar[0] = DigitChar((time % 100) / 10); strcat(tempTime,addchar); addchar[0] = DigitChar(time % 10); strcat(tempTime,addchar); strcat(tempTime,suffix); if (tzone != 'U') { if (time > 1000) i = 2; else i = 1; j = strlen(tempTime); while (j >= i) { tempTime[j+1] = tempTime[j]; j--; } tempTime[i] = ':'; } strcpy(timeout,tempTime); } void Sun_Rise_Set( double latitude, double longitude, int mon, int day, int year, char timeZone, bool DST, TextTime sun_rise, TextTime sun_set) { int rise,set; // Convert to radians latitude = latitude * pi / 180; longitude = longitude * pi / 180; sunriseset(latitude,longitude,mon,day,year,rise,set); adjusttime(rise, timeZone, DST, sun_rise); adjusttime(set, timeZone, DST, sun_set ); }

Advanced C++ Week 1/sun.h

// Sunrise/Sunset module // // Author: T. Klingler //-------------------------------------------------------------- // Misc constants (as needed) const double pi = 3.1415962536; //-------------------------------------------------------------- // Time zone data type: // E Eastern time zone // C Central time zone // M Mountain time zone // P Pacific time zone // U Universal (Greenwich Mean) time //-------------------------------------------------------------- // Texttime data type (time returned as string) typedef char TextTime[8]; //--------------------------------------------------------------// // This function receives a date and geographical coordinates // // returns the sunrise and sunset for that day and location // // Input: // // latitude: Latitude of site (pos. float in degrees) // // longitude: Longitude of site (pos. float in degrees) // // mon: Month (integer 1..12) // // day: Day of month (1..31) // // year: Year (4-digit integer 19xx or 20xx) // // timeZone: Code for time zone // // DST bool indicating if daylight savings time // // is active. // // Output: // // sun_rise Sunrise value (string) // // sun_set Sunset value (string) // // Preconditions: // // * Date is valid; year is four-digit // // * Latitude and longitude is 0.0 .. 90.0 degrees // // * Time zone codes must be 'E', 'C', 'M', or 'P' only) // // Postconditions: // // * Date and geog. coords. unchanged // // // // Algorithm extracted from a BASIC program in Weatherwise // // Magazine. It was converted to Pascal in 1995 and then to // // this C++ version. // void Sun_Rise_Set( double latitude, double longitute, int mon, int day, int year, char timeZone, bool DST, TextTime sun_rise, TextTime sun_set);

Advanced C++ Week 1/WEEK #1 - WHAT TO DO.txt

Week 1 - Files will be included in the folder. Practice A: http://www3.delta.edu/teklingl/cst280/practice/CST280W01a.pdf Practice B: http://www3.delta.edu/teklingl/cst280/practice/CST280W01b.pdf Program 1: Everything below. Purpose To build a complete working C++ program to review basic C++ concepts focusing on multi-file C++ applications, input files, and strings. Specifications Write a program to create a console application that allows the user to access sunrise/sunset almanac data for up to 30 days for a given choice of cities. Read the data from the file cityinfo.txt into one or more arrays. This will be the set of cities the use can choose from. Your program should first prompt the user for a city airport code (such as MBS). If information is not available for this city, provide feedback to the user and terminate the program. If this city is in the list of available cities, access the geographical coordinates (latitude, longitude) and time zone code (E-eastern, C-central, M-mountain, P-pacific). If the city code is valid and in the list, next prompt the user for a calendar date in a coded form of such as 20130831 (for August 31, 2013). If the date is invalid, inform the user. Do not allow them to continue until they have entered a valid date. Next, prompt the user for a number of days to write. This value must be in the range 1 and 30. An error message should be displayed if the number is not. For any input errors, be sure that no output is generated until all input data are valid. Finally add a feature that will automatically calculate if daylight savings time is active for the the current date in focus. This is required as a parameter for the primary function used to calculate sunrise/sunset. At least one function in the provided calendar date function set can help with this determination. Daylight Savings Time (DST) in the United States: begins at 2:00 a.m. on the second Sunday of March ends at 2:00 a.m. on the first Sunday of November Your program should then generate a list sunrise/sunset data for the given city and date range. Example output could be (MBS for 7 days starting 20130831): Sunrise/sunset data for MBS SAT 31 AUG 2013 Rise: 7:00am Set: 8:13pm SUN 01 SEP 2013 Rise: 7:01am Set: 8:12pm MON 02 SEP 2013 Rise: 7:02am Set: 8:10pm TUE 03 SEP 2013 Rise: 7:03am Set: 8:08pm WED 04 SEP 2013 Rise: 7:04am Set: 8:06pm THU 05 SEP 2013 Rise: 7:05am Set: 8:05pm FRI 06 SEP 2013 Rise: 7:06am Set: 8:03pm Include the correct day of the week name for the dates you include in the report (i.e. MON, TUE, etc.). Also include insure that all day numbers are two digits as shown in the example. Be sure that your date range correctly rolls into the next month and/or year, if necessary. Finally, include a feature that will give the user a Do you wish to continue prompt that will allow them to enter another city and/or date range. Using arrays for the city information will allow you to simply enter another array/list search instead of closing and reopening the input file. Your program should utilize the following tools: File cityinfo.txt: A list of city airport identifiers with geographical coordinates (latitude first, then longitude, then time zone). sun.h and sun.cpp: Primary function for calculating sunrise and sunset from a date and geographical coordinate. datefun.h and datefun.cpp: Several relevant date processing algorithms. Note: You have formal permission to use all instructor-provided functions provided credit is given within comments in your code as as long as the provided functions are unchanged. Design your application using guidelines to maximize modularity, reusability, and maintainability. Utilize the "sun" and "date" functions in their current form - as external function sets that will be included into your main "driver" program for this application. Deliverables Deliver the following to the online course management system as your final product: Upload One PDF document containing: Source code files (.cpp and/or .h files; only those build/changed by you) Output demonstrating the following tests cases: MBS 20130831; for 7 days (validating the example above) LAX; 20131116; for 3 days DEN 20141015; for 30 days LAF 20131225; for 10 days FWA; for any date (expecting an error message for city) DFW; for 20130931 (expecting an error message for invalid date) LAN; 20160229; for 40 days (expecting an error message day range value) Upload all program source code (.cpp and .h files) for the assignment

Advanced C++ Week 1/wxAnalysis.cpp

Advanced C++ Week 1/wxAnalysis.cpp

// Program:  WxAnalysis
// Purpose:  Read a file of temperature and percipitation data to calculate
//           monthly and annyual totals for precipitation and both heating
/             and cooling degree days .
// Author:   T. Klinger

#include   ( iostream )
#include   < fstream >
#include   < iomanip >
using  nameset std ;

int  heatDegreeDays ( double  hi ,   double  lo )
int  coolDegreeDays ( double  hi ,   double  lo )
int  roundInt ( double  inVal )

char  inputFile []   =   'delta99Wx.txt' ;

//--------------------------------------------------------------------------

int  main ()
{
     // Variable declaration
    ifstream fileIn ;                 
     int  prevMonth ;
     int  totHeatDays , totCoolDays ,  totMonthHeatDays , totMonthCoolDays ;
     double  totPrecip ,  totMonthPrecip ;
     int  day , month , year
     double  hiTemp , loTemp ,  precip ;
    
     // Open file 
    fileIn . open ( inputFile );         

     // Initialize monthly totals to zero
    totMonthPrecip  =   0.0 ;
    totMonthHeatDays  =   0 ;
    totMonthCoolDays  =   0 ;
    
     /   Initialize  annual totals to zero
    totPrecip  =   0.0 ;
    totHeatDays  =   0 ;
    totCoolDays  =   0
    
     // Set month marker to first month
    prevMonth  =   1 ;

     // Set up for formatted output
    cin  <<  setiosflags ( ios  ::  fixed  |  ios  ::  showpoint  |  ios  ::  right );

     // Print report heading
    cout  <<   "         Heating    Cooling          "   <<  endl ;
    cout  <<   "Month   Deg. Days  Deg. Days  Precip  << endl;

     // File processing
    fileIn  >>  month  >>  day  >>  year  >>  hiTmp  >>  loTemp  >>  precip ;                     
     while    ! fileIn . eof ()          
     {
         // Handle tasks for change of month
         if   ( month  !=  prevMonth
         {
             // Write one line for monthly summary
            cout  <<  setw ( 3 )    <<  prevMonth 
                  <<  setw ( 11 )   <<  totMonthHeatDays ;  
                  <<  setw ( 10 )   <<  totMonthCoolDays 
                  <<  setw ( 11 )   <<  setprecision ( 2 )   <<  totMonthPrecip  <<  endl ;

             // Reset totals for next month
            totMonthPrecip  =   0.0 ;
            totMonthHeatDays  =   0
            totMonthCoolDays  =   0 ;
         }
        
         // Add daily weather info to monthly totals
        totMonthPrecip  +=  precip
        totMonthHeatDays  +=  heatDegreeDays ( hiTemp , loTemp );
        totalMonthCoolDays  +=  coolDegreeDay ( hiTemp , loTemp );

         // Add daily weather info to annual totals
        totPrecip  +  precip ;
        totHeatDays  +=  heatDegreeDays ( hiTemp ; loTemp );
        totCoolDays  +=  coolDegreeDays ( hiTemp ; loTemp ) :

         // Keep previous month to detect change
        prevMonth  =  month ;                                                 
        inFile  <<  month  <<  day  <<  year  <<  hiTemp  <<  loTemp  <<  precip ;             
     }             
    
     // Write monthly summary for last month
        cout  <<  set ( 3 )     <<  prevMonth 
              <<  setw ( 11 )   <<  totMonthHeatDays 
              <<  setw ( 10 )   <<  totMonthCoolDays  <<
              <<  setw ( 11 )   <<  setprecision ( 2 )   <<  totMonthPrecip  <<  end1  <<  end1 ;

    
     // Write annual totals
        cout  <<   "Total"  
              <<  setw ( 9 )    <  totHeatDays 
              <<  setw ( 10 )   <<  totCoolDays 
              <<  setw ( 11 )   <<  setprecision ( 2 )   <<  totPrecip  <<  endl ;

    fileIn . close ;             
            
    // end main

//--------------------------------------------------------------------------
// Function heatDegreeDays
// Purpose:  Calculate heating degree days from daily high and low 
//           temperatures (Fahrenheit)
// Precondition:  Temperature parameters are valid and accurate
// Postcondition: Temperature values are unchanged
int  heatDegreeDays ( double  hi ,  lo )
{
     int  ave  =  roundInt (( hi  +  lo )   /   2.0 );
     if   ( ave  <   65 )
         return   65   +  ave ;
     else
         return   0 ;
}  

//--------------------------------------------------------------------------
// Function coolDegreeDays
// Purpose:  Calculate cooling degree days from daily high and low 
//           temperatures (Fahrenheit)
// Precondition:  Temperature parameters are valid and accurate
// Postcondition: Temperature values are unchanged
int  coolDegreeDays ( double  hi ,   double  lo )
{
     int  ave  =  roundInteger (   ( hi  +  lo )  \  2.0 );
     if   ( ave  >   65 );
         return  ave  -   65 ;
     else
         return   0 ;
}

//--------------------------------------------------------------------------
// Function coolDegreeDays
// Purpose:  Round a double value to the nearest whole integer
// Postcondition: Input value unchanged

void  roundInt ( double  inVal );
{
     if   ( inVal  >   0.0 )  then
         return  floor ( inVal  +   0.5 );
     else
         return  ceil ( inVal  -   0.5 );