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

Date Lab: help with c programming, below is the instructions. This assignment wi

ID: 3919003 • Letter: D

Question

Date Lab: help with c programming, below is the instructions. 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 calender date into a Julian date. Converts a Julian date into a calender date. Computes the number of days between and two calender dates. A calender 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 many days habe elapsed since the first of January in the current year (including the day for which the date is calculated). For example, calender date 4/12/2008 is equivalent to Julian date 103, 2008. Your program should 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 calender date into Julian date 2) Convert Julian date into calender date 3) Compute days between two calender 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: displayMenu displays selection menu and promps user for selection getCalenderDate prompts and gets calender date from user getJulianDate prompts and gets Julian date from user toCalender converts Julian date into calender date toJulian converts calender date into Julian date daysBetweenDates calculates the number of days between two calender dates Hint to compute the number of days between two calender 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 divisble by 4 but not 100, except that years divisble 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 Calender Date Into Julian Date 11 15 1922 (319, 1922) 2 29 1984 (60, 1984) 7 7 2000 (189, 2000) Convert Julian Date Into Calender Date 53 1947 ( 2/22/1947) 211 1995 ( 7/30/1995) 360 2006 (12/26/2006) Compute Number of Days Between Two Calender Dates 5 12 1949 16 1900 (17801) 12 15 1985 1 1986 76) 1 1 1900 7 1993 (34155)

Explanation / Answer

SOLUTION:

àAccording to the given data the following data is given and it is as follows;

CODE:

#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(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(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);

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

}
jultogreg(int JD)
{


LONG j, y, d, m;

//Mean whilein calculating we need to consider the following :

//to the Years -> 4 centuries (146067 days)

//to the Months -> 4 years and 5 consecutive months

//to the days -> 5 consecutive months

j = JD - 1721119;

y = (4 * j - 1) / 146097;

j = 4 * j - 1 - 146097 * y;

d = j / 4;

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

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

d = (d + 4) / 4;

m = (5 * d - 3) / 153; //that is 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; //here the additions and subtractions of 3 and 9 are to restore the "start" of the year to January.

}

else

{

m = m - 9; //here the 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);
}

therefore by using the instructions in the above data,the code is written as given above

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