#include <iostream>
using namespace std;
//2.a) A function that determines if a year is a leap
year.
bool isLeapYear(int year)
{
if((year%4 == 0 && year%100 != 0) || (year %
400 == 0))
{
return true;
}
else
{
return false;
}
}
//2.b) A function that determines the number of days in a
month.
//Remember if the year is a leap year then February has 29
days.
//You will need the leap year function.
//This is an example of a function calling another function.
int numberOfDaysInaMonth(int month, int year)
{
if(month == 2)
{
if(isLeapYear(year))
return 29;
else
return 28;
}
else if((month <= 7 && month%2 != 0) ||
(month >= 8 && month%2 == 0))
return 31;
else
return 30;
}
//2.c) A function that determines the number of days in the year
of the date in question.
//This function uses the days in month function.
int numberOfDaysInYear(int year)
{
int noOfDays = 0;
for (int i=1; i<=12; i++)
{
noOfDays += numberOfDaysInaMonth(i, year);
}
return noOfDays;
}
//2.d)Based on the "day value" of the date, and the fact that
January 1, 1900 was Monday,
//write another function that prints the day of the week that date
fell on
string dayOfTheWeek(int year, int day, int month)
{
int noOfLeapYears = (int) year / 4;
//Calculating no of days between years
long dayValue = (year - noOfLeapYears)*365 + noOfLeapYears *
366;
//Adding the no of days in the remaining months of given year
for(int i=1;i<month;i++)
{
dayValue += numberOfDaysInaMonth(i, year);
}
//Adding the no of days entered
dayValue += day - 2;
int dayOfWeek = (int) dayValue % 7;
switch(dayOfWeek) {
case 2 :
return "Monday";
case 3 :
return "Tuesday";
case 4 :
return "Wednesday";
case 5 :
return "Thursday";
case 6 :
return "Friday";
case 0 :
return "Saturday";
case 1 :
return "Sunday";
default :
break;
}
return "";
}
int main()
{
//1. Have the User enter in a date.
int day;
int month;
int year;
cin >> day;
cin >> month;
cin >> year;
if(isLeapYear(year))
cout << year << " is a leap year" <<
endl;
else
cout << year << " is not a leap year"
<< endl;
cout << "Number of days in the month: " <<
numberOfDaysInaMonth(month,year) << endl;
cout << "Number of days in the year: " <<
numberOfDaysInYear(year) << endl;
cout << "Day of the week: " <<
dayOfTheWeek(year, day, month) << endl;
return 0;
}
Hi, can you please help me with this question. I need it to be in C++....
I need help with a project, I’ve seen many answers in C++, but
i need it to be in swift, thank you!
Write a program that asks the user to enter a date (e.g. July 4, 2008) and will return the day of the week that corresponds to that date. Your program should take the input in numeric form, thus the input prompt should be as follows: Please enter a date below: Enter month (1-12): Enter day (1-31) Enter year...
An ordinal date consists of a year and a day within it,
both of which are integers. The year can be any year in the
Gregorian calendar while the day within the year ranges from one,
which represents January 1, through to 365 (or 366 if the year is a
leap year) which represents December 31.
Ordinal dates are convenient when computing differences between
dates that are a specific number of days (rather than months). For
example, ordinal dates can...
In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...
Write a function to determine the day of the week a person was born given his or her birthday. The following steps should be used to find the day of the week corresponding to any date from 1901 through the present. In the following explanation, the following terms will be helpful. Assuming I type in my birthday as "6 10 1981": The month is 6. The day of the month is 10. The year is 1981. Find the number of...
in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...
C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...
Hi any help is appreciated! I am using C++. The Julian Day Number (JDN) is a sequential count of days since the beginning of the Julian Period. Day number zero corresponds to 1 January 4713 BCE. As a result of calendar reform in the 16th Century, we will only be computing day numbers since 15 October 1582 (which was the first day of the modern Gregorian calendar, having day number 2299161). 1 January 2001 was day number 2451911. To compute...
PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file timeValidation.txt : ...
PYTHON I need some basic python homework help! Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date. You do not need to validate the input. That means you can assume: the year will be entered as a four-digit number in the range 1900 through 2100 inclusive. the month will be one of the strings "January", "February", . . ., "December". the...
Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday Your program should...