Enter the year, month, and day to determine the day of the year. You can also further judge the day of the year.
Source: Internet
Author: User
// Enter the year, month, and day to determine the day of the year. You can also further judge the day of the year.
# Include <iostream>
Using namespace STD;
Int main ()
{
Int Day (int x, int y, int R );
Int calculate_1 (int x, int y, int R );
Int calculate_2 (int n );
Int N, Y, R; /***************************************, month, day, very obvious **/
Int X; /*************************************** ****************** determine the symbol of a leap year, X = 1 is a leap year, x = 0 is not a leap year **/
Char; /*************************************** ****************** user input, determine whether to further **/
Cout <"enter" <Endl <"year, month, and day :";
Cin> N> Y> r;
While (n <= 0 | n> = 10000) /*************************************** * ** determine whether the year is correct **/
{
Cout <"Exceeds my computing range. Enter 1 ~ Year between 9999 "<'\ 001'
<"Enter the year again :";
Cin> N;
}
If (n % 4 = 0 & N % 100! = 0) | n % 400 = 0) /******************************* determine whether it is a leap year **/
X = 1;
Else x = 0;
While (Y> 12 | Y <1) /*************************************** * ******* determine whether the month is correct **/
{
Cout <"Are you kidding me with a month like this ??? "<Endl
<"Give you another chance to enter a month :";
Cin> Y;
}
While (Day (X, Y, R) = 0)
{
Cout <"the input date is incorrect, right? Enter a new date: "<Endl;
Cin> r;
}
Cout <"the date you entered is:" <n <'.' <Y <'.' <r <'.' <Endl;
Cout <"the date you entered is the day of the year" <calculate_1 (X, Y, R) <"day. "<Endl;/************* computing _ 1 */
Cout <"does it calculate the day from the first day of the first year of the current year for you ??? "<'(' <" Y/N "<')';
Cin>;
Int B = 1;
While (! = 'Y' &! = 'Y' &! = 'N' &! = 'N ')
{
Cout <"Hey! How do I enter it? Enter again :";
Cin>;
+ + B;
If (B = 5)
{
Cout <"my question is: do you calculate the day from the first day of the first year of the year ??? "<'(' <" Y/N "<')' <'\ a' <Endl;
B = 0;
}
}
If (A = 'y' | A = 'y ')
Cout <calculate_2 (n) + calculate_1 (X, Y, R) <Endl; /*************************************** * ************************** computing _ 2 */
Else cout <"well" <'\ 002' <Endl;
Return 0;
}
Int Day (int x, int y, int R) /*************************************** * *********************** judge whether the day is correct **/
{
Switch (y)
{
Case 2:
{
If (x = 1)
{
If (r> 0 & R <= 29)
Return 1;
Else return 0;
}
Else
{
If (r> 0 & R <29)
Return 1;
Else return 0;
}
}
Case 4: Case 6: Case 9: Case 11:
{
If (r> 0 & R <31)
Return 1;
Else return 0;
}
Default:
{
If (r> 0 & R <= 31)
Return 1;
Else return 0;
}
}
}
Int calculate_1 (int x, int y, int R)
{
Int A, B;
If (x = 1)
A = 29;
Else A = 28;
Switch (y)
{
Case 1: {B = r; return B ;}
Case 2: {B = 31 + R; return B ;}
Case 3: {B = 31 + A + R; return B ;}
Case 4: {B = 31 + A + 31 + R; return B ;}
Case 5: {B = 31 + A + 31 + 30 + R; return B ;}
Case 6: {B = 31 + A + 31 + 30 + 31 + R; return B ;}
Case 7: {B = 31 + A + 31 + 30 + 31 + 30 + R; return B ;}
Case 8: {B = 31 + A + 31 + 30 + 31 + 30 + 31 + R; return B ;}
Case 9: {B = 31 + A + 31 + 30 + 31 + 30 + 31 + 31 + 31 + R; return B ;}
Case 10: {B = 31 + A + 31 + 30 + 31 + 30 + 31 + 31 + 31 + 30 + R; return B ;}
Case 11: {B = 31 + A + 31 + 30 + 31 + 30 + 31 + 31 + 31 + 30 + 31 + 31 + R; return B ;}
Case 12: {B = 31 + A + 31 + 30 + 31 + 30 + 31 + 31 + 31 + 30 + 31 + 31 + 30 + R; return B ;}
}
}
Int calculate_2 (int n)
{
Int A = 0;
For (INT I = 1; I <= N; ++ I)
{
If (I % 4 = 0 & I % 100! = 0) | I % 400 = 0)
++;
}
Return (n-1) * 365 +;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.