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

(Using Microsoft Visual C++ 2010 Express) This assignment will focus on the use

ID: 3623843 • Letter: #

Question

(Using Microsoft Visual C++ 2010 Express)

This assignment will focus on the use of C control structures, functions and the passing of parameters. You are to construct a C program, date.c, which converts a calendar date into a Julian date and a Julian date into a calendar date. 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 many 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.



Your program should contain a selection menu that allows the user to choose one of the date conversions. An illustration is given below:



DATE SELECTION MENU


1) Convert calendar date into Julian date

2) Convert Julian date into calendar date

3) Exit program



ENTER SELECTION (1 - 3):





Be sure your program contains separate functions for each conversion, passing parameters as necessary. Given below is some code to get you started. Note the declaration of function prototypes, the file declaration for the csis.dat output file, the complete main() function for the program and a function to calculate leap years. 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.





int main(void);



void menu(void);

int getChoice(void);



void calendarToJulian(void);

void getCalendarDate(int *month, int *day, int *year);



void julianToCalendar(void);

void getJulianDate(int *day, int *year);



int isLeapYear(int year);



FILE *csis;



int main(void) {

int choice;



fopen_s(&csis, "csis.dat", "w");

do {

choice = getChoice();

switch (choice) {

case 1 : calendarToJulian(); break;

case 2 : julianToCalendar(); break;

case 3 : break;

}

}

while (choice != 3);

return 0;

}



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. 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)







For extra credit have your program also perform the following operations:



Compute the number of days between any two calendar dates. (Hint: For each date, figure out the number of days since January 1, 1900 and then subtract).



Given a calendar date and the number of days until some future event, determine the calendar date of the future event.



Given any calendar date, determine its corresponding day of the week. You may assume that January 1, 1900 was a Monday. (Hint: think mod 7).



Use the following test data for the extra credit portion of this lab:



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 7 1993 (34155)





Compute Future Date

5 16 1947 2376 (11/16/1953)

2 12 1912 6000 (7/17/1928)

12 15 1933 2345 (5/17/1940)







Compute day of week

12 31 1900 (Monday)

4 18 1977 (Monday)

8 1 1932 (Monday)

11 30 1947 (Sunday)

12 31 1986 (Wednesday)

12 31 1988 (Saturday)







Points to remember:



Make sure you are creating a C program and not a C++ program.



You should not be using any global variables in your program

Explanation / Answer

please rate - thanks

see my message

I don't know how to run C in Visual C++ sorry   Message me if any problems

#include <stdio.h>
#include <conio.h>
void toJulian(FILE *);
void fromJulian(FILE *);
int todoy(int,int,int);
void todate(int,int,FILE *);
int leap(int);
int menu();
int main()
{int choice;
FILE *output;
output = fopen("csis.dat", "w");
               
choice=menu();
while(choice!=3)
   {if(choice==1)
      toJulian(output);
    else
       fromJulian(output);
    choice=menu();
   }
fclose(output);    
return 0;
}
int menu()
{int choice=0;
while(choice<1||choice>3)
   {printf("DATE SELECTION MENU ");
   printf("1) Convert calendar date into Julian date ");
   printf("2) Convert Julian date into calendar date ");
   printf("3) Exit program ");
   printf("ENTER SELECTION (1 - 3): ");
   scanf("%d",&choice);
   printf(" ");
   if(choice<1||choice>3)
       printf("invalid entry ");
   }
return choice;
}
void toJulian(FILE * out)
{
int month,day,doy,year,d;
int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("enter month ");
     scanf("%d",&month);
     while(month<1||month>12)
        { printf("invalid month ");
          printf("enter month ");
        scanf("%d",&month);
        }
    printf("enter day ");
     scanf("%d",&day);
     if(month!=2)
         while(day<1||day>days[month-1])
            { printf("Invalid day ");
             printf("enter day ");
            scanf("%d",&day);
            }
      printf("Enter year ");
     scanf("%d",&year);
      if(month==2)
      {d=days[1]+leap(year);
         while(day<1||day>d)
            { printf("Invalid day ");
             printf("enter day ");
            scanf("%d",&day);
            }
            }
     doy=todoy(month,day,year);
     fprintf(out,"%d/%d/%d is %d days from January 1 ",
            month,day,year,doy);
}
void todate(int doy,int year,FILE *out)      //change date to day of year
{
int days=0,i=0,n,orig=doy;
int daysinmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(leap(year)==1)
     daysinmonth[1]++;
while(doy>daysinmonth[i])
    {doy=doy-daysinmonth[i++];
    }
fprintf(out,"%d/%d is day %d of %d ",i+1,doy,orig,year);

}
void fromJulian(FILE * out)
{int doy,year,error;
do
     {error=0;
     printf("Enter day of year ");
     scanf("%d",&doy);
     printf("Enter year ");
     scanf("%d",&year);
     if(doy<1||doy>leap(year)+365)
         {printf("day of year out of range ");
         error=1;
         }
      }while(error);
todate(doy,year,out);

}
int todoy(int month,int day,int year)      //change date to day of year
{int daysinmonth;
int days=1,i;
             
for (i=1;i<month;i++)       //go up to that month add how many days in the month
    { switch(i)
         {
         case 9:
         case 4:
         case 6:
         case 11:daysinmonth=30;
                 break;
         case 2: daysinmonth=28 +leap(year);  
                 break;
         default:daysinmonth=31;
         }
      days+=daysinmonth;               //and count how many days passed
     }
days+=day;                           //add to the day wanted
return days-1;   
}

int leap(int year)
{int leapcode=0;
    if(year%4==0)
    {if(year%100!=0)
            leapcode=1;
       else
           if(year%400==0)
               leapcode=1;
       }
return leapcode;
}