Download Julian Day Number: Algorithm and Calculation and more Slides Computer Science in PDF only on Docsity! Project one March 30, 2006 1 First Project – Julian Day Number Calculation Larry Caretto Computer Science 106 Computing in Engineering and Science March 30, 2006 2 Outline • Outline first project – Goals of project – Connection with exercise seven • Julian day number – Definition – Algorithm • Code structure for first project 3 Project One Goals • Design a program with several functions • Look at communication among several functions in a single program • Write routine using mathematical statements (and choice statements) from pseudocode • See that functions developed in a general purpose manner for one code can be reused in another code 4 What is a Julian Day Number? • Continuous time used by astronomers • Integer part is number of days • Decimal part is fraction of a day starting at noon: 6 pm is 0.25; midnight is 0.5 • Class start time,12:30 pm on Tuesday, March 28, 2006 was Julian date number 2453823.02083333 – Fractional part is fractional part of a day starting at noon (1/48 = 0.02083333…) – What is JDN for start of today’s class? 2453825.02083333 5 Julian Day Number Cases 2454102.499998811:59:59.9 pm1-Jan-2007 2454102noon1-Jan-2007 2454101.50:00:00 am1-Jan-2007 2454101.256:00:00 pm31-Dec-2006 Julian NumberTimeCalendar Date Your program must match these results! • Run sample cases shown in assignment 6 Julian Day Number Algorithm • Thirteen-step algorithm in exercise notes – requires user input of integer year, month, day, hour (0-23), minutes • Use type double for seconds – use integer operations on month, day, year • To get fraction of day convert time to common elapsed time (hours, minutes or seconds) and divide by 24 h = 1440 min = 86,400 s • Convert types to double before division! Project one March 30, 2006 2 7 Typical Algorithm Steps • Subtract 14 from the month and divide the result by 12. Discard the remainder. Call the quotient J. • Define K as J plus 4800 plus the year. • Multiply K by 1461 and divide the result by 4. Discard the fractional part and call the quotient L. • And a few more steps like these 8 Project One Code • Use data validation functions from exercise seven – getValidInt – getMaxDays – leap • Write main, input and Julian Day functions • Use getValidDouble and getDoubleGELT functions from project one assignment • Write three other functions (or stubs) similar to getDoubleGELT 9 Main Function for Project One • Use outer loop for repeated input of different cases (see task three of exercise one for general structure) – Many did this for exercises five and six • Within this loop – Call input function for data on year, month, day, hour, minute second – Pass input information to function that calculates Julian Day Number – Print input and Julian Day Number • Use setprecision to match test cases 10 Input Data Function • Uses getValidInt and getValidDouble • Code is extension of input function from task two of exercise seven • Must use pass by reference to return variables to main function • Possible prototype void getInput( int& month, int& day, int& year, int& hour, int& minute, double& second); 11 Valid double Input • For valid integer input we can have input equal to max and min values • For real input we want to have choices – User input less than or less-than-or-equal- to a stated maximum value – User input greater than or greater-than-or- equal-to a stated minimum value • User calls getValidDouble function that specifies choices for both maximum and minimum values 12 getValidDouble • This function returns a value for a type double variable that is with a range set by the user • The user can also specify if variable is > or >= the minimum value • Similarly it is possible to specify that the variable is < or <= the maximum value • The specifications of the lower and upper limit are done by the use of strings – “<“ or “<=“ specify the kind of upper limit – “>” or “>=“ specify the kind of lower limit