日期结构体

来源:互联网 发布:js自动登录脚本 编辑:程序博客网 时间:2024/06/06 08:46
/** 程序的版权和版本声明部分* Copyright (c)2013, 烟台大学计算机学院学生* All rightsreserved.* 文件名称:a.cpp* 作    者:孔云* 完成日期:2014年3月3日* 版 本 号: v1.0* 输入描述:输入年、月、日。* 问题描述:定义一个结构体变量(包括年、月、日),要求输入年、月、日,计算            输出该日是该年的第几天。*/#include <iostream>using namespace std;struct Date{    int year;    int month;    int day;};int d[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};int main(){    Date date;    cout<<"input year,month,day:";    cin>>date.year>>date.month>>date.day;    int days=0,i;    //计算days    for(i=0; i<date.month; i++)    {        days+=d[i];    }    days+=date.day;    if((date.year%4==0&&date.year%100!=0||date.year%400==0)&&date.month>=3)    {        days+=1;    }    cout<<date.month<<"月"<<date.day<<"日是"<<date.year<<"年的第"<<days        <<"天."<<endl;    return 0;}


心得体会:本程序中,用到了结构体类型,更重要的是将结构体变量与数组结合运用,使此次程序简便化,真的不错哦!奋斗

0 0