谭浩强C++ 程序设计7_1

首先画一个流程图


#include <iostream>
using namespace std;

//定义Date结构体
struct
{
	int year;
	int input_month;
	int day;
} Date;

int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

main()
{
	void Input_time();
	void Leap_year(int year);
	void count_days(int,int);

	Input_time();
	Leap_year(Date.year);
	count_days(Date.input_month,Date.day);
	
	return 0;
}

//输入时间的函数	
void Input_time()
{
	cout<<"Input YYYY"<<endl;
	cin>>Date.year;
	
	cout<<"Input MM"<<endl;
	cin>>Date.input_month;
	
	cout<<"Input DD"<<endl;
	cin>>Date.day;
	
	cout<<"The date is:"<<Date.year<<"/"<<Date.input_month<<"/"<<Date.day<<endl;
}

//判断是否是闰年,如果是闰年便修改month[2]的数据
void Leap_year(int year)
{
	int i;

	if(year%400==0) i=1;
	else 
	{
		if(year%4==0&&year%100!=0) i=1;
		else i=0;
	}

	if(i) 
	{
		cout<<year<<"is a leap year!"<<endl;
		month[2]=29;
	}
	else 
	{
		cout<<year<<"is not a leap year!"<<endl;
		month[2]=28;
	}
}

void count_days(int month_f,int day)
{
	int sum=day;
	int j;
	for(j=0;j<month_f;j++)//如输入3,取得0 1 2 共两个月
	{
		sum+=month[j];
	}
    cout<<"The date:"<<Date.year<<"/"<<Date.input_month<<"/"<<Date.day
		<<" is the "<<sum<<" day of the year"<<endl;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值