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

Write a C++ program, which given a date will print out the day of the year. For

ID: 3691004 • Letter: W

Question

Write a C++ program, which given a date will print out the day of the year. For example, February 3, 1998 was the 34th day of that year. Your program must handle leap years. If a year is a multiple of 4, then it is a leap year. However, if the year is a multiple of 100, then it is not a leap year. However, if the year is a multiple of 400, then it is a leap year. (Confusing, no?) Prompt the user for the month, day, and year in numeric form. The following dates will be used to test your program: April 7, 1998, June 11, 2000, July 25, 1885, December 22, 1958, March 26, 1900, July 4, 1776, and February 2, 2004. Style: All prior style guidelines remain enforced. “if” statements written on one line requires no braces. if (x > 0) y++; “if” statements written on multiple lines must have braces, even if they only contain one statement. if (x > 0) { y++; } Ending braces in an “if” must line up under the “i” in “if” if (x > 0) { y++; } else { y = z / 2; } Opening braces end the line. All statements within the multi-lined “if” must be indented one tab Each case in a switch lines up under the “s” in “switch” Each line executed within a case is indented one tab, including the “break;” The ending brace of a switch lines up under the “s” in “switch” switch (inputChar) { case 'A' : cout << "Excellent"; break; case 'B' : cout << "Not bad!"; break; case 'C' : cout << "You're doing well"; break; otherwise : cout << "Try harder"; break; }

Explanation / Answer

/*#include <stdio.h>
#include <stdlib.h>
//#include <fstream>
#define BUFFSIZE 10000
int main(int argc , char *argv[])
{
char a[BUFFSIZE];
int words=0,characters=0,i=0,j=0;
// printf("%s",argv[1]);
FILE *file=(fopen(argv[1],"r"));
printf("where data.txt contains ");
if(argc==2)
{
while(fgets(a, BUFFSIZE - 1, file) != NULL)
{
while(a[i]!='')
{
i++;
}
j++;
printf("%s ",a);
}

}
else
printf("Unable to open the file");
while(fgets(a, BUFFSIZE - 1, file) != NULL)
{
printf("%s ",a);

}

printf("number of Lines = %d characters = %d ",j,i);

fclose(file);
return 0;
}
*/
# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <iostream>
using namespace std;
int main()
{
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char week[7][10] ;
int date, mon, year, i, r, s = 0 ;
strcpy(week[0], "Sunday") ;
strcpy(week[1], "Monday") ;
strcpy(week[2], "Tuesday") ;
strcpy(week[3], "Wednesday") ;
strcpy(week[4], "Thursday") ;
strcpy(week[5], "Friday") ;
strcpy(week[6], "Saturday") ;
cout << "Enter a valid day: ";
cin >> date;

cout << "Enter a valid month: ";
cin >> mon;

cout << "Enter a valid year: ";
cin >> year;

if( (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)) )
month[1] = 29 ;
for(i = 0 ; i < mon - 1 ; i++)
s = s + month[i] ;
s = s + (date + year + (year / 4) - 2) ;
s = s % 7 ;
cout << " The day is : " << week[s] ;
return 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