California State University, Northridge



|[pic] |College of Engineering and Computer Science |

| |Computer Science Department |

| |Computer Science 106 |

| |Computing in Engineering and Science |

| |Spring 2006 Class number: 11672 Instructor: Larry Caretto |

First Programming Project

Objective

In this project, you will write a program that is organized into individual functions. You will use the functions that you developed in exercise seven for this project. You will expand those functions so that you can validate input on date and time inputs and use the valid data in any calculation. The problem addressed here, the conversion between a standard calendar date and a dating system known as the Julian day number used by astronomers, also gives you practice in writing expressions and assignment statements.

Background on the project

The Julian day number, used by astronomers, is a continuous dating system.[1] The date in this system has a decimal part that represents the fraction of a day. The integer part of the Julian day number is incremented at noon. Thus, the fractional part is 0.25 at 6 pm, 0.5 at midnight and 0.75 at 6 am on the next calendar day. The whole part represents the day. The following table shows some examples of the Julian day number.

|Calendar Date |Time |Julian Day Number |

|December 31, 2006 |6:00:00 pm |2454101.25 |

|January 1, 2007 |0:00:00 am |2454101.5 |

|January 1, 2007 |noon |2454102 |

|January 1, 2007 |11:59:59.9 pm |2454102.4999988 |

The conversion from a standard calendar date and time to a Julian Date uses the following algorithm.[2]

1. Define DAY, MONTH, YEAR, HOUR, MINUTE, and SECOND as the components of the conventional date and time to be converted. The HOUR variable uses a 24-hour clock where 0 is midnight, 12 is noon, 18 is 6 pm, etc.[3]

2. Subtract 14 from the month and divide the result by 12. Discard the remainder. Call the quotient J.

3. Define K as J plus 4800 plus the year.

4. Multiply K by 1461 and divide the result by 4. Discard the fractional part and call the quotient L.

5. Define M as the MONTH minus 2 minus ( 12 times J ).

6. Multiply M by 367 and divide the product by 12. Discard the remainder and call the quotient N.

7. Divide the sum of 100 plus K by 100. Discard the remainder and call the quotient P.

8. Multiply P by 3 and divide the result by 4. Discard the remainder and call the quotient Q.

9. Add L plus N to DAY and subtract Q from the sum; call the result T.

10. If the HOUR is greater than or equal to 12 subtract 32075 from T; otherwise subtract 32076 from T. The result is the integer part of the Julian Day Number.

11. Define a modified hour, HMOD, by subtracting 12 from the HOUR if HOUR is greater than or equal to 12 and adding 12 to the HOUR if HOUR is less than 12.

12. Convert the time measured as the modified hour, HMOD, MINUTE and SECOND, into a decimal fraction of a day. (One day = 24 hours = 1440 minutes = 86400 seconds.)

13. Add the fractional part to the integer part to get the final Julian Day Number.

In defining time we use integer variables for year, month, day, hour and minute. However, we use a real variable for seconds. Using a float or double for seconds allows us to define time differences as small as possible while keeping the conventional time measures. For this project you will have to write a function that has the year, month, date, hour, minute and second as input parameters. This function should compute and return a value of the Julian day number.

Range checking for type double input variables – In exercise seven, you developed functions to allow a user to input a year, month and date, with the ability to check to see that the day of the month was in the proper range. You should be able to use the following functions directly from that exercise in this project: getValidInt, getMaxDays, and leap. In addition, you should be able to modifiy the input function you prepared for that exercise for this assignment.

The major addition required for this project (in addition to the Julian day number function) is a function to check the validity of type double input. This is similar to the getValidInt function, but the problem is more complicated for type double. When reading an integer variable, we always know that the input data is greater than or equal the minimum value and is less than or equal to the maximum value. For input of a real variable, however, we may want to have two possible cases for the minimum value: (1) the input data must be greater than the minimum value or (2) the input data must be greater than or equal to the minimum value. We also have two possible cases for the maximum value: (1) the input data must be less than the maximum value or (2) the input data must be less than or equal to the maximum value.

These different cases can be handled by the function, getValidDouble, that has the following prototype:

double getValidDouble( string minCond, double xMin, string maxCond,

double xMax, string name );

The parameters xMin, xMax, and name are similar to those in the getValidInt function. (xMin is the minimum value, xMax is the maximum value, and name is the variable name to be printed in the user input cue.) The string parameters minCond and maxCond are used to specify the nature of the minimum condition and the maximum condition, respectively.

• If minCond is the string “>” then the minimum conditions is a greater than-condition; if minCond is “>=”, then the minimum condition requires that the input be greater than or equal to the minimum value.

• If maxCond is the string “ ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download