您的位置:首页 > 其它

以结构指针作为函数参数

2013-10-07 15:38 190 查看
#include <iostream>
using namespace std;
struct date
{
int day;
int month;
int year;
int yeardays;
};
void days(struct date *pd);
void main()
{
struct date ymd;
cout << "Enter year/month/day:";
cin >> ymd.year >> ymd.month >> ymd.day;
days(&ymd);
cout << "the passddays: " << ymd.yeardays;
}
void days(struct date *pd)
{
static int day_tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31},
};
int i,Ip;
pd -> yeardays = pd -> day;
Ip = pd->year%4==0&&pd||pd->year%100!=0
||pd->year%400==0;
for(i=1; i<pd->month; i++)
pd->yeardays = pd->yeardays + day_tab[Ip][i];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: