Software testing and quality assurance _ a question about date

Source: Internet
Author: User
Code:
  1. /*
  2. A question from the software testing and quality assurance INSTRUCTOR:
  3. Enter the year, month, and day (the year value is divided into [1600,210], and the result is: the day of the last day, the next day, the day of the week,
  4. How many days is the difference between the date of birth and the date of birth? Is it a leap year, and the day is the day of the year?
  5. // The program is basically completed, and the input range is limited.
  6. */
  7. # Include <stdio. h>
  8. # Include <iostream>
  9. # Include <string>
  10. # Include <string. h>
  11. Using namespace STD;
  12. // Statement
  13. Int upanddown (INT year, int month, int Day );
  14. Int isleap (INT year );
  15. Int dateweek (INT year, int month, int Day );
  16. Int days (INT year, int month, int Day );
  17. Int birthdaytime (INT year, int month, int Day );
  18. // Calculate the previous day and the next day
  19. Int upanddown (INT year, int month, int Day)
  20. {
  21. Int array [13] = {, 31, 31 };
  22. If (month = 12 & day = 31) // the last day of the year
  23. {
  24. Printf ("Last Day: % d-% 02d-% 02d/N", year, month, day-1 );
  25. Printf ("the next day is: % d-% 02d-% 02d/N", year +, 01 );
  26. }
  27. Else if (month = 1 & day = 1) // the first day of the year
  28. {
  29. Printf ("Last Day: % d-% 02d-% 02d/N", year-1 );
  30. Printf ("the next day is: % d-% 02d-% 02d/N", year, month, day + 1 );
  31. }
  32. Else if (month! = 12 & day = array [month]) // the last day of the month
  33. {
  34. Printf ("Last Day: % d-% 02d-% 02d/N", year, month, day-1 );
  35. Printf ("the next day is: % d-% 02d-% 02d/N", year, month + );
  36. }
  37. Else if (month! = 1 & day = 1) // the first day of the month
  38. {
  39. If (month = 3 & isleap (year) = 1)
  40. {
  41. Printf ("Last Day: % d-% 02d-% 02d/N", year, month-1, 29 );
  42. }
  43. Else
  44. {
  45. Printf ("Last Day: % d-% 02d-% 02d/N", year, month-1, array [month-1]);
  46. }
  47. Printf ("the next day is: % d-% 02d-% 02d/N", year, month, day + 1 );
  48. }
  49. Else // normal
  50. {
  51. Printf ("Last Day: % d-% 02d-% 02d/N", year, month, day-1 );
  52. Printf ("the next day is: % d-% 02d-% 02d/N", year, month, day + 1 );
  53. }
  54. Return 0;
  55. }
  56. // Determine whether it is a leap year
  57. Int isleap (INT year)
  58. {
  59. If (Year % 4 = 0 & amp; Year % 100! = 0 | year % 400 = 0)
  60. {
  61. // Cout <"this year is a leap year! "<Endl;
  62. Return true;
  63. }
  64. Else
  65. {
  66. // Cout <"this year is a normal year! "<Endl;
  67. Return false;
  68. }
  69. }
  70. // Determine the current day of the week
  71. Int dateweek (INT year, int month, int Day)
  72. {
  73. Int Week;
  74. // String weekday [8] = {"error", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ", "Sunday "};
  75. If (month = 1 | month = 2 ){
  76. Year-= 1;
  77. Month + = 12;
  78. }
  79. Week = (day + 1 + 2 * month + 3 * (month + 1)/5 + year + (Year/4)-year/100 + year/400) % 7;
  80. Switch (week)
  81. {
  82. Case 1: printf ("% d-% 02d-% 02d is Monday! /N ", year, month, day); break;
  83. Case 2: printf ("% d-% 02d-% 02d is Tuesday! /N ", year, month, day); break;
  84. Case 3: printf ("% d-% 02d-% 02d is Wednesday! /N ", year, month, day); break;
  85. Case 4: printf ("% d-% 02d-% 02d is Thursday! /N ", year, month, day); break;
  86. Case 5: printf ("% d-% 02d-% 02d is Friday! /N ", year, month, day); break;
  87. Case 6: printf ("% d-% 02d-% 02d is Saturday! /N ", year, month, day); break;
  88. Case 7: printf ("% d-% 02d-% 02d is Sunday! /N ", year, month, day); break;
  89. Default: cout <"error! "<Endl; break;
  90. }
  91. Return Week;
  92. }
  93. // Calculate the day of the year
  94. Int days (INT year, int month, int Day)
  95. {
  96. Int array [13] = {, 31, 31 };
  97. Int days = 0;
  98. If (isleap (year) = 1)
  99. {
  100. Array [2] = 29;
  101. }
  102. Else
  103. {
  104. Array [2] = 28;
  105. }
  106. For (INT I = 1; I <month; I ++)
  107. {
  108. Days + = array [I];
  109. }
  110. Days + = Day;
  111. Return days;
  112. }
  113. // Calculate the difference between the date you entered and your date of birth
  114. Int birthdaytime (INT year, int month, int Day)
  115. {
  116. Int resultday = 0;
  117. Int day1 = 0, day2 = 0, day3 = 0, I;
  118. Int birthyear, birthmonth, birthday;
  119. Cout <"Enter your birthday date:" <Endl;
  120. Scanf ("% d-% d", & birthyear, & birthmonth, & birthday );
  121. // If the year and month are the same, the absolute value of the number of days is directly subtracted.
  122. If (year = birthyear & month = birthmonth)
  123. {
  124. Resultday = (day> birthday )? (Day-birthday) :( birthday-day );
  125. }
  126. // If the year is the same and the month is different, it is the day of the year, and then subtract the absolute value.
  127. Else if (year = birthyear & month! = Birthmonth)
  128. {
  129. Day1 = days (year, month, day );
  130. Day2 = days (birthyear, birthmonth, birthday );
  131. Resultday = (day1> day2 )? (Day1-Day2) :( Day2-Day1 );
  132. }
  133. Else // If the year and month are different, then resultday = the number of days from the end of the year, the number of days in the year, and the number of days in the whole year
  134. {
  135. If (year <birthyear)
  136. {
  137. // Calculate the number of days from the end of the year.
  138. If (isleap (year) = 1)
  139. {
  140. Day1 = 366-days (year, month, day );
  141. }
  142. Else
  143. {
  144. Day1 = 365-days (year, month, day );
  145. }
  146. // Number of days in the year
  147. Day3 = days (birthyear, birthmonth, birthday );
  148. // Calculate the number of days separated by the whole year
  149. For (I = year + 1; I <birthday; I ++)
  150. {
  151. If (isleap (I) = 1)
  152. {
  153. Day2 ++ = 366;
  154. }
  155. Else
  156. Day2 ++ = 365;
  157. }
  158. Resultday = day1 + day2 + day3;
  159. }
  160. Else
  161. {
  162. // Calculate the number of days from the end of the year.
  163. If (isleap (birthyear) = 1)
  164. {
  165. Day1 = 366-days (birthyear, birthmonth, birthday );
  166. }
  167. Else
  168. {
  169. Day1 = 365-days (birthyear, birthmonth, birthday );
  170. }
  171. // Number of days in the year
  172. Day3 = days (year, month, day );
  173. // Calculate the number of days separated by the whole year
  174. For (I = birthyear + 1; I <year; I ++)
  175. {
  176. If (isleap (I) = 1)
  177. {
  178. Day2 ++ = 366;
  179. }
  180. Else
  181. Day2 ++ = 365;
  182. }
  183. Resultday = day1 + day2 + day3;
  184. }
  185. }
  186. Printf ("% d-% 02d-% 02d the number of days between your date of birth % d-% 02d-% 02d is % d. /n ", year, month, day, birthyear, birthmonth, birthday, resultday );
  187. Return resultday;
  188. }
  189. Int main (void)
  190. {
  191. Int year, month, day;
  192. Cout <"Enter year, month, and day in MM-MM-MM format! "<Endl;
  193. Scanf ("% d-% d", & year, & month, & Day );
  194. Upanddown (year, month, day );
  195. If (isleap (year) = 1)
  196. {
  197. Printf ("% d is a leap year! /N ", year );
  198. }
  199. Else
  200. {
  201. Printf ("% d Year is normal year! /N ", year );
  202. }
  203. Dateweek (year, month, day );
  204. Printf ("% d-% 02d-% 02d is % d day of % d. /N ", year, month, day, year, days (year, month, day ));
  205. Birthdaytime (year, month, day );
  206. Return 0;
  207. }

 

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.