第17周上机实践项目5——玩日期时间(3)

来源:互联网 发布:古典音乐 知乎 编辑:程序博客网 时间:2024/04/30 15:31

问题及代码

/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作    者:辛彬 * 完成日期:2014年 12 月 23 日 * 版 本 号:v1.0 * * 问题描述: 输出这是这一天中的第几秒。 * 输入描述:出生年、月、日、时、分、秒。 * 程序输出:第几秒; */#include <iostream>using namespace std;struct Date{    int year;    int month;    int day;    int hour;    int minute;    int second;};void day(int y,int m,int d);void seconds(int h,int m,int s);int main(){    Date date;    cout<<"请输入年、月、日、时、分、秒"<<endl;    cin>>date.year>>date.month>>date.day>>date.hour>>date.minute>>date.second;    day(date.year,date.month,date.day);    seconds(date.hour,date.minute,date.second);    return 0;}void day(int y,int m,int d){    int days=0;    int mon[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31},i;    for(i=0; i<m; i++)        days+=mon[i];    if(((y%4==0&&y%100!=0)||y%400==0)&&m>2)        days++;    days+=d;    cout<<m<<"月"<<d<<"日是"<<y<<"年的第"<<days<<"天."<<endl;}void seconds(int h,int m,int s){    int ss;    ss=h*60*60+m*60+s;    cout<<"这是这一天中的第"<<ss<<"秒"<<endl;;}

运行结果:


0 0
原创粉丝点击