Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm kind of stuck on this problem. Can you fix the code to work well? It does not compile. This is a code. #include int

I'm kind of stuck on this problem. Can you fix the code to work well? It does not compile.

This is a code.

#include

int isLeapYear(int year);

int displayMenu(void);

void getCalenderDate(int &day, int &month, int &year);// prompts and gets calender date from user

void getJulianDate(int &days, int &year);// prompts and gets Julian date from user

void toCalender(int days, int year2, int &day, int &month, int &year1);// converts Julian date into calender date

void toJulian(int day, int month, int year1, int &days, int &year2);// converts calender date into Julian date

int daysBetweenDates(int days, int year2, int &day, int &month, int &year1);// calculates the number of days between two calender date

int main(void)

{

int Jyear = 1900;

int year1, year2, month1, month2, day1, day2;

int days;

int choice=0;

do

{

choice = displayMenu();

switch(choice)

{

case 1:

getCalenderDate(day1, month1, year1);

break;

case 2:

getJulianDate(day2, year2);

break;

case 3:

printf("Convert to Julian Date: ");

toJulian(day1, month1, year1, day2, year2);

printf("%d \t %d \t %d \t (%d, %d) ", day1, month1,year1, day2, year2); break;

case 4:

printf("Convert to Original Date: ");

toCalender(day2, year2, day1, month1, year1);

printf("%d \t %d \t\t (%d/%d/%d) ", day2, year2, day1, month1, year1);

break;

case 5:

getCalenderDate(day1, month1, year1);

getJulianDate(day2, year2);

days =daysBetweenDates(day2, year2, day, month, year1);

printf("%d \t %d \t %d %d %d %d ", day1, month1,year1, day2, year2, days);

break;

case 6:

exit(0);

}

}while(1);

// your code goes here

return 0;

}

//function to check whether it is leap year or not

int isLeapYear(int year)

{

return ((!(year %4) && (year % 100) || !(year % 400)));

}

//displays selection menu and promps user for selection

int displayMenu()

{

int choice=0;

while(choice6)

{

printf("DATE SELECTION MENU ");

printf("1) Convert calendar date into Julian date ");

printf("2) Convert Julian date into calendar date ");

printf("3) Compute days between two calender dates ");

printf("4) Exit program ");

printf("ENTER SELECTION (1 - 3): ");

scanf("%d",&choice);

printf(" ");

if(choice3)

printf("invalid entry ");

}

return choice;

}

void getCalenderDate(int &day, int &month, int &year)

{

printf("Enter date: ");

scanf("%d", &day);

printf("Enter month: ");

scanf("%d", &month);

printf("Enter year: ");

scanf("%d", &year);

}

void getJulianDate(int &days, int &year)

{

printf("Enter date: ");

scanf("%d", &days);

printf("Enter year: ");

scanf("%d", &year);

}

void toJulian(int day, int month, int year1, int &days, int &year2)

{

int daysinmonth;

int days=1,i;

for (i=1;i

{

switch(i)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

daysinmonth=31;

break;

case 9:

case 4:

case 6:

case 11:

daysinmonth=30;

break;

case 2:

daysinmonth=28 +isLeapYear(year);

break;

}

days+=daysinmonth; //and count how many days passed

}

days+=day; //add to the day wanted

year2 = year;

}

void toCalendar(int days, int year2, int &day, int &month, int &year1)

{

int i=0;

int daysinmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};

if(isLeapYear(year)==1)

daysinmonth[1]++;

while(days>daysinmonth[i])

{

days=days-daysinmonth[i];

i++;

}

day = days;

month = i;

year1 = year2;

}

int daysBetweenDates(int days, int year2, int day, int month, int year1)

{

int days2=0, count=0, total =0, difference;

toJulian(day1, month1, year1, day2, year2);

if(year1>year2)

{

difference = year1-year2;

for(int i = year2 ; i

{

if(isLeapYear(i))

count++;

}

}

else

{

difference = year2-year1;

for(int i = year1 ; i

{

if(isLeapYear(i))

count++;

}

}

total = count + difference*365;

return total;

}

This is a question.

image text in transcribed

image text in transcribed

image text in transcribed

Thank you.

Date Lab 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 the following operations: ch of 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 days have elapsed since the first of January in the current year (including the for which the date is calculated). For example, calendar date 4/12/2008 is equivalent to Julian date 103, 2008. many da 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 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 operations, passing parameters as necessary. Remember that no globold variables are allowed in your program except for the file pointer. You create at least the following functions for your program: ired

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions