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

Can someone help me with this fairly simple C program?? Its a intro class so ple

ID: 3689089 • Letter: C

Question

Can someone help me with this fairly simple C program?? Its a intro class so please try to keep it simple. Thank you!!!

The UNIX cal command prints out the calendar of the month/year that the user enters. Type in the following, one at a time, and observe the output: cal 3 2014 cal 2014 cal 1 1 To learn more about this command, type in man cal for help Write a program named cal.c that prints out the following (which is the output when you type in cal 4 2016 in UNIX). Note that you are not asked to implement the cal command. You can assume that you know March 1 is a Sunday. You will need to use loops and the % operator. April 2016 Su Mo Tu We Th Fr Sa 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Explanation / Answer

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#define LEAP_YEAR ((Year%4==0 && Year%100 != 0)||Year%400==0)
#define TRUE 1
#define CH '-'
#define MAX_NO 91

int MonthDay[] = {31,28,31,30,31,30,31,31,30,31,30,31};
char *MonthName[]={

"January","February","March","April","May","June","July", "August","September","October","November","Decembeer"

};
char *MonthName1[]={"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};

getkey()
{
   union REGS i,o;
   while(!kbhit());
   i.h.ah = 0;
   int86(22,&i,&o);
   return (o.h.ah);
}
int getZeller(int Month,int Year)
{
   int Day = 1, ZMonth, ZYear, Zeller;
   if(Month < 3)
       ZMonth = Month+10;
   else
       ZMonth = Month-2;
   if(ZMonth > 10)
       ZYear = Year-1;
   else
       ZYear = Year;
   Zeller = ((int)((13*ZMonth-1)/5)+Day+ZYear%100+(int)((ZYear%100)/4)-2*(int)(ZYear/100)+(int)(ZYear/400)+77)%7;
   return Zeller ;
}

void PrintFile(int M,int Y, int Z)
{
   int i,j;
   char filename[12];
   char stryear[5];
   FILE *stream;

   strcpy(filename,MonthName1[M-1]);
   itoa(Y,stryear,10);
   strcat(filename,stryear);
   strcat(filename,".txt");

   if((stream=fopen(filename,"w"))==NULL)
   {
       printf(" Error-cannot create file.");
       getch();
       exit(1);
   }
   fprintf(stream," %s %d ",MonthName[M-1],Y);
   for(i=1;i<=MAX_NO;i++)
       fprintf(stream,"-");
   fprintf(stream," SUN MON TUE WED THU FRI SAT ");
   for(i=1;i<=MAX_NO;i++)
       fprintf(stream,"-");
   /* setting starting position */
   fprintf(stream," ");
   for(i = 1; i <= Z; i++)
       fprintf(stream," -");
   j = Z;
   /* printing dates */
   for(i = 1; i <= MonthDay[M-1]; i++)
   {
       if(j++ % 7 == 0)
           fprintf(stream," ");
       fprintf(stream," %2d",i);
   }
   fprintf(stream," ");
   for(i=1;i<=MAX_NO;i++)
       fprintf(stream,"-");
   fprintf(stream," Created by: Debabrata Das [debabrata.dd@gmail.com]");
   fclose(stream);
}
void printchar(char c)
{
   int i=1;
   printf(" ");
   for(i=1;i<=51;i++)
       printf("%c",c);
   printf(" ");

}


void main(void)
{
   int Month, Year, Zeller;
   int i, j, KeyCode;


Top: /* goto statement */
   textcolor(WHITE);
   clrscr();
   printf(" This program shows calendar of ");
   printf(" a given month. Enter month, year...format is mm-yyyy. ");
           /* taking input */
   while(TRUE)
   {
       fflush(stdin);
       printf(" Enter mm-yyyy: ");
       scanf("%d-%d", &Month, &Year);
       if(Year < 0)
       {
           printf(" Invalid year value...");
           continue;
       }
       if(Year < 100)
           Year += 1900;
       if(Year < 1582 || Year > 4902)
       {
           printf(" Invalid year value...");
           continue;
       }
       if(Month < 1 || Month > 12)
       {
           printf(" Invalid month value...");
           continue;
       }
       break;
   }   /* End of while loop */
   do
   {
       /* calculating day of 1st date of given month */
       Zeller = getZeller(Month,Year);
       clrscr();
       printf(" ");

       /* printing the corresponding month name */
       textbackground(Month);
       cprintf("%s %d ",MonthName[Month-1],Year);
       textbackground(BLACK);

       /* adjusting February in case of Leap Year */
       MonthDay[1] = LEAP_YEAR ? 29 : 28;

       /* giving output */
       printchar(CH);

       textcolor(12); /* LIGHTRED */
       printf(" ");cprintf("SUN");
       textcolor(LIGHTGREEN);
       cprintf(" MON TUE WED THU FRI SAT");
       textcolor(7);

       printchar(CH);

       /* setting starting position */
       for(i = 1; i <= Zeller; i++)
           printf(" -");
       j = Zeller;
       /* printing dates */
       for(i = 1; i <= MonthDay[Month-1]; i++)
       {
           if(j++ % 7 == 0)
           {
               printf(" ");
               textcolor(12);
               cprintf("%2d",i);
               textcolor(WHITE);
           }
           else
               printf(" %2d",i);
       }

       printchar(CH);
       printf(" (*) Use Left,Right,Up & Down Arrow.");
       printf(" (*) Press I for New Month & Year.");
       printf(" (*) Press P for Print to File.");
       printf(" (*) Press ESC for Exit. ");

       textcolor(11);
       textbackground(9);
       cprintf("Created by: Chegg");
       textcolor(WHITE);
       textbackground(BLACK);

       KeyCode = getkey(); /
       if(KeyCode == 72)   
           Year++;
       if(KeyCode == 80)   
           Year--;
       if(KeyCode == 77)   
       {
           Month++;
           if(Month > 12)
           {
               Month = 1;
               Year++;
           }
       }
       if(KeyCode == 75)   
       {
           Month--;
           if(Month < 1)
           {
               Month = 12;
               Year--;
           }
       }
       if(KeyCode == 25)   
           PrintFile(Month,Year,Zeller);
       if(KeyCode == 23)
           goto Top;
   }while(KeyCode != 1);  
   exit(0);
}      

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