现在的位置: 首页 > 综合 > 正文

项目三拓展

2014年08月24日 ⁄ 综合 ⁄ 共 827字 ⁄ 字号 评论关闭

上机内容:C++程序的编写和运行
上机目的:掌握简单C++程序的编辑、编译、连接和运行的一般过程
我的程序:

/*
Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作    者:赵玲玲
* 完成日期:2014 年 2 月 27 日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述: 输入两人的生日,看差多少天
* 程序输出: 略
* 问题分析:
* 算法设计:略
*/
#include <iostream>
using namespace std;
struct Date
{
    int year;
    int month;
    int day;
};
Date date;
int jisuan();
int main()
{
    int sum1,sum2,u;
    cout<<"请输入甲同学生日(年月日):";
    cin>>date.year>>date.month>>date.day;
    sum1=jisuan();
    cout<<"请输入甲同学生日(年月日):";
    cin>>date.year>>date.month>>date.day;
    sum2=jisuan();
    u=sum1-sum2;                                                         //差的天数
    if(u<0)
    {
        u=-u;
    }
    cout<<"两人生日相差"<<u<<"天"<<endl;
    main();
    return 0;
}
int jisuan()
{
    int days=date.day;
    for(int i=1; i<date.month; i++)                                     //对不同月份相加不同的天数
    {
        switch(i)
        {
        case 2:
            days+=(date.year%4==0&&date.year%100!=0||date.year%400==0)?29:28;//闰年2月29天,平年2月28天
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            days+=30;
            break;
        default:
            days+=31;
            break;
        }
    }
    return days;
}

运行结果: 
心得体会:一开始还想弄两个结构体变量,后来一看不用,调用两次函数就行了 ,哦也
知识点总结:略

抱歉!评论已关闭.