The day corresponding to the output is the day of the year

Source: Internet
Author: User

[Cpp]/** Copyright and version statement of the program section * Copyright (c) 2013, student * All rightsreserved from computer College of Yantai University. * file name: date. cpp * OPERATOR: Ji Zilong * Completion Date: July 15, March 8, 2013 * version: v1.0 * input Description: year, month, and day * Problem description: The output date corresponds to the day of the year * output: day */# include <iostream> using namespace std; struct Date {int year; int month; int day; int hour; int minu; long second ;}; int sumday (int m); int main () {int days; long dseconds, yseconds; Date date; cout <"please I Nput year month day hour minu, second "<endl; cin> date. year> date. month> date. day> date. hour> date. minu> date. second; if (date. month = 1) days = date. day; if (date. month = 2) days = 31 + date. day; if (date. year % 4 = 0 & date. month> 2) {if (date. month <8) {days = date. day + sumday (date. month)-1;} else {days = date. day + sumday (7) + sumday (date. month-7)-1 ;}} if (date. year % 4! = 0 & date. month> 2) {if (date. month <8) {days = date. day + sumday (date. month)-1;} else {days = date. day + sumday (7) + sumday (date. month-7)-1 ;}/// calculates the number of seconds dseconds = (date. hour-1) * 3600 + (date. minu-1) * 60 + date. second; yseconds = (days-1) * 3600*24 + dseconds; cout <date. month <"month" <date. day <"day is" <date. the day of year <"year" <days <. "<date. minu <"Minute" <date. second <"second is the day" <dseconds <"second, is the year's" <yseconds <"second" <endl; return 0;} int sumday (int m) {if (m-1 = 0) return 0; if (m-1% 2) = 0) return 31 + sumday (m-1 ); else return 30 + sumday (S-1);} running result:

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.