第十七周项目5(部分) 该年第几秒

来源:互联网 发布:dota1深渊领主技能数据 编辑:程序博客网 时间:2024/05/01 02:27
/**Copyright (c) 2014,烟台大学计算机学院void change(int a[8][8]);*All rights reserved.*文件名称:main.cpp*作者:苏强*完成日期:2014年12月23日*版本号:v1.0**问题描述:输入年月日,输出该时间是本年的第几秒*输入描述:年、月、日 、时、分、秒*程序输出:该年的第几秒*/#include <iostream>using namespace std;struct Time{    int year;    int month;    int day;    int hour;    int minute;    int second;};int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int calculatesecond(Time);int calculateday(Time);void calculatesecondodyear(int ,int );int main(){    int secondofday,dayofyear,secondofyear;    Time t;    cin>>t.year>>t.month>>t.day>>t.hour>>t.minute>>t.second;    secondofday=calculatesecond(t);    cout<<t.hour<<"时"<<t.minute<<"分"<<t.second<<"秒是本天的第"<<secondofday<<"秒."<<endl;    dayofyear=calculateday(t);    cout<<t.year<<"年"<<t.month<<"月"<<t.day<<"日是"<<t.year<<"年的第"<<dayofyear<<"天."<<endl;    calculatesecondodyear(dayofyear,secondofday);    return 0;}int calculatesecond(Time t){    int m;    m=(t.hour*60+t.minute)*60+t.second;    return m;}int calculateday(Time t){    int days=0,i;    for(i=1;i<t.month;i++)         days+=mon[i];    days+=t.day;    if((t.month>2)&&((t.year%4==0&&t.year%100!=0)||t.year%400==0))        days++;    return days;}void calculatesecondodyear(int x,int y){    int secondofyear;    secondofyear=(x-1)*24*3600+y;    cout<<"是本年的第"<<secondofyear<<"秒."<<endl;}


 

 

0 0