
Here is mine code in C++:
#include <iostream>
#include <stdlib.h>
using namespace std;
bool checking_year(int year){
if ((year>999) && (year < 10000)){
return true;
}else{
return false;
}
}
bool checking_month(int month){
if ((month>0) && (month<13)){
return true;
}else{
return false;
}
}
bool checking_date(int day, int month){
if ((month==2) && (day>0) && (day<30)){
return true;
}
if ((
(month==1) ||
(month==3) ||
(month==5) ||
(month==7) ||
(month==8) ||
(month==10)||
(month==12)
) && ((day>0) && (day<32)))
{
return true;
}
if ((
(month==4) ||
(month==6) ||
(month==9) ||
(month==11)
) && ((day>0) && (day<31)))
{
return true;
}
return false;
}
bool isLeapYear(int year){
if (((year % 4)==0) && ((year % 100)!=0)){
return true;
}else if ((year % 400)==0){
return true;
}else {
return false;
}
}
// http://en.wikipedia.org/wiki/Julian_day#Calculation
const char *get_day(int day, int month, int year){
int JMD;
JMD = (day + ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) /
5) +
(365 * (year + 4800 - ((14 - month) / 12))) +
((year + 4800 - ((14 - month) / 12)) / 4) -
((year + 4800 - ((14 - month) / 12)) / 100) +
((year + 4800 - ((14 - month) / 12)) / 400) - 32045) % 7;
const char *weekday[] = {"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"};
return weekday[JMD];
}
int main(){
int year, month, date, x, y;
cout << "\nPlease Enter The Year [YYYY] : ";
cin >> year;
if (checking_year(year)){
cout << "\n\tYear Verified";
}else{
cout << "\n\t Wrong Year Format\n";
exit(0);
}
cout << "\nPlease Enter The Month [MM] : ";
cin >> month;
if (checking_month(month)){
cout << "\n\tMonth Verified";
}else{
cout << "\n\t Wrong Month Format";
exit(0);
}
cout << "\nPlease Enter The Date [DD] : ";
cin >> date;
if (checking_date(date, month)){
cout << "\n\tDate Verified\n\n";
}else{
cout << "\n\t Wrong Date Format";
exit(0);
}
cout << "Date : " << date << ", Month : "
<< month << ", Year : " << year << " [
";
if (isLeapYear(year)){
cout << "Leap Year" << " ]";
}else{
cout << "Not Leap Year" << " ]";
}
cout << "\n\tWeekday : ";
cout << get_day(date, month, year);
cout << "\n\n";
return 0;
}
Output:-
![Please Enter The Year [YYYY] : 2019 Year Verified Please Enter The Month [MM]: 3 Month Verified Please Enter The Date [DD]: 2](http://img.homeworklib.com/images/09821b2f-8757-46c5-888f-a11327c35e43.png?x-oss-process=image/resize,w_560)
Here is my code for Swift 3 and later:-
import Foundation
import Glibc
func gettingDayOfWeek(_ today:String) -> Int? {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
guard let todayDate = formatter.date(from: today) else { return nil }
let myCalendar = Calendar(identifier: .gregorian)
let weekDay = myCalendar.component(.weekday, from: todayDate)
return weekDay
}
if let weekday = gettingDayOfWeek("2019-03-17") {
print(weekday)
} else {
print("bad input")
}
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 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...
Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. 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: ...
C++ code: Days in current month: Write a program that can determine the number of days in a month for a specified month and year. The program should allow a user to enter two integers responding a month and a year, and it should determine how many days are in the specified month. The integers 1 through 12 will be used to identify the months of January through December. The user indicates the end of days in the current month...
Has to be written in C++ Write a program that asks the user to enter the month (1-12) and the year (0-2019). Validate the input and print an error and stop the program if an invalid month or year was entered. The program should then display the number of days in that month. Use the following criteria to identify leap years: Determine whether the year is divisible by 100. If it is, then it is a leap year if and...
Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the following data entry error conditions: A number less than 1 or greater than 12 has been entered for the month A negative integer has been entered for the year utilizes a try and catch clause to display an appropriate message when either of these data entry errors exceptions occur. Thank you let me know if you need more info import java.util.*; //Class definition public...
A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year...
the instructions are: A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are:1) The year must be divisible by 42) If the year is a century year...
Must use a function to compute the day.
All cin and cout statements must appear in main(). Has to be in
c++. lab 10
Problem write a program that prints the day number of the year, given the date in the form month-day year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12 the day number is 359. The program should check for a leap year. A year is a leap year...
Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for the month (1 = January, 2 February, etc). l An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if...
Hi, can you please help me with this question. I need it to be in C++. Please without struct and files. Only with functions bc I didnt learn struct and files yet. Many computer applications, such as Microsoft Excel, can compare date values that occur after January 1, 1900. For example, these programs can determine if 06/06/99 is less than (comes before) 11/01/00. They use January 1, 1900 as their reference point. This becomes day 1. All other dates are...