第十三周上机实践项目:定义日期变量,进行年、月、日的输入,计算该日期是本年中的第几天。

来源:互联网 发布:java数据输入 编辑:程序博客网 时间:2024/06/09 22:10
/* *Copyright(c) 2016.烟台大学计算机与控制工程学院 *ALL rights  reserved. *文件名称:cpp.cpp *作者:  赵子琳 *完成日期:2016年6月15日 *问题描述:定义一个日期变量,进行年、月、日的输入,计算该日期是本年中的第几天。 */#include <iostream>using namespace std;struct y_m_d{    int year;    int month;    int day;};int is_runnian(int iyear){    if((iyear%4==0&&iyear%100!=0)||(iyear%400==0))        return 1;    else        return 0;}int sday(int num,int iyear){    switch(num)    {    case 1:    case 3:    case 5:    case 7:    case 8:    case 10:    case 12:        return 31;    case 4:    case 6:    case 9:    case 11:        return 30;    case 2:        if(is_runnian(iyear))            return 29;        else            return 28;    }    return 0;}int days(y_m_d date){    int i,s=0;    for(i=1;i<=date.month;i++)        s=s+sday(i,date.year);        return s;}int main(){  y_m_d date;  int days(y_m_d);  int day_sum;  cin>>date.year>>date.month>>date.day;  day_sum=days(date);  cout<<day_sum<<endl;  return 0;}

0 0
原创粉丝点击