Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment will focus on the use of functions and the passing of parameters

ID: 3693625 • Letter: T

Question

This assignment will focus on the use of functions and the passing of parameters. You are to construct a C program, date.c, which performs each of the following operations: • Converts a calendar date into a Julian date. • Converts a Julian date into a calendar date. • Computes the number of days between any two calendar dates. A calendar date is simply a date that contains a year, month, and day and a Julian date is an integer between 1 and 366, inclusive, which tells how m any days have elapsed since the first of January in the current year (including the day for which the date is calculated). For example, calendar date 4/12/2008 is equivalent to Julian date 103, 2008. Write a C program to contain a selection menu (hint: think do - while loop) that allows the user to choose one of the options. An illustration is given below: DATE SELECTION MENU 1) Convert calendar date into Julian date 2) Convert Julian date into calendar date 3) Compute days between two calendar dates 4) Exit program ENTER SELECTION (1-4): Be sure your program contains separate functions for each of the required operations, passing parameters as necessary. Remember that no global variables are allowed in your program except for the file pointer. You should create at least the following functions for your program: • display Menu displays selection menu and prompts user for selection • get Calendar Date prompts and gets calendar date from user • get Julian Date prompts and gets Julian date from user • to Calendar converts Julian date into calendar date • to Julian converts calendar date into Julian date • days Between Dates calculates the number of days between two calendar dates Hint to compute the number of days between two calendar dates: For each date, figure out the number of days since January 1, 1900 and then subtract. For this assignment we will define a leap year as any year that is evenly divisible by 4 but not 100, except that years divisible by 400 are leap years. Here’s a function you can use to calculate leap years. Try and work through its details. int isLeapYear(int year) { return ((!(year % 4) && year % 100) || !(year % 400)); } Test data for the lab is given below. Be sure to turn in output for each of the test data provided below. The information appearing in the parentheses after each piece of the test data are the correct (hopefully) solutions. You may use these solutions to test your program on the supplied test data. Ultimately, however, your program should be able to run on any valid data. Convert Calendar Date into Julian Date 11 15 1922 319, 1922 2 29 1984 60, 1984 7 7 2000 189, 2000 Convert Julian Date into Calendar Date 53 1947 2/22/1947 211 1995 7/30/1995 360 2006 12/26/2006 Compute Number of Days between Two Calendar Dates 5 12 1949 8 16 1900 17801 12 15 1985 3 1 1986 76 1 1 1900 7 1 1993 34155

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int main()
{
float number;
float sum = 0;


printf ("Please enter number for the following functions or enter any letter to exit: ");
printf("Enter 1: Gregorian to julian ");
printf(" 2: Julian to gregorian ");
printf(" 2: number of days left in an year ");

scanf ("%f", &number);

// if user ENTERS a letter, program will terminate

if(1!=scanf ("%f", &number))
{
getchar();
printf ("Exiting the program... ");
exit(0);
}


while (1)
{
int dd, int mm, int yyyy, juldate;
printf(" Enter gregorian date in the format dd ");
scanf (%d, dd);
printf(" Enter gregorian month in the format mm ");
scanf (%d, mm);
printf(" Enter gregorian year in the format mm ");
scanf (%d,yyyy);
juldate = gregtojul(dd, mm, yyyy);

}
while (2)
{
int gregdate, juldate;
printf(" Enter juliandate ");
scanf (%d, juldate);
gregdate = jultogreg(juldate);

}

while (3)
{
int gregdate,numdays;
printf(" Enter gregorian date in the format ddmmyyyy ");
scanf (%d, gregdate);
numdate = calculatedays(gregdate);

}


// if user ENTERS a letter, program will terminate

if(1!=scanf ("%f", &number))
{
getchar();
printf ("Exiting the program... ");
exit(0);
}

}


return 0;
}
gregtojul(int dx, int mx, int yx)
{

int Res1 = ((2 - yx / 100) + (yx / 400));

int Res2 = int(365.25 * yx);

int Res3 = int(30.6001 * (mx + 1));

float jdn1 = (Res1 + tRes2 + Res3 + dx + 1720994.5);


//Displays first julian date

cout << "The first Julian Date is " << jdn1 << endl;

}
jultogreg(int JD)
{


LONG j, y, d, m;

//while calculating we consider the following :

//for Years -> 4 centuries (146067 days)

//for Months -> 4 years and 5 consecutive months

//for days -> 5 consecutive months

j = JD - 1721119; //1721119 is the number of days since JD 0 to the start of March 2 1BC. //hence j are the no of days from March 2 1BC

y = (4 * j - 1) / 146097; //146097 is the number of days in four centuries, time it takes for the cycle of leap years to repeat.

j = 4 * j - 1 - 146097 * y; //4 is used to denote leap year

d = j / 4;

j = (4 * d + 3) / 1461; //number of days in four years.

d = 4 * d + 3 - 1461 * j;

d = (d + 4) / 4;

m = (5 * d - 3) / 153; //number of days in 5 consecutive months alternating between 31 and 30 days (either Mar-Jul or Aug-Dec).

d = 5 * d - 3 - 153 * m;

d = (d + 5) / 5;

y = 100 * y + j;

if (m < 10)

{

m = m + 3; //additions and subtractions of 3 and 9 are to restore the "start" of the year to January.

}

else

{

m = m - 9; //additions and subtractions of 3 and 9 are to restore the "start" of the year to January.

y = y + 1;

}

*Year = (WORD) y;

*Month = (WORD) m;

*Day = (WORD) d;

}

Calculatedays(int days, int mm, int year)
{
intnumbdays =0
if (year %100 =0 && year % 400 = 0)


int months[] = {31,29,31,30,31,30,31,31,30,31,30,31}
else
int months[] = {31,28,31,30,31,30,31,31,30,31,30,31}

for(month = mm, month< =12, month++)
numbdays +=months[mm]

numbday -= days;

printf(" number of days in rest of the year from the given date is ", numbdays);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote