| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:这两个程序如何组合啊
只看楼主 加入收藏
诺亚Kiss
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-9-6
结帖率:0
收藏
 问题点数:0 回复次数:3 
这两个程序如何组合啊
问下这个程序:
#include "stdio.h"
#include "conio.h"
void main()
{
   int leap_year(int y);
   int count_leap(long year);
   int monthdays(int month,long year);
   void monthprint(long year,int month);
   int month=0;
   long year=0;
   char choose;
  
   do
       {printf ("\n\nPlease input one integer number as 'year'(0~999999):\n");
        scanf ("%ld",&year);
        if (year<0||year>999999) printf ("WANNING:ERROR,please input again!");
       }
   while (year<0||year>999999);
    printf ("\n\n");
    do
       {printf ("please input the month(1~12)\n\n");
        scanf ("%d",&month);
       if (month<=0||month>12) printf ("WANNING:ERROR,please input again!");
       }
    while (month<=0||month>12);
    printf ("\n\n\n");
   printf("\t\t\t\t%ld\t%d\n\n",year,month);
   printf
("\n********************************************************************************\n");
   printf("\t\t Sun\t Mon\t Tue\t Wen\t Thu\t Fri\t Sat\n");
   monthprint(year,month);
   printf("\n\n");
   choose=getchar();
    printf("Continue?(y/n):\n\n");
    scanf("%c",&choose);
    if (choose=='y'||choose=='Y') main(); /*main函数调用main函数本身*/
}
int leap_year(int y)//判断闰年
{ int i;
  if (y%4==0&&y%100!=0||y%400==0) i=1;
  else i=0;
  return i;
}

int count_leap(long year)
{
  int i=0,j,min,max;
  if(year>2006) {min=2006;max=year;}
  else {min=year+1;max=2006;}
  for(j=min;j<max;j++)
     if(leap_year(j)) i++;
    return i;
}
int monthdays(int month,long year)
{
  int sum=0,i,j;
  if(year>=2006)
    { static int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};/*1~12月的每月天数*/
      j=month-1;
      if(leap_year(year)) t[1]=29;
       else t[1]=28;
      for(i=0;i<j;i++)
       sum=sum+t[i];
    }
  else
    {  static int t1[12]={31,30,31,30,31,31,30,31,30,31,0,31}; /*12~1月的每月天数*/
       j=12-month;
       if(leap_year(year)) t1[10]=29;
       else t1[10]=28;
       for(i=0;i<=j;i++)
   sum=sum+t1[i];
    }
   return sum;
}

void monthprint(long year,int month)      
{
 static int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
 int i,y,weekday=0;
 long days=0;
 if(leap_year(year)) t[1]=29;
       else t[1]=28;
 y=t[month-1];
 if(year>2006)
  {
   days=(year-2006)*365+count_leap(year)+monthdays(month,year);
   weekday=days%7;
  }
  else if(year<2006)
  {days=(2005-year)*365+count_leap(year)+monthdays(month,year);
   weekday=7-days%7;
  }
  else
  {days=monthdays(month,year);weekday=days%7;}
 for (i=1;i<=weekday+2;i++) /*由于上一行打印星期的时候空2个制表位,所以weekday要加2*/
    printf ("\t");
 for (i=1;i<=y;i++)
    {if ((i+weekday-1)%7==0) printf ("\n\n\t\t%3d\t",i);
      else printf ("%3d\t",i);};
 printf
("\n********************************************************************************\n\n");
}
和这一个程序:

#ifndef _TM_DEFINED
struct tm
{
     int tm_sec;     
     int tm_min;   
     int tm_hour;   
     int tm_mday;   
     int tm_mon;     
     int tm_year;   
    int tm_wday;   
int tm_yday;   
     int tm_isdst;  
 };
#define _TM_DEFINED
#endif

#include <iostream.h>
#include <time.h>
int main(void)
{
        struct tm *local;
        long t;
        time(&t);
        cout << "The Calendar Time now is:" << t << endl ;
        local = localtime(&t);
        local->tm_year = local->tm_year + 1900;
        local->tm_mon ++;
        cout << "今天是: " << local->tm_year    << "年" << local->tm_mon
            << "月" << local->tm_mday << "日" << "星期" << local->tm_wday
            <<"当前的时间是:"<< local->tm_hour
            << "时" << local->tm_min  << "分" << local->tm_sec <<"秒"
             << endl;
        return 0;
}
怎么进行组合成一个程序,我怎么试都不行啊!
各位帮个忙。

搜索更多相关主题的帖子: include please number 
2010-09-07 17:13
jack10141
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:陕西西安
等 级:小飞侠
威 望:6
帖 子:706
专家分:2271
注 册:2010-8-10
收藏
得分:0 
你需要考虑由哪个程序作为main()函数,然后另外一个程序的函数改名字,其输入改成从主函数传递数据过来!
然后就可以运行了啊!!!

Coding就像一盒巧克力,你永远不会知道你会遇到什么BUG
别跟我说你是不能的,这让我愤怒,因为这侮辱了你的智慧
2010-09-07 18:40
诺亚Kiss
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-9-6
收藏
得分:0 
回复 2楼 jack10141
如果第一个作为主函数,应该组合成什么形式呢?组合出来什么样?
2010-09-07 21:35
jack10141
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:陕西西安
等 级:小飞侠
威 望:6
帖 子:706
专家分:2271
注 册:2010-8-10
收藏
得分:0 
你想做什么程序?实现什么功能??你有什么思路???
回答了这三个问题,你也就知道怎么连接两个程序了!!

Coding就像一盒巧克力,你永远不会知道你会遇到什么BUG
别跟我说你是不能的,这让我愤怒,因为这侮辱了你的智慧
2010-09-07 22:25
快速回复:这两个程序如何组合啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013930 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved