Question

Hi any help is appreciated! I am using C++. The Julian Day Number (JDN) is a...

Hi any help is appreciated! I am using C++.

The Julian Day Number (JDN) is a sequential count of days since the beginning of the Julian Period. Day number zero corresponds to 1 January 4713 BCE. As a result of calendar reform in the 16th Century, we will only be computing day numbers since 15 October 1582 (which was the first day of the modern Gregorian calendar, having day number 2299161). 1 January 2001 was day number 2451911.

To compute the JDN for a specific date, we need its month number (an integer between 1 and 12, where January = 1, February = 2, etc.), day (an integer between 1 and 31), and year (a four-digit integer). The JDN is calculated with the following formulas, using only integer arithmetic:

a ← [ ( 14 − month ) / 12 ] { Note: [ a / b ] means integer quotient only — no remainders or decimals! }

m ← ( month − 3 ) + ( 12 × a )

y ← year + 4800 − a

leap_days ← [ y / 4 ] − [ y / 100 ] + [ y / 400 ]

jdn ← day + [ ( ( 153 × m ) + 2 ) / 5 ] + ( 365 × y ) + leap_days − 32045

1. Using the formulas provided above, compute the JDN by hand for the following dates: 15 October 1582, 1 January 2001, and your instructor’s birthday. Show all work (i.e., show each formula in the calculation sequence with numbers replacing the variables, though you may want to use a calculator to help with the arithmetic) and check your results.

2. Create an IPO chart for a program that prompts the user to input a date as a month, day and year, then computes and displays the corresponding JDN. (Do this step, and the one that follows, before you start writing any source code.)

3. Create a table of test data with five dates, other than then ones used in Step #1. Choose a wide variety of dates that might help expose errors in your coding — e.g., use various months and days, along with a selection of years that are and are not leap years.

4. Write the program described in Step #2 in C++. Your program must separate input, processing, and output into at least three independent modules that are called in sequence by the main module. The user should be prompted as in the sample below, and your program should match the sample format as closely as possible (the underlined numbers in bold are examples of inputs made by the user — your program will not underline the user’s inputs or show them in bold):


Enter a month number (Jan=1, Feb=2, etc.): 6


Enter a day number (1..31) : 1


Enter a year using four digits : 1972


The JDN for 6/1/1972 is 2441470

0 0
Add a comment Improve this question Transcribed image text
Answer #1
C++ Program
#include<iostream>
using namespace std;

// function declaration
void inputMDY(int&, int&, int&); // INPUT
unsigned int calculateJDN(int, int, int); // PROCESSING
void printJDN(int,int,int,unsigned int); // OUTPUT

// main function
int main()
{
    // declare the variables
    int month = 0;
    int day = 0;
    int year = 0;
    unsigned int JDN = 0;
    // call the inputMDY() function
    // to input the values from the user
    inputMDY(month, day, year);
    // process the input to calculate JDN
    JDN = calculateJDN(month, day, year);
    // print the JDN
    cout << endl;
    printJDN(month,day,year,JDN);
}

// function to input the day, month and year
// and return the same using call be reference
// parameters to the function
void inputMDY(int &m, int &d, int &y)
{
    cout << "Enter a month number (Jan=1, Feb=2, etc.): ";
    cin >> m;
    cout << "Enter a day number (1..31) : ";
    cin >> d;
    cout << "Enter a year using four digits : ";
    cin >> y;
}

// function to calculate the Julian day number and return it
unsigned int calculateJDN(int m, int d, int y)
{
    // declare the JDN variable to store the result
    unsigned int JDN = 0;
    // perform the intermediate calculations
    int a = (14-m)/12;
    m = (m-3) + (12*a);
    y = y + 4800 - a;
    int leap_days = (int)(y/4) - (int)(y/100) + (int)(y/400);
    // do the main calculation and save the result in variable JDN
    JDN = (unsigned int)d+(( (int)((153*m) + 2 )/5 )+ (365*y) + leap_days - 32045);
    // return the result
    return JDN;
}

// function to print the JDN with date
void printJDN(int m,int d,int y,unsigned int JDN)
{
    cout << "The JDN for " << m << "/" << d <<"/" << y 
         << " is: " << JDN << endl;
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Hi any help is appreciated! I am using C++. The Julian Day Number (JDN) is a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Julian day numbers (JDN) are used to provide a number for a day of the year...

    Julian day numbers (JDN) are used to provide a number for a day of the year so that calculations can be performed relatively easily to determine the difference between two dates. The JDN for a day is the number of days that have elapsed between that day and a base date of January 1, 4713 BC. Use the following calculation: JDN = (1461 × (Y + 4800 + (M − 14) / 12)) / 4 + (367 × (M −...

  • In ruby Write a program that prompts the user to enter a year and first day...

    In ruby Write a program that prompts the user to enter a year and first day of the year, and displays the calendar table of that year. For example, if the user entered the year 2019, and 2 for Tuesday, January 1, 2019, your program should display the calendar for each month in the year 2019.

  • Hi I need some help in C programing class and I doing one of the exercise...

    Hi I need some help in C programing class and I doing one of the exercise so that I can get better at coding. Suppose you are asked to design a software that helps an elementary school student learn multiplication and division of one-digit integer numbers. The software allows the student to select the arithmetic operation she or he wishes to study. The student chooses from a menu one of two arithmetic operations: 1) Multiplication and 2) Division (quotient). Based...

  • Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b):...

    Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b): Write a program that gives remainder without using modulus operator and loops. The first number entered will be dividend and second number entered will be divisor. Sample input: 15 6 Sample output: Remainder is 3 In a right triangle, the square of the length of one side is equal to the sum of the squares of the length of the other two sides. Write...

  • c++ please :) First, ask the user to enter a year (4-digit) and what week day...

    c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....

  • please solve in c++ MULT PLES number Writo a complete nat counts and prints the even...

    please solve in c++ MULT PLES number Writo a complete nat counts and prints the even pies of 5 as well as the number of multiples of 8 be.ween two integer values entered by the user and the total number. You must use a while or do ... while loop. If the user's first input is greater than or equal to the second one, your program should ask the user for another two inputs until the first one is less...

  • I need help with this C++ assignment. Create a program which will implement the sum of...

    I need help with this C++ assignment. Create a program which will implement the sum of the numbers between 1 and n where n is an integer. When completed, the program will allow the user to input a positive integer (n) then the program will add all numbers between 1 and n (including n) and output the sum. For example, if the user enters 8 then the program will sum the numbers 1 through 8 and will output the sum....

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • An ordinal date consists of a year and a day within it, both of which are...

    An ordinal date consists of a year and a day within it, both of which are integers. The year can be any year in the Gregorian calendar while the day within the year ranges from one, which represents January 1, through to 365 (or 366 if the year is a leap year) which represents December 31. Ordinal dates are convenient when computing differences between dates that are a specific number of days (rather than months). For example, ordinal dates can...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT